Skip to content

Commit 2b021cf

Browse files
committed
partial-application: get into a compiling state
1 parent 9454a25 commit 2b021cf

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

partial-application.hs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
map next [1..5]
2-
map (\x -> x + 1) [1..5]
1+
main = undefined
2+
3+
-- map next [1..5]
4+
-- map (\x -> x + 1) [1..5]
35

46
-- CURRYING:
57
-- f :: X -> Y -> Z -> A
@@ -11,22 +13,22 @@
1113

1214
-- currying explained with lambdas:
1315

14-
\x y z -> x + y + z
16+
-- \x y z -> x + y + z
1517

1618
-- the same as
1719

18-
\x -> (\y z -> x + y + z)
20+
-- \x -> (\y z -> x + y + z)
1921

2022
-- the same as
2123

22-
\x -> (\y -> (\z -> x + y + z))
24+
-- \x -> (\y -> (\z -> x + y + z))
2325

2426
-- because all functions can be seen as functions with single argument, partial application is possible
2527

26-
add x y = x+y
27-
add x y = (add x) y
28-
add3 = add 3 -- = \y -> 3 + y
29-
add3 4 -- = (add 3) 4 = add 3 4 = 7
28+
-- add x y = x+y
29+
-- add x y = (add x) y
30+
-- add3 = add 3 -- = \y -> 3 + y
31+
-- add3 4 -- = (add 3) 4 = add 3 4 = 7
3032

3133
-- this is also the reason why it is possible to write things like this:
32-
map (+1) [1..5]
34+
-- map (+1) [1..5]

0 commit comments

Comments
 (0)