summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2013-02-28 20:32:32 +0000
committerDaniel Silverstone <dsilvers@digital-scurf.org>2013-02-28 20:32:32 +0000
commit84b0a3bffdb3e7b0c27beedb356edd3433e2bef2 (patch)
tree7a740d9b9b5dd1c0bc357e392cfcf18dbf39980f
parent445464513287f2f7b6a76974c4fcdf6cba2987d8 (diff)
downloadcalculator-84b0a3bffdb3e7b0c27beedb356edd3433e2bef2.tar.bz2
Parse additions and numbers
-rw-r--r--calculator.hs11
1 files changed, 9 insertions, 2 deletions
diff --git a/calculator.hs b/calculator.hs
index 12f958e..23aab5e 100644
--- a/calculator.hs
+++ b/calculator.hs
@@ -7,10 +7,17 @@ parseNumber = do
n' <- many1 $ oneOf "0123456789"
return (read (neg ++ n'))
+parseAddition :: Parser Int
+parseAddition = do
+ n1 <- parseNumber
+ char '+'
+ n2 <- parseNumber
+ return (n1 + n2)
+
calculation :: Parser Int
calculation = do
- parseNumber
-
+ try parseAddition <|> parseNumber
+
calculate :: String -> String
calculate s =
case ret of