[Haskell] Boxing (Day) Question

Nick Benton nick at microsoft.com
Mon Dec 26 14:47:27 EST 2005


>That reminds me of something that I have wondered about for some
>time. Why is there such reluctance to instantiate polymorhic functions
>with the types with which they are used? (This isn't done automatically
>in complilers right?)

MLj, SML.NET and MLton all compile polymorphism this way. They can do it
fairly straightforwardly because (a) they have the whole program
available, and (b) because SML, unlike Haskell, doesn't have polymorphic
recursion. Of course, you don't actually want a copy per source language
instantiation type, just a copy per target language representation.

The .NET CLR also compiles parametric polymorphism by representation
specialization. Thanks to JIT compilation, it can do this lazily, at
"run" time, sidestepping both the restrictions above. The details are
non-trivial in this context (interfaces, runtime "types", etc.) - see
the papers on generics by Andrew Kennedy and Don Syme for the hairy
truth.

Specialization is (generally) a big performance win over uniform
representations for non-symbolic code (e.g. scientific code operating on
floats). 

  Nick


More information about the Haskell mailing list