summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2013-02-28 19:56:15 +0000
committerDaniel Silverstone <dsilvers@digital-scurf.org>2013-02-28 19:56:15 +0000
commit0adc2afc0e54a2eed615f3c98c91db27fd495f25 (patch)
treef202f6973e8e9672d155cf1599923f8d15208285
parent900e22461160a8b869f9c2f66c67c90f5546f4b5 (diff)
downloadcalculator-0adc2afc0e54a2eed615f3c98c91db27fd495f25.tar.bz2
Pre-parsing.
This is the skeleton from before we started to write the parser. You can start from here if you want to play around with writing your own calculator.
-rw-r--r--calculator.hs16
1 files changed, 16 insertions, 0 deletions
diff --git a/calculator.hs b/calculator.hs
new file mode 100644
index 0000000..7753022
--- /dev/null
+++ b/calculator.hs
@@ -0,0 +1,16 @@
+import Text.Parsec
+import Text.Parsec.String
+
+calculation :: Parser Int
+calculation = return undefined
+
+calculate :: String -> String
+calculate s =
+ case ret of
+ Left e -> "error: " ++ (show e)
+ Right n -> "answer: " ++ (show n)
+ where
+ ret = parse calculation "" s
+
+main :: IO ()
+main = interact (unlines . (map calculate) . lines)