From 6588473adf96a3eb7cfac55820ec022d4533fcbf Mon Sep 17 00:00:00 2001 From: Joe Zhao Date: Mon, 24 Aug 2015 15:45:45 -0600 Subject: Foldables --- monad/h3.hs | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 monad/h3.hs (limited to 'monad/h3.hs') diff --git a/monad/h3.hs b/monad/h3.hs new file mode 100644 index 0000000..9439331 --- /dev/null +++ b/monad/h3.hs @@ -0,0 +1,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 -- cgit v1.2.3-70-g09d2