Skip to content

Commit 651f937

Browse files
committed
[exercise] 12.4
1 parent d12c351 commit 651f937

File tree

1 file changed

+12
-0
lines changed
  • chapter12-Monads-and-more

1 file changed

+12
-0
lines changed

chapter12-Monads-and-more/4.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)