We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4d896fb commit a359699Copy full SHA for a359699
chapter16/heavy_lifting.hs
@@ -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