Henry Laxen <nadine.and.he...@pobox.com> writes: > It seems to me this should be easy, but I can't quite figure out > how to do it without a lot of typing. Here is the question: > > Suppose you have a data type like: > Data Foo = Foo { a :: Int, b :: Int, > ... many other fields ... > y :: Int } deriving (Eq, Read, Show, Typeable, Data) > > Now I would like to add a field z :: Int to the end of Foo. If > I have a ton of data out on disk, which I wrote with, say > writeFile "a.data" (show foo) -- where foo is a [Foo] say 1000 > long, I would like to get a new "a.data" file which has a new > z::Int field.
One approach to this would be to temporarily redefine Foo data Foo = Foo { a :: Int, b :: Int, ... many other fields ... y :: Int } deriving (Eq, Read, Show, Typeable, Data) | NuFu {a :: Int, b :: Int, ... many other fields ... y :: Int, z :: Int} deriving (Eq, Read, Show, Typeable, Data) read the file, map Foo to NuFoo + whatever the initial value of z is and write it out again. -- Jón Fairbairn jon.fairba...@cl.cam.ac.uk _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe