lists searches in SYB or uniplate haskell
Posted
by Chris
on Stack Overflow
See other posts from Stack Overflow
or by Chris
Published on 2010-03-11T19:50:25Z
Indexed on
2010/03/11
19:54 UTC
Read the original article
Hit count: 205
haskell
|tree-traversal
I have been using uniplate and SYB and I am trying to transform a list
For instance
type Tree = [DataA]
data DataA = DataA1 [DataB]
| DataA2 String
| DataA3 String [DataA]
deriving Show
data DataB = DataB1 [DataA]
| DataB2 String
| DataB3 String [DataB]
deriving Show
For instance, I would like to traverse my tree and append a value to all [DataB]
So my first thought was to do this:
changeDataB:: Tree -> Tree
changeDataB = everywhere(mkT changeDataB')
chanegDataB'::[DataB] -> [DataB]
changeDataB' <add changes here>
or if I was using uniplate
changeDataB:: Tree -> Tree
changeDataB = transformBi changeDataB'
chanegDataB'::[DataB] -> [DataB]
changeDataB' <add changes here>
The problem is that I only want to search on the full list. Doing either of these searches will cause a search on the full list and all of the sub-lists (including the empty list)
The other problem is that a value in [DataB] may generate a [DataB], so I don't know if this is the same kind of solution as not searching chars in a string.
I could pattern match on DataA1 and DataB3, but in my real application there are a bunch of [DataB]. Pattern matching on the parents would be extensive.
The other thought that I had was to create a
data DataBs = [DataB]
and use that to transform on. That seems kind of lame, there must be a better solution.
© Stack Overflow or respective owner