Skip to content

Instantly share code, notes, and snippets.

@eccstartup
Created November 6, 2014 14:52
Show Gist options
  • Save eccstartup/e32567836c5369c738c7 to your computer and use it in GitHub Desktop.
Save eccstartup/e32567836c5369c738c7 to your computer and use it in GitHub Desktop.
module Lab3 where
-----------------------------------------------------------------------------------------------------------------------------
-- LIST COMPREHENSIONS
------------------------------------------------------------------------------------------------------------------------------
-- ===================================
-- Ex. 0 - 2
-- ===================================
evens :: [Integer] -> [Integer]
evens = filter even
-- ===================================
-- Ex. 3 - 4
-- ===================================
-- complete the following line with the correct type signature for this function
-- squares :: ...
squares :: Integer -> [Integer]
squares n = map (^2) [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' :: ...
squares' :: Integer -> Integer -> [Integer]
squares' m n = map (^2) [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]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment