[Haskell-cafe] type inference and named fields

Christian Maeder maeder at tzi.de
Mon Jun 27 09:16:07 EDT 2005


Malcolm Wallace wrote:
> I believe this is a very different question from the consecutive
> update one.  

I agree, consecutive and parallel updates are quite different.

> I can see no
> reason to outlaw a type change, where all the relevant types change
> at the same time:
> 
>   update_ok  v@(A{}) = v { one=Void, two=Void }
>   update_ok' v@(A{}) = (\A one two -> A Void Void) v

Because typing fails in your original example:

voidcast v at VariantWithOne{} = v {field1 = Void}

What would be the "lambda equivalent"?

> voidcast v at VariantWithOne{} =
    (\ (VariantWithOne a) -> VariantWithOne Void) v

would go through. Whereas

> voidcast v at VariantWithOne{} = ( \ x -> case x of
     VariantWithTwo a b -> VariantWithTwo Void b
     VariantWithOne a -> VariantWithOne Void) v

fails like the field notation.

I think writing "VariantWithOne {field1 = Void}" instead of
"v {field1 = Void}" is as clear as writing "Right r" again on the rhs
instead of "x" from the pattern "x@(Right r)"

Christian


More information about the Haskell-Cafe mailing list