Skip to content

Instantly share code, notes, and snippets.

@JustusAdam
Last active September 26, 2015 08:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JustusAdam/0d793b4ef86711273f68 to your computer and use it in GitHub Desktop.
Save JustusAdam/0d793b4ef86711273f68 to your computer and use it in GitHub Desktop.
Added second version
{- 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
@JustusAdam
Copy link
Author

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