[Haskell-cafe] Annotations in abstract syntax tree

Ryan Ingram ryani.spam at gmail.com
Fri Apr 27 23:06:42 CEST 2012


For simple datatypes like this, GHC can derive the Functor implementation
for you:

{-# LANGUAGE DeriveFunctor #-}

data ExprF r = ....
  deriving (..., Functor)

See http://www.haskell.org/ghc/docs/7.0.4/html/users_guide/deriving.html

  -- ryan

On Fri, Apr 27, 2012 at 5:40 AM, Stefan Holdermans <stefan at vectorfabrics.com
> wrote:

> Romildo,
>
> > I could write the (Functor ExprF) instance:
> >
> >  instance Functor ExprF where
> >    fmap f expr = case expr of
> >                    Num n -> Num n
> >                    Var v -> Var v
> >                    Bin op x y -> Bin op (f x) (f y)
>
> Yes, excellent. That'll do.
>
> Cheers,
>
>  Stefan
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120427/39bee0db/attachment.htm>


More information about the Haskell-Cafe mailing list