List
++
and:
for concatenationhead
,tail
,init
,last
reverse
take num
,drop num
null
elem
elem 'x' ['a', 'b', 'c']
concat
concat [[3, 1], [2], [], [5, 10]]
- Linear time function
length
!!
index
- range
[1, 3 .. 20]
[1,3,5,7,9,11,13,15,17,19]
[10, 9 .. 1]
[10,9,8,7,6,5,4,3,2,1]
[0 .. ]
infinite lists
String
list
of characters
word
unword
Pakages
-
module — a collection of functions and custom data types
-
package — a collection of modules + metadata
-
Hackage — a central repository of Haskell packages
-
base — standard Haskell library
-
Prelude — the module from base imported by default
-
import Data.List
Control Flow
if then else
price = if product == "milk" then 1 else 2
guards
case of
Misc
let in
where
Maybe
Type | Values |
---|---|
Maybe Bool | Nothing, Just False, Just True |
Maybe Int | Nothing, Just 0, Just 1, … |
Maybe [Int] | Nothing, Just [], Just [1,1337], … |
Either
Constructor
Start with capital letter.