[Haskell-beginners] Haskell's Scrap Your Boilerplate (SYB) - applying transformation only once instead of everywhere

Duc le anh anhducit at gmail.com
Tue Jun 4 09:31:31 CEST 2013


What's the best way to apply a transformation to a tree only once instead
of everywhere using SYB? For instance, in the following simplified
expression, there are several instances of Var "x", and I want to replace
the first instance with Var "y" only.

data Exp = Var String | Val Int | Plus Exp Exp |...

myExp = Val 5 `Plus` Var "x" `Plus` Val 5 `Plus` Var "x" ...

This can't be done using the everywhere combinator since it will try to
transform all instances of Var "x" toVar "y".

-- 
Duc A. Le
PS: I also asked this on stackoverflow but figured that I might get a
faster response here. Thank you!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130604/248d2198/attachment.htm>


More information about the Beginners mailing list