Skip to content

Instantly share code, notes, and snippets.

@SuperManEver
Created October 1, 2016 11:41
Show Gist options
  • Save SuperManEver/69b225dd3aab3d02bac833b4cb605640 to your computer and use it in GitHub Desktop.
Save SuperManEver/69b225dd3aab3d02bac833b4cb605640 to your computer and use it in GitHub Desktop.
square x = x * x
double x = x + x
factorial n = if n == 1
then 1
else n * factorial (n - 1)
evaluate f x = f x
sumList l = if null l
then 0
else (head l) + sumList (tail l)
lengthL l = if null l
then 0
else 1 + lengthL (tail l)
multiplyL l = if null l
then 1
else (head l) * multiplyL (tail l)
increaseL l n = if null l
then l
else (head l) * n : increaseL (tail l) n
[x*2 | x <- [1..10]]
take 10 [x | x <- [1..], even x]
take 10 [x | x <- [1..], odd x]
boomBangs xs = [ if x < 10 then "BOOM!" else "BANG!" | x <- xs, odd x]
boomBangs [7..13]
[ x | x <- [10..20], x /= 13, x /= 15, x /= 19]
combineLists xs ys = [x*y | x <- xs, y <- ys]
let nouns = ["hobo", "from", "pope"]
let adjectives = ["lazy", "grouchy", "scheming"]
[noun ++ " " ++ adjective | noun <- nouns , adjective <- adjectives]
length' xs = sum [1 | _ <- xs]
onlyEvens xs = [x | x <- xs, even x]
removeNonUppercase st = [ c | c <- st, c `elem` ['A'..'Z']]
let xxs = [[1,3,5,2,3,1,2,4,5],[1,2,3,4,5,6,7,8,9],[1,2,4,2,1,6,3,1,3,2,3,6]]
[ [ x | x <- xs, even x ] | xs <- xxs]
-- Tuples
zip [1,2,3,4,5] [5,5,5,5,5]
factorial n = product [1..n]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment