Last active
September 26, 2015 08:31
-
-
Save JustusAdam/0d793b4ef86711273f68 to your computer and use it in GitHub Desktop.
Added second version
This file contains 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
{- read a file, filter out all words in quotes that are at the beginning of a line, and print the resulting words. Using functions from Prelude only -} | |
main = readFile "input.txt" >>= mapM (putStrLn . (('\"' :) . (++ "\"") . takeWhile (/= '\"') . tail)) . filter ((== '\"') . head) . lines | |
{- here's another version, that's a bit more hacky in my opinion, but closer to the original (and shorter than the ruby code ;) -} | |
main=readFile"input.txt">>=mapM(putStrLn.takeWhile(/=' ')).filter((=='\"').head).lines |
As is typical in Haskell it uses a bunch of partial functions and is mostly read from right to left.
If you're unfamiliar with the syntax it can be quite difficult to understand whats going on 😄
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
wow, that actually is less readable than the ruby version :D
I got to catch up on haskell some day