Skip to content

Instantly share code, notes, and snippets.

@softa
Created September 15, 2010 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save softa/580861 to your computer and use it in GitHub Desktop.
Save softa/580861 to your computer and use it in GitHub Desktop.
module Main where
import Text.ParserCombinators.Parsec
runop :: Char -> Integer -> Integer -> Integer
runop '+' n1 n2 = n1 + n2
runop '-' n1 n2 = n1 - n2
runop '*' n1 n2 = n1 * n2
runop '^' n1 n2 = n1 ^ n2
operation :: Parser Integer
operation = do
n1 <- number
o <- operator
n2 <- number
return (runop o n1 n2)
operator :: Parser Char
operator = do
o <- oneOf "+-*^"
return (o)
number :: Parser Integer
number = do
n <- many (oneOf "0123456789")
return (read n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment