[Haskell-cafe] Annotated ASTs, and the tension between Bound, Free, and Cofree...

Tom Ellis tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Wed Jul 29 16:01:16 UTC 2015


On Wed, Jul 29, 2015 at 05:43:23PM +0200, Merijn Verstraaten wrote:
> 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:
> 
> newtype Expr a = Expr { unExpr :: Free (ExprF Expr) a }
>    deriving (Functor,Applicative,Monad,Foldable,Traversable)
> 
> data ExprF f a
>  = App (f a) (f a)
>  | Lam Type (Scope () f a)
>  | TmTrue
>  | TmFalse
>  | If (f a) (f a) (f a)
>  deriving (Eq,Ord,Show,Read,Functor,Foldable,Traversable)

By the way, when I was playing around with bound and free I guessed that it
would be more appropriate to define a "higher order" free thing which is
called Mu here:

    Was bound but now I'm free: http://lpaste.net/136836

I'd be grateful if you'd take a look and see if you think it has any benefit
over just using Free.

Tom


More information about the Haskell-Cafe mailing list