[Haskell-cafe] What's wrong with my Haskell code?

Meihui Fan mhfan at 163.com
Tue Apr 13 19:44:22 EDT 2004


when loading the following code, hugs escaped and reported that

ERROR "cal24.hs":10 - Instance of Integral (Ratio Integer) required for 
definition of Main.eval

I don't know why and how to solve it, anyone help me?

data ETree = Add ETree ETree
            | Sub ETree ETree
            | Mul ETree ETree
            | Div ETree ETree
            | Node Integer
            deriving Show

eval :: ETree->Maybe Rational
eval (Node x)    = Just (fromInteger x)
eval (Add t1 t2) = do { x<-eval t1; y<-eval t2;
                         if x>=y then return (x+y) else Nothing }
eval (Sub t1 t2) = do { x<-eval t1; y<-eval t2; return (x-y) }
eval (Mul t1 t2) = do { x<-eval t1; y<-eval t2;
                         if x>=y then return (x*y) else Nothing }
eval (Div t1 t2) = do { x<-eval t1; y<-eval t2;
                         if y/=0 then return (x `div` y) else Nothing }



More information about the Haskell-Cafe mailing list