flexible records

Stephen Weeks MLton@sourcelight.com
Thu, 18 Oct 2001 16:38:45 -0700


> I  would  think  that it would be better to go for the opposite: a very small
> context.   The  point  is   not   algorithmic   difficulty,   it   is   human
> understandability.   For  polymorphic functions I know that the context can't
> matter.  For overloading, I know that the context does, so I  would  like  to
> not  have  to  look  too  far  to find that context.  If you use a very large
> context then you end up with cases where changing  some  far  away  code  can
> cause the overloading resolution to fail.

That's maybe why a context of strdec makes sense.  Topdec is maybe too
big, and whole-program certainly is.  But valdec is so small as to be
painful.  Anyways, if the resolution fails, you do get a type error,
so it's not a big deal.  Here is the clasic example where I get bitten
a lot.

I have some higher-order function f that passes one of its arguments a
record type.  So a call to f looks like

	f (x, y, fn {a, b, ...} => e)

Now, if e gets to big, I decide to name the anonymous function, and
write:

	let fun g {a, b, ...} = e
        in f (x, y, g)
	end

If flexrecord inference is restricted to valdecs, as it is in SML/NJ,
then this rewrite fails -- one has to add a type constraint to the
record pattern.