-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMain.hs
38 lines (31 loc) · 1.19 KB
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
-- option 1 (https://github.com/PiotrJustyna/haskell-anywhere):
-- ./ghci.bat C:\Users\piotr_justyna\Documents\github\programming-in-haskell\part2_chapter12_exercise2
-- option 2 (stack):
-- stack ghci
-- option 3 (ghci):
-- ghci
--
-- :load Main
-- This exercise doesn't need a solution as the code would not compile.
-- It would not compile, because it clashes with:
-- instance Functor ((->) r) where
-- fmap = (.)
-- It just needs some samples.
-- For reference, this is the dot (composition) operator:
-- (.) :: (b -> c) -> (a -> b) -> (a -> c)
-- My brain just got permanently damaged.
-- I do not fully understand this, but it intuitively makes sense:
-- a partially applied function type (a ->) is a functor when composition is its fmap.
-- Then, to demonstrate that it works, we apply two arguments to fmap:
-- * a function
-- * a function
-- from: https://wiki.haskell.org/Functor
-- class Functor f where
-- fmap :: (a -> b) -> f a -> f b
-- (<$) :: a -> f b -> f a
main = do
-- if I understand the exercise correctly:
putStrLn . show $ (fmap (+1) (*2)) 5
putStrLn . show $ ((+1) . (*2)) 5
putStrLn . show $ ((+1) <$> (*2)) 5
putStrLn . show $ (fmap (show) (+1)) 3