-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImAListComprehension.fr
34 lines (22 loc) · 1.09 KB
/
ImAListComprehension.fr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
module learnyou.chapter02.ImAListComprehension where
boomBangs xs = [ if x < 10 then "BOOM!" else "BANG!" | x <- xs, odd x ]
nouns = [ "hobo", "frog", "pope" ]
adjectives = [ "lazy", "grouchy", "scheming" ]
length' xs = sum [ 1 | _ <- xs ]
removeNonUppercase st = [ c | c <- st, c `elem` [ 'A' .. 'Z' ] ]
xxs = [ [ 1, 3, 5, 2, 3, 1, 2, 4, 5 ]
, [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
, [ 1, 2, 4, 2, 1, 6, 3, 1, 3, 2, 3, 6 ]
]
main _ = do
println $ [ x * 2 | x <- [ 1 .. 10 ] ]
println $ [ x * 2 | x <- [ 1 .. 10 ], x * 2 >= 12 ]
println $ [ x | x <- [ 50 .. 100 ], x `mod` 7 == 3 ]
println $ boomBangs [ 7 .. 13 ]
println $ [ x | x <- [ 10 .. 20 ], x != 13, x != 15, x != 19 ]
println $ [ x * y | x <- [ 2, 5, 10 ], y <- [ 8, 10, 11 ] ]
println $ [ x * y | x <- [ 2, 5, 10 ], y <- [ 8, 10, 11 ], x * y > 50 ]
println $ [ adjective ++ " " ++ noun | adjective <- adjectives, noun <- nouns ]
println $ packed $ removeNonUppercase "Hahaha! Ahahaha!"
println $ packed $ removeNonUppercase "IdontLIKEFROGS"
println $ [ [ x | x <- xs, even x ] | xs <- xxs ]