[Haskell] Unnamed fields

Malcolm Wallace Malcolm.Wallace at cs.york.ac.uk
Tue Nov 16 11:07:48 EST 2004


On Tue, 16 Nov 2004 15:04:02 +0000, Ian Lynagh <igloo at earth.li> wrote:

> > Is there a good reason why I can't say
> > 
> >     data Bar = Bar { _ :: Int, _ :: Char, x :: Bool }

Since you only want one field out of many, what is the difficulty in
simply defining the projection/updating functions separately?

    data Bar = Bar Int Char Bool
    x (Bar _ _ b) = b
    (Bar i c _) `updX` b = Bar i c b

Regards,
    Malcolm


More information about the Haskell mailing list