diff options
-rw-r--r-- | functor/h1.hs | 7 | ||||
-rw-r--r-- | functor/h2.hs | 2 | ||||
-rw-r--r-- | functor/h3.hs | 6 |
3 files changed, 15 insertions, 0 deletions
diff --git a/functor/h1.hs b/functor/h1.hs new file mode 100644 index 0000000..11688ad --- /dev/null +++ b/functor/h1.hs @@ -0,0 +1,7 @@ +data MyEither a b = MyLeft a | MyRight b + deriving (Show) + +instance Functor (MyEither a) where + fmap f (MyLeft a) = MyLeft a + fmap f (MyRight b) = MyRight (f b) + diff --git a/functor/h2.hs b/functor/h2.hs new file mode 100644 index 0000000..54be77c --- /dev/null +++ b/functor/h2.hs @@ -0,0 +1,2 @@ +instance Functor ((->) e) where + fmap = (.) diff --git a/functor/h3.hs b/functor/h3.hs new file mode 100644 index 0000000..1a048f6 --- /dev/null +++ b/functor/h3.hs @@ -0,0 +1,6 @@ +data ITree a = + Leaf (Int -> a) | Node [ITree a] + +instance Functor ITree where + fmap f (Node x) = Node (fmap (fmap f) x) + fmap f (Leaf x) = Leaf (f.x) |