Created
November 10, 2012 15:42
-
-
Save devnoo/4051422 to your computer and use it in GitHub Desktop.
seven languages in seven weeks : haskell day 1
This file contains hidden or 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
module Main where | |
allEvenWithRecursion :: [Integer] -> [Integer] | |
allEvenWithRecursion [] = [] | |
allEvenWithRecursion (h:t) = if even h then h:allEvenWithRecursion t else allEvenWithRecursion t | |
allEvenWithListComprehension :: [Integer] -> [Integer] | |
allEvenWithListComprehension (numbers) = [x | x <- numbers , even x ] | |
allEvenWithFilter:: [Integer] -> [Integer] | |
allEvenWithFilter = filter even | |
allEvenWithFoldRight :: [Integer] -> [Integer] | |
allEvenWithFoldRight = foldr (\x xs -> if even x then x:xs else xs) [] | |
allEvenWithFoldLeft :: [Integer] -> [Integer] | |
allEvenWithFoldLeft = foldl (\x xs -> if even xs then x ++ [xs] else x) [] |
This file contains hidden or 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
let colors= ["black", "white","blue","yellow","red"] | |
[(a,b) | a<-colors, b<-colors, a<=b] |
This file contains hidden or 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
let colors= ["red" , "green" , "blue"] | |
[("Alabama" ,alabamaColor, "Mississipi", mississipiColor, "Georgia", georgiaColor, "Tennessee", tennesseeColor, "Florida", floridaColor) | alabamaColor <- colors, mississipiColor <- colors, georgiaColor <- colors, tennesseeColor <- colors, floridaColor <- colors, mississipiColor /= tennesseeColor, mississipiColor /= alabamaColor, alabamaColor /= tennesseeColor, alabamaColor /= georgiaColor, alabamaColor /= floridaColor,georgiaColor /= floridaColor, georgiaColor /= tennesseeColor] |
This file contains hidden or 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
[(factor,multiplier,factor * multiplier)| factor <- numbers, multiplier <- numbers] |
This file contains hidden or 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
reverseList :: [a] -> [a] | |
reverseList [] = [] | |
reverseList (head:tail) = reverseList tail ++ [head] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment