Skip to content

Commit

Permalink
partial-application: get into a compiling state
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-martin committed Feb 23, 2022
1 parent 9454a25 commit 2b021cf
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions partial-application.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
map next [1..5]
map (\x -> x + 1) [1..5]
main = undefined

-- map next [1..5]
-- map (\x -> x + 1) [1..5]

-- CURRYING:
-- f :: X -> Y -> Z -> A
Expand All @@ -11,22 +13,22 @@

-- currying explained with lambdas:

\x y z -> x + y + z
-- \x y z -> x + y + z

-- the same as

\x -> (\y z -> x + y + z)
-- \x -> (\y z -> x + y + z)

-- the same as

\x -> (\y -> (\z -> x + y + z))
-- \x -> (\y -> (\z -> x + y + z))

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

add x y = x+y
add x y = (add x) y
add3 = add 3 -- = \y -> 3 + y
add3 4 -- = (add 3) 4 = add 3 4 = 7
-- add x y = x+y
-- add x y = (add x) y
-- add3 = add 3 -- = \y -> 3 + y
-- add3 4 -- = (add 3) 4 = add 3 4 = 7

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

0 comments on commit 2b021cf

Please sign in to comment.