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 }
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
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
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
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
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
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