Slide 24
Slide 24 text
Lists
reverse :: [Char] -> String -- reverse [1,2,3] == [3,2,1]
reverse [] = []
reverse (h:t) = reverse t ++ [h]
concat :: [[Int]] -> [Int] -- concat [[1,2],[3,4]] == [1,2,3,4]
Lists are written using [ , , , ]
“Cons”-operator is infix (:) :: a -> [a] -> [a]
Syntactic sugar for lists:
[1,2,3,4] -- shorthand for 1:2:3:4:[]
[’c’..’g’] -- evaluates to "cdefg"
[1,3..10] -- evaluates to [1,3,5,7,9]
List comprehension similar notated to math. set-compreh.
[ (x,z) | x <- [1,3..5], y <- [0..x], even y, let z = y+1 ]
evaluates to [(1,1),(3,1),(3,3),(5,1),(5,3),(5,5)]