In addition to fixing 'Float', you should define the 'Fractional' instance for MathExpression. This would let you use: let pi = 3.14 :: MathExpression
So your instance of Fractional would look like: instance Num MathExpression where (+) a b = Add a b (*) a b = Multiply a b (-) a b = Subtract a b negate b = Subtract 0 b fromInteger = MathFloat . fromInteger abs = undefined signum = undefined instance Fractional MathExpression where fromRational = MathFloat . fromRational (/) a b = Divide a b recip b = Divide 1 b That would give 'fromRational' and 'fromInteger' which are the main numeric conversion functions. Regards, Dave On Fri, Aug 19, 2011 at 1:40 PM, Paul Reiners <paul.rein...@gmail.com>wrote: > I've created a simple type declaration: > > data MathExpression = Float > | Add MathExpression MathExpression > | Subtract MathExpression MathExpression > | Multiply MathExpression MathExpression > | Divide MathExpression MathExpression > deriving (Show) > > Now how do I create an instance of MathExpression which is just a Float? >
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe