SML: What's the difference between using abstype and using a signature to hide the implementation of a structure?

前端 未结 2 2110
青春惊慌失措
青春惊慌失措 2021-02-07 07:20

I\'ve done a little work in SML in the past, but I\'m now starting to get to the more interesting parts.

Using the abstype...with...end construct, I can ma

2条回答
  •  别那么骄傲
    2021-02-07 07:47

    Why would I ever want to use abstype?

    Starting with the easiest, you won't. Atleast I can't come up with one good reason.


    Aren't signatures/structures just a more general version of abstypes?

    Well, I guess we have to take a look at the history of SML. The opaque (... :> ...) signature matching was not part of SML '90 as explained on this smlnj document about modules 1.3.9. opaque signature matching :>

    ... whose purpose was to create an "abstract" instance of the signature SIG. This feature was left out of SML '90 for various reasons, but the need for it was real.

    I have no idea about the reasoning for not including it, but as far as I know McQueen was the "farther" of the abstype which was part of SML '90 and for some reason wasn't removed in SML '97 (maybe backwards compatibility?)

    There is however a fundamentally difference between them, abstype is part of the core language where modules/signatures/functors are part of the module system.


    What can I do with abstypes that I can't do with signatures/structures?

    I can't come up with anything. However I'm pretty sure it would be easy to construct some example that you can using opaque signature matching and can't do with abstypes.


    UPDATE

    The page Degrade abstype to derived form from the successor-ml wiki actually contains a tiny informal description about abstype being a leftover.

    As with many other, they also refer to the sections of the Defects in the Revised Definition of Standard ML paper which contains details about some "minor" errors/defects in the definition of abstype, although their link being dead. The "Revised Definition of Standard ML" is the definition of SML '97.

提交回复
热议问题