[Haskell-cafe] type inference and named fields

Christian Maeder maeder at tzi.de
Fri Jun 24 06:20:52 EDT 2005


Malcolm Wallace wrote:
> Ah, but the reason I want to use field update, rather than a new
> construction on the rhs, is that my type really has lots of other
> fields (not mentioned here), which are all of fixed definite types
> (not parametric).  It is much nicer to be able to write
> 
>     v { field1 = Void }
> 
> than
> 
>     VariantWithOne { field1 = Void
>                    , field2 = field2 v
>                    , field3 = field3 v
>                    , field4 = field4 v
>                    , field5 = field5 v
>                      ...
>                    }

There is no problem with the desirable short version of updating if the
type of v does not change! Only for a polymorphic record data type
suitable map (or update) functions should be considered.

Your long version is (of course) wrongly typed if the type of another
field depends on the type of field1.

Christian


More information about the Haskell-Cafe mailing list