From 1c35f8f304a349b7fa8c5eb6c6256d707f0987fd Mon Sep 17 00:00:00 2001 From: Joe Zhao Date: Wed, 25 Mar 2015 15:50:18 +0800 Subject: functors --- functor/h5.hs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 functor/h5.hs (limited to 'functor/h5.hs') 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 -- cgit v1.2.3-70-g09d2