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
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
_
Romildo,
> How should an instance of (Functor ExprF) be defined? It is not shown in
> the thesis.
It's actually quite straigtforward:
instance Functor ExprF where
fmap _ (Num n) = Num n
fmap _ (Var x) = Var x
fmap f (Bin op l r) = Bin op (f l) (f r)
As expected you get:
On Fri, Apr 27, 2012 at 08:39:23AM -0300, romi...@malaquias.dhcp-GERAL wrote:
> On Thu, Apr 26, 2012 at 10:21:36AM +0200, José Pedro Magalhães wrote:
> > Hi Romildo,
> >
> > If I understand correctly, you now want to add annotations to
> > mutually-recursive datatypes. The annotations package supp
On Thu, Apr 26, 2012 at 10:21:36AM +0200, José Pedro Magalhães wrote:
> Hi Romildo,
>
> If I understand correctly, you now want to add annotations to
> mutually-recursive datatypes. The annotations package supports that.
> Section 8 of our paper [1] gives an example of how to do that, and also
> C
Hi Romildo,
If I understand correctly, you now want to add annotations to
mutually-recursive datatypes. The annotations package supports that.
Section 8 of our paper [1] gives an example of how to do that, and also
Chapter 6 of Martijn's MSc thesis [2].
Let me know if these references do not answ
Hello.
I need to annotate abstract syntax tree with additional information in a
compiler.
Using the Annotations package[1] I have written the following small
program:
import Annotations.F.Annotated
import Annotations.F.Fixpoints
data ExprF r
= Num Double
| Var String
| Add r r