Question abt Num

Hamilton Richards hrichrds at swbell.net
Wed Oct 22 23:08:53 EDT 2003


At 9:20 PM -0500 10/22/03, Pratik Bhadra wrote:
>Hi
>
>I have a data type Expr for handling Expressions
>
>data Expr = Lit1 Int | Lit2 Bool | Var String | BinOp Op Expr Expr
>
>As you can see, I am trying to have an Expression have both Int and Bool
>values so that I can work with both arithmetic (+,-,*,/) and
>logical(and,or,<,<=,>,>=) operators.

That makes sense.

>What I am aiming at is to parse a line which contains an expression,
>evaluate it and return the result. I am facing some problems in this
>regard. When I write the evaluate function, the Haskell compiler refuses
>to compile my code as it says, instance of Num Expr required. Any ideas
>what I am supposed to do to fix that?

I think that's the same question I answered in my previous email. Right?

It's saying that Expr needs to be an instance of Num, because (+), or 
some other numeric operation, is being applied to an Expr.

--HR
-- 
------------------------------------------------------------------
Hamilton Richards, PhD           Department of Computer Sciences
Senior Lecturer                  The University of Texas at Austin
512-471-9525                     1 University Station C0500
Taylor Hall 5.138                Austin, Texas 78712-1188
ham at cs.utexas.edu                hrichrds at swbell.net
------------------------------------------------------------------


More information about the Haskell mailing list