File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change
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)
You can’t perform that action at this time.
0 commit comments