diff options
Diffstat (limited to 'functor/h5.hs')
-rw-r--r-- | functor/h5.hs | 14 |
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 |