Hello, I was wondering if PolyML does any cleaver memory sharing when using constructors.
Here's what I mean...
given:
datatype tree = Lf of int | Br of tr * tr
if I write:
fun trmap f (Lf x) = Lf (f x) | trmap f (Br (a,b)) = Br (trmap f a, trmap f b);
can PolyML avoid allocating more memory if I do the following:
trmap (fn x => if x = 0 then x + 1 else x) (Br (Lf 1, Lf 1))
My understanding is that most ML systems will allocate new memory every time they see a constructor, even if the same constructor on the same arguments already exists. I think that the compiler could automatically optimise such things and avoid the need for horrible exception throwing code which is otherwise useful to optimise memory management. Does PolyML do anything like this?
Any thoughts or suggestions?
thanks, lucas