forked from ikhoon/FP101x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chapter6-lab3.hs
45 lines (30 loc) · 1.28 KB
/
chapter6-lab3.hs
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
35
36
37
38
39
40
41
42
43
44
45
module Lab3 where
-----------------------------------------------------------------------------------------------------------------------------
-- LIST COMPREHENSIONS
------------------------------------------------------------------------------------------------------------------------------
-- ===================================
-- Ex. 0 - 2
-- ===================================
evens :: [Integer] -> [Integer]
evens xs = [ x | x <- xs, x `rem` 2 == 0]
-- ===================================
-- Ex. 3 - 4
-- ===================================
-- complete the following line with the correct type signature for this function
squares :: Integer -> [Integer]
squares n = [ x ^ 2 | x <- [1..n]]
sumSquares :: Integer -> Integer
sumSquares n = sum (squares n)
-- ===================================
-- Ex. 5 - 7
-- ===================================
-- complete the following line with the correct type signature for this function
squares' :: Integer -> Integer -> [Integer]
squares' m n = [ x ^ 2 | x <- [n+1..n+m]]
sumSquares' :: Integer -> Integer
sumSquares' x = sum . uncurry squares' $ (x, x)
-- ===================================
-- Ex. 8
-- ===================================
coords :: Integer -> Integer -> [(Integer,Integer)]
coords m n = [ (x, y) | x <- [0..m], y <- [0..n]]