Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Haskell One Liners
-- 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.