[MLton-user] a new approach to type-indexed values in SML

Vesa Karvonen vesa.karvonen at cs.helsinki.fi
Fri Sep 29 05:25:48 PDT 2006


Just a couple of quick questions/notes after briefly skimming your post.

Quoting Stephen Weeks <sweeks at sweeks.com>:
[...]
> Raw tivs themselves are deceptively simple.  The keep a list ref with
> one element (a function) for each type constructor that has a rule.

Doesn't this mean that the compiler will have a very hard time dropping
unused tis (type-indices) and tivs from the program?  If you define a ti
for some type, and you have defined tivs for equality, ordering, hashing,
serialization, random generation, etc..., woudn't something be (almost
certainly) registered (imperatively added to the list ref) for each of
those tivs whether or not you actually use all of those tivs at the
specific ti?

[...and later...]
> This note uses only constant-time wrappers and unwrappers, and handles
> mutable values smoothly.
[...]

I'd like to better understand what (if any) overhead the approach implies.
Could you elaborate on it?

[...]
> In the value-independent style, one uses a single family of types and
> allows as many tivs as one wants to be defined for the family.  This
> is a superior approach to the value-dependent approach because it
> easier to add new tivs and because tivs are automatically composable
> -- one isn't forced to collect together the tivs into a product.

It is better when compared in that particular aspect.  However, as you
later note

> Yang's approach also uses deep coercion functions between ordinary SML
> values and values of his universal type, which take time proportional
> to the size of the data structure being coerced. This is inefficient
> and doesn't work with mutable values. [...]

all is not rosy.  This is one of the reasons why I think that Yang's
technique, while interesting from a theoretical pov, is not really
practical (or at least not suitable for all tivs).

-Vesa Karvonen



More information about the MLton-user mailing list