mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-09 08:16:58 +02:00
Merge pull request #1006 from nero-luci/master
Update haskell.html.markdown. Wrong explanation about '$' operator
This commit is contained in:
@@ -202,19 +202,20 @@ foo = (*5) . (+10)
|
|||||||
foo 5 -- 75
|
foo 5 -- 75
|
||||||
|
|
||||||
-- fixing precedence
|
-- fixing precedence
|
||||||
-- Haskell has another function called `$`. This changes the precedence
|
-- Haskell has another operator called `$`. This operator applies a function
|
||||||
-- so that everything to the left of it gets computed first and then applied
|
-- to a given parameter. In contrast to standard function application, which
|
||||||
-- to everything on the right. You can use `$` (often in combination with `.`)
|
-- has highest possible priority of 10 and is left-associative, the `$` operator
|
||||||
-- to get rid of a lot of parentheses:
|
-- 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
|
-- before
|
||||||
(even (fib 7)) -- true
|
(even (fib 7)) -- false
|
||||||
|
|
||||||
-- after
|
-- after
|
||||||
even . fib $ 7 -- true
|
even . fib $ 7 -- false
|
||||||
|
|
||||||
-- equivalently
|
-- equivalently
|
||||||
even $ fib 7 -- true
|
even $ fib 7 -- false
|
||||||
|
|
||||||
----------------------------------------------------
|
----------------------------------------------------
|
||||||
-- 5. Type signatures
|
-- 5. Type signatures
|
||||||
|
Reference in New Issue
Block a user