87
|
1 module AllEven where
|
|
2 allEven :: [Integer] -> [Integer]
|
|
3 allEven [] = []
|
|
4 -- Note: "h:allEven t" doesn't parse the same as some other languages. We're not invoking anything on "h".
|
|
5 -- It is literally "h" joined to the list made by "allEven t"
|
|
6 allEven (h:t) = if even h then h:allEven t else allEven t
|
|
7
|
|
8 allEvenGuard :: [Integer] -> [Integer]
|
|
9 allEvenGuard [] = []
|
|
10 -- We can't include the empty list case because decomposing an empty list with "h:t" gives the exception "Non-exhaustive patterns in h : t"
|
|
11 allEvenGuard (h:t)
|
|
12 | even h = h:allEven t
|
|
13 | otherwise = allEven t
|
|
14
|
|
15 allEvenComp :: [Integer] -> [Integer]
|
|
16 allEvenComp lst = [x | x <- lst, even x] |