Create a gist now

Instantly share code, notes, and snippets.

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
@hoodie
hoodie commented Sep 23, 2015

wow, that actually is less readable than the ruby version :D

puts File.open($FILENAME).read().lines().select{|l|l.start_with? ?"}.map{|l|l.split()[0][1..-2]}

I got to catch up on haskell some day

@JustusAdam
Owner

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