[Haskell-cafe] type inference and named fields

Christian Maeder maeder at tzi.de
Fri Jun 24 04:37:08 EDT 2005

Tomasz Zielonka wrote:
>>>>voidcast v@(VariantWithTwo{}) = v { field1 = Void , field2 = Void }
>>>>voidcast v@(VariantWithOne{}) = v { field1 = Void }
>>I would not expect that updating only field1 can change the type of v.
> But it can. Note that if you change the second field1 to field3 (both in
> datatype definition and voidcast function), the code will be accepted.
>>The right thing is to construct a new value.
> In the report, section 3.15.3, "Updates Using Field Labels", the
> translation is simply a pattern-match and (re-)construction.  There is
> no requirement that "input" and "output" types are the same. It can be a
> nice feature actually, I've used it once or twice.

Obviously this (magic) reconstruction does not work always (and not in
the given case). Even consecutive updates (that could be recognized by
the desugarer) don't work:

voidcast v at VariantWithTwo{} = v { field1 = Void} {field2 = Void }

I think, the type checker of programatica requires that input and output
type of updated values are the same (not only because comma-separated
field updates are desugared to consecutive updates.)


More information about the Haskell-Cafe mailing list