summaryrefslogtreecommitdiff
path: root/monad/h3.hs
diff options
context:
space:
mode:
authorJoe Zhao <ztuowen@gmail.com>2015-08-24 15:45:45 -0600
committerJoe Zhao <ztuowen@gmail.com>2015-08-24 15:45:45 -0600
commit6588473adf96a3eb7cfac55820ec022d4533fcbf (patch)
treedcc6d21e7ce8ed368eda73a7fd74eca5340355ed /monad/h3.hs
parent3cf3e36b1498271f3c9162576809d886482e6d97 (diff)
downloadtypeclass-6588473adf96a3eb7cfac55820ec022d4533fcbf.tar.gz
typeclass-6588473adf96a3eb7cfac55820ec022d4533fcbf.tar.bz2
typeclass-6588473adf96a3eb7cfac55820ec022d4533fcbf.zip
FoldablesHEADmaster
Diffstat (limited to 'monad/h3.hs')
-rw-r--r--monad/h3.hs11
1 files changed, 11 insertions, 0 deletions
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