1.3 sequences (lists)
To represent something as a list of a certain type, we write
Haskell supports list comprehension, which looks more like set notation. We can look at the base functions for managing lists to understand how exactly this works:
> map :: (a -> b) -> [a] -> [b]
> (map f) xs = [ f x | x <- xs]
Reading this out, map
sends a function of type
filter :: (a -> Bool) -> [a] -> [a]
(filter p) xs = [ f x | x <- xs, p x]
This is almost the exact same, but here
concat :: [[a]] -> [a]
concat xss = [x | xs <- xss, x <-xs]
Note the order of instantiation. Haskell reads it from left to right, and as such needs
As a nice programming type of thing, elements of type String are just lists of Char types, meaning we can do each of these list comprehension functions on a String.