Created
June 11, 2013 17:53
-
-
Save rrichardson/5759119 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Expressions where | |
import Text.ParserCombinators.Parsec | |
import Control.Monad | |
import Control.Monad.Error | |
import System.IO | |
data Term a = IntVal Integer | |
| StrVal String | |
| RealVal Double | |
data Expr a = BinOp String (Expr a) (Expr a) | |
| UnOp String (Expr a) | |
| Fun String (Expr a) | |
| Ident String | |
| IfElse (Expr a) (Expr a) (Expr a) | |
| Cond (Expr a) [Expr a] | |
| Term a | |
deriving (Show, Eq) | |
evaluate :: (Eq a) => Expr a -> b | |
evaluate (BinOp "+" e1 e2) = (evaluate e1) + (evaluate e2) | |
evaluate (Term (IntVal i)) = i | |
evaluate (Term (StrVal s)) = s | |
evaluate (Term (RealVal r)) = r | |
evaluate _ = undefined | |
------ | |
Expressions.hs:24:30: | |
Couldn't match type `Integer' with `[Char]' | |
Expected type: b | |
Actual type: String | |
In the expression: s | |
In an equation for `evaluate': evaluate (Term (StrVal s)) = s | |
Expressions.hs:25:31: | |
Couldn't match type `Integer' with `Double' | |
Expected type: b | |
Actual type: Double | |
In the expression: r | |
In an equation for `evaluate': evaluate (Term (RealVal r)) = r | |
Failed, modules loaded: none. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment