Note that there are some explanatory texts on larger screens.

plurals
  1. POlists searches in SYB or uniplate haskell
    primarykey
    data
    text
    <p>I have been using uniplate and SYB and I am trying to transform a list</p> <p>For instance</p> <pre><code> 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 </code></pre> <p>For instance, I would like to traverse my tree and append a value to all [DataB]</p> <p>So my first thought was to do this:</p> <pre><code>changeDataB:: Tree -&gt; Tree changeDataB = everywhere(mkT changeDataB') chanegDataB'::[DataB] -&gt; [DataB] changeDataB' &lt;add changes here&gt; </code></pre> <p>or if I was using uniplate</p> <pre><code> changeDataB:: Tree -&gt; Tree changeDataB = transformBi changeDataB' chanegDataB'::[DataB] -&gt; [DataB] changeDataB' &lt;add changes here&gt; </code></pre> <p>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)</p> <p>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.</p> <p>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.</p> <p>The other thought that I had was to create a </p> <pre><code>data DataBs = [DataB] </code></pre> <p>and use that to transform on. That seems kind of lame, there must be a better solution.</p> <p>Update: The main reason that I need to do this is that I need to</p> <ol> <li>change the order of [DataB]</li> <li>add something to [DataB]</li> </ol> <p>So if you all know a cool way to create a mkT that would match </p> <p>B1:B2:B3:B4:[] (which would be per say the full list of [DataB]</p> <p>and not</p> <p>B2:B3:B4:[]<br> or any other derivations of that.</p> <p>I am siding to just biting the bullet and createing the "DataBs", data type and doing a simple mkT match on that. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload