Skip to content

Instantly share code, notes, and snippets.

@JustusAdam
Last active September 26, 2015 08:31
Show Gist options
  • 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
@hoodie
Copy link

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
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