Skip to content

Commit

Permalink
Merge pull request adambard#1006 from nero-luci/master
Browse files Browse the repository at this point in the history
Update haskell.html.markdown. Wrong explanation about '$' operator
  • Loading branch information
geoffliu committed Mar 27, 2015
2 parents bc7fd77 + e8a1ee8 commit 1f49ae9
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions haskell.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,20 @@ 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
(even (fib 7)) -- false

-- after
even . fib $ 7 -- true
even . fib $ 7 -- false

-- equivalently
even $ fib 7 -- true
even $ fib 7 -- false

----------------------------------------------------
-- 5. Type signatures
Expand Down

0 comments on commit 1f49ae9

Please sign in to comment.