Hello Henry,<br><br>The paper &quot;A Lightweight Approach To Datatype-Generic Rewriting&quot; [1] describes a way to generically add a constructor to any regular datatype using type-indexed datatypes [2]. A similar technique could be used to add a new field to each constructor. Then you get something like:<br>

<br><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote"><span style="font-family: courier new,monospace;">data Foo</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">type Extended f = ...</span><span style="font-family: courier new,monospace;"></span><br></blockquote><br>|Extended Foo| represents your |Foo| datatype with an added |z| field of type |Int|. Since the underlying generic programming library used (regular [3]) has Template Haskell generation, you don&#39;t even have to write the generic representations for your many datatypes.<br>

<br>(As far as I know, SYB does not mix with type-indexed datatypes.)<br><br><br>Cheers,<br>Pedro<br><br>[1] Thomas van Noort, Alexey Rodriguez, Stefan Holdermans, Johan Jeuring, Bastiaan Heeren. A Lightweight Approach to Datatype-Generic Rewriting. Submitted to the Workshop on Generic Programming 2008. <a href="http://www.cs.uu.nl/wiki/bin/view/Alexey/ALightweightApproachToDatatype-GenericRewriting">http://www.cs.uu.nl/wiki/bin/view/Alexey/ALightweightApproachToDatatype-GenericRewriting</a><br>

[2] <a href="http://www.iai.uni-bonn.de/~ralf/publications/SCP2004.pdf">http://www.iai.uni-bonn.de/~ralf/publications/SCP2004.pdf</a><br>[3] <a href="http://www.cs.uu.nl/wiki/GenericProgramming/Regular">http://www.cs.uu.nl/wiki/GenericProgramming/Regular</a><br>

<br><div class="gmail_quote">On Tue, Jul 28, 2009 at 16:29, Henry Laxen <span dir="ltr">&lt;<a href="mailto:nadine.and.henry@pobox.com">nadine.and.henry@pobox.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

Dear Group,<br>
<br>
It seems to me this should be easy, but I can&#39;t quite figure out<br>
how to do it without a lot of typing.  Here is the question:<br>
<br>
Suppose you have a data type like:<br>
Data Foo = Foo { a :: Int, b :: Int,<br>
   ... many other fields ...<br>
 y :: Int } deriving (Eq, Read, Show, Typeable, Data)<br>
<br>
Now I would like to add a field z :: Int to the end of Foo.  If<br>
I have a ton of data out on disk, which I wrote with, say<br>
writeFile &quot;a.data&quot; (show foo) -- where foo is a [Foo] say 1000<br>
long, I would like to get a new &quot;a.data&quot; file which has a new<br>
z::Int field.<br>
<br>
So far the only way I can think of is to make a new Data Foo1,<br>
which includes the z::Int, read in a.data as a list of Foo,<br>
write a function like:<br>
<br>
fooTofoo1 :: Foo -&gt; Foo1<br>
fooTofoo1 xx = Foo1 {a = a xx, ... y = y xx, z = 1}<br>
<br>
then write the file back out, and perhaps use emacs to<br>
query-replace all the Foo1&#39;s back to Foo&#39;s, add the z::Int field<br>
back into Foo, and read it back.<br>
<br>
Please tell me there is a better way.  Thanks in advance.<br>
Best wishes,<br>
Henry Laxen<br>
<br>
PS:<br>
I have read syb1, and syb2 a couple of times now, but so far<br>
haven&#39;t been able to connect it with this kind of problem.<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</blockquote></div><br>