We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 144efaf commit 27becdeCopy full SHA for 27becde
12-monads-and-more/12.05-exercises.hs
@@ -0,0 +1,25 @@
1
+-- 1.
2
+data Tree a = Leaf
3
+ | Node (Tree a) a (Tree a)
4
+ deriving Show
5
+
6
+instance Functor Tree where
7
+ fmap f (Node l x r) = Node (fmap f l) (f x) (fmap f r)
8
+ fmap _ Leaf = Leaf
9
10
+-----------------------------------------------------------------------------
11
+-- 2.
12
+--
13
+-- |
14
+-- Avoid conflict with library definition for `((->) r)`
15
+newtype R r a = R
16
+ { run :: r -> a }
17
18
+instance Functor (R r) where
19
+ fmap f (R r) = R $ f . r
20
21
+applyR :: (Int -> Int) -> R Int Int -> Int -> Int
22
+applyR f r x = run (fmap f r) x
23
24
+runR :: Int
25
+runR = applyR (+100) (R $ (+2)) 3
0 commit comments