[Haskell-cafe] type inference and named fields

Tomasz Zielonka tomasz.zielonka at gmail.com
Thu Jun 23 15:54:35 EDT 2005

On Thu, Jun 23, 2005 at 09:08:12PM +0200, Christian Maeder wrote:
> Malcolm Wallace wrote:
> >>voidcast :: Fields a -> Fields Void
> >>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.

Best regards

More information about the Haskell-Cafe mailing list