Skip to content

Instantly share code, notes, and snippets.

@devnoo
Created November 10, 2012 15:42
Show Gist options
  • Save devnoo/4051422 to your computer and use it in GitHub Desktop.
Save devnoo/4051422 to your computer and use it in GitHub Desktop.
seven languages in seven weeks : haskell day 1
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) []
let colors= ["black", "white","blue","yellow","red"]
[(a,b) | a<-colors, b<-colors, a<=b]
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]
[(factor,multiplier,factor * multiplier)| factor <- numbers, multiplier <- numbers]
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