On 3/4/11 2:32 PM, Jason Dusek wrote:
On Fri, Mar 4, 2011 at 07:01, wren ng thornton<w...@freegeek.org>  wrote:
where the annotation of MergeAnn is merged with the previous
annotation up the tree (via mappend), thus allowing for
annotations to be inherited and modified incrementally based
on the Monoid instance; whereas the NewAnn constructor uses
the annotation directly, overriding any contextual
annotations. This can be helpful to reduce the amount of
duplication in the AST, though how helpful will depend on how
you plan to use/generate the ASTs.

   To handle this situation, I thought I'd leave it in the hands
   of the user (who will be me later) to use Data.Foldable.fold
   (or not) to arrive at the annotation when building up their
   tree of statements. I don't anticipate a problem with this but
   I may not use monoidal annotations on this AST for some time.
   (I anticipate using comments and raw text inclusions in the
   near future.)

That could be a workable solution. The tricky thing is that sometimes you want to mix the monoidal merge behavior of the annotation with the monoidal override behavior I mentioned, and it can get ugly to do that in one monoid. Whenever dealing with problems like this I often find myself running into semirings-- i.e., two monoids that interact in a sensible way. If you'll be wanting a semiring then the Foldable solution doesn't work very well. Again, it depends on what exactly you're planning to do with these ASTs.

--
Live well,
~wren

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to