Skip to content

Commit a359699

Browse files
committed
chapter16: added 3 exercises from heavy lifting exercise
1 parent 4d896fb commit a359699

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

chapter16/heavy_lifting.hs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-- Instructions
2+
-- Add fmap, parentheses, and function composition to the expression
3+
-- as needed for the expression to typecheck and produce the
4+
-- expected result.
5+
6+
-- 1. a = (+1) $ read "[1]" :: [Int]
7+
a :: [Int]
8+
a = fmap (+1) $ (read "[1]" :: [Int])
9+
10+
-- 2. b = (++ "lol") (Just ["Hi,", "Hello"])
11+
-- Expected value of b is Just ["Hi,lol", "Hellolol"]
12+
b :: Maybe [ String ]
13+
b = (fmap . fmap) (++ "lol") (Just ["Hi", "Hello"])
14+
15+
-- 3. c = (*2) (\x -> x - 2)
16+
-- Preluce> c 1
17+
-- -2
18+
-- Solution Note - This one is tricky since the fmap is happening over the function functor (yes, no typo there)
19+
c = fmap (*2) (\x -> x - 2)
20+
21+
main = do
22+
putStrLn (show a)
23+
putStrLn (show b)

0 commit comments

Comments
 (0)