[Haskell-cafe] nested datatypes

Thomas Girod girodt at gmail.com
Sun Aug 26 13:24:32 EDT 2007

Hi there.

recently I was trying to represent complex data by defining several
datatypes and nesting them, such as

data Foo = Foo { foo :: Bar }
    deriving (Eq,Show)
data Bar = Bar { bar :: Int }
    deriving (Eq,Show)

To change only a part of the data, syntactic sugar is quite convenient. But
it seems to be quite painful with nested datatypes.

b = Bar 10
f = Foo b

foobar :: Int -> Foo -> Foo
foobar i f =
    let nb = (foo f){bar = i}
    in f{foo = nb}

So, my question is : is there a nifty way to modify data within a nested
datatype, similar to the f{foo = bar} style ? If not, anyone is using some
kind of workaround for this ?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070826/9fef271d/attachment.htm

More information about the Haskell-Cafe mailing list