Skip to content

Instantly share code, notes, and snippets.

Last active September 26, 2015 08:31
What would you like to do?
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
Copy link

hoodie commented Sep 23, 2015

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

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

I got to catch up on haskell some day

Copy link

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