[Haskell-cafe] type inference and named fields

Christian Maeder maeder at tzi.de
Thu Jun 23 15:08:12 EDT 2005


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.
The right thing is to construct a new value. This looks as follows with
record syntax:

voidcast VariantWithTwo{} =
    VariantWithTwo { field1 = Void , field2 = Void }
voidcast VariantWithOne{} =
    VariantWithOne { field1 = Void }

Christian


More information about the Haskell-Cafe mailing list