summaryrefslogtreecommitdiff
path: root/functor/h5.hs
diff options
context:
space:
mode:
authorJoe Zhao <ztuowen@gmail.com>2015-03-25 15:50:18 +0800
committerJoe Zhao <ztuowen@gmail.com>2015-03-25 15:50:18 +0800
commit1c35f8f304a349b7fa8c5eb6c6256d707f0987fd (patch)
tree18305734a1442ce0b381f0453a7519bcad90f3c9 /functor/h5.hs
parent22fc8bffd0ee10d4e7e4ad7f4c65b472fea4fb50 (diff)
downloadtypeclass-1c35f8f304a349b7fa8c5eb6c6256d707f0987fd.tar.gz
typeclass-1c35f8f304a349b7fa8c5eb6c6256d707f0987fd.tar.bz2
typeclass-1c35f8f304a349b7fa8c5eb6c6256d707f0987fd.zip
functors
Diffstat (limited to 'functor/h5.hs')
-rw-r--r--functor/h5.hs14
1 files changed, 14 insertions, 0 deletions
diff --git a/functor/h5.hs b/functor/h5.hs
new file mode 100644
index 0000000..88bc79a
--- /dev/null
+++ b/functor/h5.hs
@@ -0,0 +1,14 @@
+-- The composition of two Functors is also a Functor.
+
+import Data.Functor
+
+newtype Comp f g a = Comp { unComp :: f (g a) }
+
+compose :: f (g a) -> Comp f g a
+compose = Comp
+
+decompose :: Comp f g a -> f (g a)
+decompose = unComp
+
+instance (Functor f, Functor g) => Functor (Comp f g) where
+ fmap f = compose . fmap (fmap f) . decompose