Skip to content

Commit e9fbf9f

Browse files
committed
chapter 16 - Finished all exercises from heavy lifting
1 parent a359699 commit e9fbf9f

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

chapter16/heavy_lifting.hs

+24-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,30 @@ b = (fmap . fmap) (++ "lol") (Just ["Hi", "Hello"])
1616
-- Preluce> c 1
1717
-- -2
1818
-- Solution Note - This one is tricky since the fmap is happening over the function functor (yes, no typo there)
19+
c :: Integer -> Integer
1920
c = fmap (*2) (\x -> x - 2)
2021

22+
-- 4. d = ((return "1" ++) . show) (\x -> [x, 1..3])
23+
-- Prelude> d 0
24+
-- 1[0, 1, 2, 3]
25+
d :: Integer -> String
26+
d = fmap (("1" ++) . show) (\x -> [x, 1..3])
27+
28+
-- 5. e :: IO Integer
29+
-- e = let ioi = readIO "1" :: IO Integer
30+
-- changed = read ("123" ++) show ioi
31+
-- in (*3) changed
32+
-- Prelude> e
33+
-- 3693
34+
e :: IO Integer
35+
e = let ioi = (readIO "1" :: IO Integer)
36+
changed = fmap (read . ("123" ++) . show) ioi
37+
in fmap (*3) changed
38+
39+
main :: IO Integer
2140
main = do
22-
putStrLn (show a)
23-
putStrLn (show b)
41+
print a
42+
print b
43+
print (c 1)
44+
print (d 0)
45+
e

0 commit comments

Comments
 (0)