pattern-matching with labelled types

Andre W B Furtado [email protected]
Thu, 7 Mar 2002 22:49:00 -0300


If I have:

> data MyType = MT {
>     x :: Int,
>     y :: Char
>     }

How do I update the Int value of MyType leaving the Char value unaffected? I
tryied something like:

> MT {x = newValue}

but GHC gave me a warning about the Char value and it indeed caused strange
effects. Of course, it is possible to do something like

> update :: MyType -> Int -> MyType
> update mt newValue = MT {x = newValue, y = oldValue}
>     where oldValue = y mt

but this really annoys me when MyType has too many fields. Suggestions?

Thanks a lot,
-- Andre