There was an error while loading. Please reload this page.
1 parent d12c351 commit 651f937Copy full SHA for 651f937
chapter12-Monads-and-more/4.hs
@@ -0,0 +1,12 @@
1
+newtype ZipList a = Z [a]
2
+ deriving Show
3
+
4
+instance Functor ZipList where
5
+ -- fmap :: (a -> b) -> ZipList a -> ZipList b
6
+ fmap g (Z xs) = Z (map g xs)
7
8
+instance Applicative ZipList where
9
+ -- pure :: a -> ZipList a
10
+ pure x = Z [x]
11
+ -- (<*>) :: ZipList (a -> b) -> ZipList a -> ZipList b
12
+ (Z gs) <*> (Z xs) = Z $ map (\(f, x) -> f x) (zip gs xs)
0 commit comments