diff options
Diffstat (limited to 'haskell.html.markdown')
-rw-r--r-- | haskell.html.markdown | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/haskell.html.markdown b/haskell.html.markdown index 2f807c5f..369b1b20 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -202,19 +202,21 @@ foo = (*5) . (+10) foo 5 -- 75 -- fixing precedence --- Haskell has another function called `$`. This changes the precedence --- so that everything to the left of it gets computed first and then applied --- to everything on the right. You can use `$` (often in combination with `.`) --- to get rid of a lot of parentheses: +-- Haskell has another operator called `$`. This operator applies a function +-- to a given parameter. In contrast to standard function application, which +-- has highest possible priority of 10 and is left-associative, the `$` operator +-- has priority of 0 and is right-associative. Such a low priority means that +-- the expression on its right is applied as the parameter to the function on its left. -- before -(even (fib 7)) -- true - --- after -even . fib $ 7 -- true +even (fib 7) -- false -- equivalently -even $ fib 7 -- true +even $ fib 7 -- false + +-- composing functions +even . fib $ 7 -- false + ---------------------------------------------------- -- 5. Type signatures @@ -281,7 +283,7 @@ foldl (\x y -> 2*x + y) 4 [1,2,3] -- 43 foldr (\x y -> 2*x + y) 4 [1,2,3] -- 16 -- This is now the same as -(2 * 3 + (2 * 2 + (2 * 1 + 4))) +(2 * 1 + (2 * 2 + (2 * 3 + 4))) ---------------------------------------------------- -- 7. Data Types |