Skip to content

Instantly share code, notes, and snippets.

@octopuscabbage
Created April 27, 2015 01:40
Show Gist options
  • Save octopuscabbage/6fc231d65f070ddb6cad to your computer and use it in GitHub Desktop.
Save octopuscabbage/6fc231d65f070ddb6cad to your computer and use it in GitHub Desktop.
Golf is fun
import Text.ParserCombinators.Parsec
main = (getLine >>= \line -> putStrLn . either show show $ ((parse (many digit >>= \d1 -> oneOf ['+','-','/','*'] >>= \f -> many digit >>= \d2 -> return (read d1, (if (f == '+') then (+) else if (f=='-') then (-) else if (f == '*') then (*) else if (f == '/') then (/) else undefined), read d2)) "golf parser"line) >>= \(d1,f,d2)->return (f d1 d2)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment