Lucas Dixon wrote:
This might be a general ML question, but perhaps you can help... I'm curious why type functions cannot be shared, but datatypes can
Is there a theoretical reason for this? (I cannot think of one)
I have been thinking of things like: type tname = .... as type abbreviations to save me typing, and I'm curious why wrapping the type into a datatype should allow sharing... ?
In ML 97 structure sharing is just a derived form of type sharing. You are allowed to share types which are flexible i.e. not bound to external types and are not type functions. If sharing of general type functions were allowed then potentially the compiler would have to produce the equality between two arbitrary type functions.
For example, signature SA = sig type S type T = S * S end signature SB = sig type P type 'a Q type S type T = P Q end signature S = sig structure A:SA and B: SB sharing A = B end; If this were legal the compiler would have to work out the possible interactions between P, 'a Q and S.
When you use datatypes only the types are shared. The right hand side of the datatype is ignored and there is no check that the sharing will result in a signature that can be matched. For example, signature SA = sig datatype T = X of int | Y of bool end signature SB = sig datatype T = A of string end signature S = sig structure A:SA and B: SB sharing A = B end; is legal but unmatchable.
David