Last active
August 29, 2015 13:58
-
-
Save jamescrowley/10010374 to your computer and use it in GitHub Desktop.
Haskell - Seven languages in Seven Weeks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Question 1 | |
allEven :: [Integer] -> [Integer] | |
allEven [] = [] | |
allEven (h:t) = if even h then h:allEven t else allEven t | |
allEven2 :: [Integer] -> [Integer] | |
allEven2 list = [a | a <- list, even a] | |
-- Question 2 | |
reverse2 [] = [] | |
reverse2 (h:t) = (reverse t) | |
reverse3 list = rev list [] | |
where | |
rev [] y = y | |
rev (x:xs) y = rev xs (x:y) | |
-- Question 3 | |
let allColours = [(a,b) | a <- colours, b <- colours, a < b] | |
where colours = ["black","white","blue","yellow","red"] | |
-- Question 4 | |
let multiplicationTable = [(a,b,a * b) | a <- [1..12], b <- [1..12] ] | |
-- Question 5 | |
let colours = ["red", "green", "blue"] | |
[(alabama, mississippi, georgia, tennessee, florida) | | |
alabama <- colours, | |
mississippi <- colours, | |
georgia <- colours, | |
tennessee <- colours, | |
florida <- colours, | |
mississippi /= tennessee, | |
mississippi /= alabama, | |
alabama /= tennessee, | |
alabama /= georgia, | |
alabama /= florida, | |
georgia /= florida, | |
georgia /= tennessee] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment