[Haskell-cafe] Re: Adding a field to a data record

2009-07-29 Thread Jon Fairbairn
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 }

Re: [Haskell-cafe] Re: Adding a field to a data record

2009-07-29 Thread Lennart Augustsson
With the RecordWildCard extension you should be able to write newFoo Old.Foo{..} = New.Foo { .., z=1 } On Tue, Jul 28, 2009 at 3:47 PM, Henry Laxennadine.and.he...@pobox.com wrote: Malcolm Wallace Malcolm.Wallace at cs.york.ac.uk writes: and perhaps use emacs to query-replace all the

[Haskell-cafe] Re: Adding a field to a data record

2009-07-28 Thread Henry Laxen
Malcolm Wallace Malcolm.Wallace at cs.york.ac.uk writes: and perhaps use emacs to query-replace all the Foo1's back to Foo's At least this bit can be avoided easily enough, by using module qualification during the conversion process. module Original (Foo(..)) where data

Re: [Haskell-cafe] Re: Adding a field to a data record

2009-07-28 Thread Jason Dagit
On Tue, Jul 28, 2009 at 7:47 AM, Henry Laxen nadine.and.he...@pobox.comwrote: Malcolm Wallace Malcolm.Wallace at cs.york.ac.uk writes: and perhaps use emacs to query-replace all the Foo1's back to Foo's At least this bit can be avoided easily enough, by using module qualification

[Haskell-cafe] Re: Adding a field to a data record

2009-07-28 Thread Maurí­cio CA
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

Re: [Haskell-cafe] Re: Adding a field to a data record

2009-07-28 Thread Malcolm Wallace
the part I would really like to avoid is writing the New.Foo { a=a, b=b, ... z=1 } part, where the field names are many, long, and varied. OK, here is another hack-ish trick, since I notice your data is stored on disk as text, using show. I assume you are using something like Read to

Re: [Haskell-cafe] Re: Adding a field to a data record

2009-07-28 Thread Iavor Diatchki
Hello, you may also find the package pretty-show (http://hackage.haskell.org/package/pretty-show) useful. It contains code to convert automatically derived instances of Show into an explicit data structure, which you can then manipulate (e.g., by adding the extra field), and then render back to