Why not allow empty record updates?

Yitzchak Gale gale at sefer.org
Tue Nov 15 18:33:25 CET 2011

Simon Peyton-Jones wrote:
>>>> Trouble is, what type does this have?
>>>>   f x = x {}

Malcolm Wallace wrote:
>>> f :: a -> a

Ian Lynagh wrote:
>> That wouldn't help the original poster, as it is incompatible with
>> f :: Foo Clean -> Foo Dirty

Only because in that expression the type of x is not known.

>>>> ...the whole feature of type-changing update is (as you know)
>>>> a bit obscure and not widely used, so it'd be adding
>>>> complexity to an already-dark corner.

To me, at least, that is surprising. The report implies that
record updates are just sugar for the given case expression.
Whether or not it changes a type parameter seems

In fact, I would even advocate adding a line of explanation
in the Report that this is a convenient way of copying
a value from an ADT to itself with a different type
as its parameter. I agree with Malcolm that this is
analogous to using empty record syntax in a pattern
to avoid hard-coding the number of parameter to
a constructor.

I usually avoid using the combination of type parameters and
record syntax altogether, mainly because this obvious syntax
doesn't work. Perhaps that's the reason why type-changing
update is not widely used.

(Admittedly, I didn't think of Herbert's trick. But doesn't
that seem like somewhat of an ugly hack?)

Are you hesitant because of implementation difficulty,
or only because you are worried about the semantics
being confusing? In my opinion, it's more confusing
the way it is now.


More information about the Glasgow-haskell-users mailing list