mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-01-17 21:49:22 +01:00
added info about tuples, integrated wild card use into a function definition
This commit is contained in:
parent
0d211d3419
commit
8c30522d58
@ -124,6 +124,9 @@ last [1..5] -- 5
|
|||||||
fst ("haskell", 1) -- "haskell"
|
fst ("haskell", 1) -- "haskell"
|
||||||
snd ("haskell", 1) -- 1
|
snd ("haskell", 1) -- 1
|
||||||
|
|
||||||
|
-- pair element accessing does not work on n-tuples (i.e. triple, quadruple, etc)
|
||||||
|
snd ("snd", "can't touch this", "da na na na") -- error! see function below to get around this
|
||||||
|
|
||||||
----------------------------------------------------
|
----------------------------------------------------
|
||||||
-- 3. Functions
|
-- 3. Functions
|
||||||
----------------------------------------------------
|
----------------------------------------------------
|
||||||
@ -159,8 +162,8 @@ fib 1 = 1
|
|||||||
fib 2 = 2
|
fib 2 = 2
|
||||||
fib x = fib (x - 1) + fib (x - 2)
|
fib x = fib (x - 1) + fib (x - 2)
|
||||||
|
|
||||||
-- Pattern matching on tuples:
|
-- Pattern matching on tuples, using wild card (_) to bypass naming an unused value
|
||||||
foo (x, y) = (x + 1, y + 2)
|
sndOfTriple (_, y, _) = y
|
||||||
|
|
||||||
-- Pattern matching on lists. Here `x` is the first element
|
-- Pattern matching on lists. Here `x` is the first element
|
||||||
-- in the list, and `xs` is the rest of the list. We can write
|
-- in the list, and `xs` is the rest of the list. We can write
|
||||||
|
Loading…
x
Reference in New Issue
Block a user