summaryrefslogtreecommitdiff
path: root/monad/h3.hs
blob: 9439331e87ebd80015035ef350856e3cb80c7d66 (plain)
1
2
3
4
5
6
7
8
9
10
11
data Free f a = Var a
              | Node (f (Free f a))

instance Functor f => Functor (Free f) where
    fmap g (Var a) = g a
    fmap g (Node a) = fmap g a

instance Functor f => Monad (Free f) where
    return a = Var a
    (Var a) >>= g = g a
    (Node a) >>= g = fmap g a