Search code examples
sml

How is structure sharing broken in Standard ML?


In a 2013 presentation about the future of Standard ML, Bob Harper says, on slide 9, that "structure sharing is broken". Can someone give more detail on that? I don't have enough experience with sharing to understand what he meant.


Solution

  • It is broken because as specified, it cannot be applied to structures that have transparent type components. For example:

    signature S = sig type t; type u = int end
    signature T =
    sig
      structure A : S
      structure B : S
      sharing A = B
    end
    

    would already be illegal, although you would naturally expect this to be fine.

    The history here is that structure sharing was introduced in SML'90, where no transparent type components existed. With SML'97, those were added. At that point, the whole business with sharing constraints became somewhat obsolete because they were (to some extent) superseded by "where type" constraints. So, the semantics of sharing was vastly simplified, and structure sharing degraded from a primitive to syntactic sugar. But this sugar was defined such that it only worked with SML'90 programs -- which makes sense if you only view it as a backwards compatibility hack, but not if you consider structure sharing a central feature of SML'97.

    People in the SML community disagree about the relevance of sharing constraints. Some consider them obsolete, some still important. Unfortunately, SML'97 failed to add a "where structure" constraint, which could have properly replaced structure shairing.