File tree Expand file tree Collapse file tree 1 file changed +17
-11
lines changed
Expand file tree Collapse file tree 1 file changed +17
-11
lines changed Original file line number Diff line number Diff line change @@ -9,17 +9,23 @@ instance Functor Tree where
99
1010-----------------------------------------------------------------------------
1111-- 2.
12- --
13- -- |
14- -- Avoid conflict with library definition for `((->) r)`
15- newtype R r a = R
16- { run :: r -> a }
12+ instance Functor ((-> ) a ) where
13+ fmap = (.)
1714
18- instance Functor (R r ) where
19- fmap f (R r) = R $ f . r
15+ -----------------------------------------------------------------------------
16+ -- 3.
17+ instance Applicative ((-> ) a ) where
18+ pure x = \ _ -> x
19+ f <*> g = \ x -> f x $ g x
20+
21+ -----------------------------------------------------------------------------
22+ -- 4.
23+ newtype ZipList a = Z [a ]
24+ deriving Show
2025
21- applyR :: ( Int -> Int ) -> R Int Int -> Int -> Int
22- applyR f r x = run (fmap f r) x
26+ instance Functor ZipList where
27+ fmap f ( Z xs) = Z (fmap f xs)
2328
24- runR :: Int
25- runR = applyR (+ 100 ) (R $ (+ 2 )) 3
29+ instance Applicative ZipList where
30+ pure x = Z $ repeat x
31+ Z fs <*> Z xs = Z [f x | (f, x) <- zip fs xs]
You can’t perform that action at this time.
0 commit comments