summaryrefslogtreecommitdiffhomepage
path: root/haskell.html.markdown
diff options
context:
space:
mode:
authorGeoff Liu <cangming.liu@gmail.com>2014-11-27 00:42:20 -0700
committerGeoff Liu <cangming.liu@gmail.com>2014-11-27 00:42:20 -0700
commite1610bf1a93550740072832cff1c647b0869a993 (patch)
tree2d933f5062f8318a841ca4a763692c71d03a9eb3 /haskell.html.markdown
parent448aee0ed7b68d1ad029d78f3ac157eeba8c3555 (diff)
parent1d7f26f2f4ce6d8ff1eeb6055d635b3fd63bbbcf (diff)
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'haskell.html.markdown')
-rw-r--r--haskell.html.markdown19
1 files changed, 11 insertions, 8 deletions
diff --git a/haskell.html.markdown b/haskell.html.markdown
index 2785405c..748a29da 100644
--- a/haskell.html.markdown
+++ b/haskell.html.markdown
@@ -110,7 +110,7 @@ last [1..5] -- 5
-- A tuple:
("haskell", 1)
--- accessing elements of a tuple
+-- accessing elements of a pair (i.e. a tuple of length 2)
fst ("haskell", 1) -- "haskell"
snd ("haskell", 1) -- 1
@@ -195,8 +195,8 @@ 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 `.` and `$` to get rid of a lot
--- of parentheses:
+-- to everything on the right. You can use `$` (often in combination with `.`)
+-- to get rid of a lot of parentheses:
-- before
(even (fib 7)) -- true
@@ -204,6 +204,9 @@ foo 5 -- 75
-- after
even . fib $ 7 -- true
+-- equivalently
+even $ fib 7 -- true
+
----------------------------------------------------
-- 5. Type signatures
----------------------------------------------------
@@ -227,24 +230,24 @@ double :: Integer -> Integer
double x = x * 2
----------------------------------------------------
--- 6. Control Flow and If Statements
+-- 6. Control Flow and If Expressions
----------------------------------------------------
--- if statements
+-- if expressions
haskell = if 1 == 1 then "awesome" else "awful" -- haskell = "awesome"
--- if statements can be on multiple lines too, indentation is important
+-- if expressions can be on multiple lines too, indentation is important
haskell = if 1 == 1
then "awesome"
else "awful"
--- case statements: Here's how you could parse command line arguments
+-- case expressions: Here's how you could parse command line arguments
case args of
"help" -> printHelp
"start" -> startProgram
_ -> putStrLn "bad args"
--- Haskell doesn't have loops because it uses recursion instead.
+-- Haskell doesn't have loops; it uses recursion instead.
-- map applies a function over every element in an array
map (*2) [1..5] -- [2, 4, 6, 8, 10]