Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Haskell One Liners

View haskell_one_liners
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
-- Inspired by http://solog.co/47/10-scala-one-liners-to-impress-your-friends/
 
-- Double everything in a list
map (*2) [1..10]
 
-- Sum a list of numbers
sum [1..1000]
 
-- Verify if exists in a string (thanks to hammar for this: http://stackoverflow.com/questions/6224315/how-to-verify-if-some-items-are-in-a-list)
any (`elem` ["haskell", "ghc", "monads", "cabal"]) $ words "this is a piece of example text talking about haskell and ghc"
 
-- read in a file
readFile "file.txt" >>= return . lines
 
-- Sing happy birthday
putStr "Who's the birthday boy then? > " >> getLine >>= (\name -> mapM_ (\i -> putStrLn $ "Happy Birthday" ++ (if (i == 3) then " dear " ++ name else " to you!")) [1..4])
 
-- Filter/partiton a list of numbers
partition (>60) [49, 58, 76, 82, 88, 90]
 
-- Fetch and Parse an XML web service
 
-- Find a minimum or maximum in a list
maximum [14, 35, -7, 46, 98]
minimum [14, 35, -7, 46, 98]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.