<div dir="ltr"><div>Have you looked at this? <a href="https://hackage.haskell.org/package/Annotations">https://hackage.haskell.org/package/Annotations</a><br><br></div>Alan<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jul 29, 2015 at 5:43 PM, Merijn Verstraaten <span dir="ltr"><<a href="mailto:merijn@inconsistent.nl" target="_blank">merijn@inconsistent.nl</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
So I'm playing around with using bound to define a simple AST using the bound library to deal with substitution/abstraction.<br>
<br>
Being a lazy haskeller I figured that ASTs map nicely onto Free and that I could get all the necessary Applicative, Monad, etc. instances for free by using something like:<br>
<br>
newtype Expr a = Expr { unExpr :: Free (ExprF Expr) a }<br>
deriving (Functor,Applicative,Monad,Foldable,Traversable)<br>
<br>
data ExprF f a<br>
= App (f a) (f a)<br>
| Lam Type (Scope () f a)<br>
| TmTrue<br>
| TmFalse<br>
| If (f a) (f a) (f a)<br>
deriving (Eq,Ord,Show,Read,Functor,Foldable,Traversable)<br>
<br>
Now, for an AST to be useful, it has to be annotated with things like source location, type info, etc. So I started looking into how to accomplish this in a way where it's easy to add/modify annotations on any node of the AST.<br>
<br>
My initial idea was to use FreeT with ((,) a) as a base monad for annotations, but I quickly realised this fails, because "((,) a)" is only a Monad if 'a' is a Monoid and there's no sensible Monoid for type information/source locations.<br>
<br>
Then I looked around more and realised that this actually sounds a lot like Cofree. But here's where I run into problems. Bound expects the type of variables to be in the functor position of my Expr type, whereas Cofree expects the type of *annotations* to be in the functor position.<br>
<br>
So I can't figure out an elegant way to both use bound to deal with substitution for me *and* use Cofree to deal with annotations, since there's no way to make the types line up sanely.<br>
<br>
So my question boils down too: Has anyone done all the hard work for me already? i.e. how can I have an annotated AST with substitution *and* an easy way to modify the annotations, without writing a ton of boiler plate to deal with substitution and/or annotations?<br>
<br>
Cheers,<br>
Merijn<br>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br></div>