[MLton-user] curried function definition and pattern destructuring

Stephen Weeks sweeks@sweeks.com
Tue, 18 Jul 2006 10:39:21 -0700


> Just out of interest, could this transformation ever worsen space
> behaviour?

To be clear, here are the two pieces of code.

 (A) fun f (T {x, ...}) y = e
 (B) fun f (T {x, ...}) = fn y => e

(A) could have worse space usage than (B) under the expansion give in
the Definition, because the closure holds on to the entire 'T' value,
while the closure in (B) only holds onto 'x'.  So, transforming from
(A) to (B) cannot worsen space usage, while transforming from (B) to
(A) can.  That's the essence of what I meant by "not equivalent".

Perhaps it's easier to see the difference by looking at (A) and (B)
expanded out a bit.

  (A') fun f z = fn y => (fn T {x, ...} => e) z
  (B') fun f z = (fn T {x, ...} => fn y => e) z

These make clearer when the destructuring of the first argument to 'f'
happens.