This is not a valid data declaration. You can't have a "Float" field without any constructor name and have it still of type "MathExpression". I suggest you do something like: data MathExpr = MathFloat Float .... So you may declare pi: let mathPi = MathFloat pi -- note "pi" is defined in the prelude alread Cheers, Thomas On Fri, Aug 19, 2011 at 1:40 PM, Paul Reiners <paul.reiners@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?
This doesn't work:
*Main> let pi = 3.14 :: MathExpression
<interactive>:1:10: No instance for (Fractional MathExpression) arising from the literal `3.14' Possible fix: add an instance declaration for (Fractional MathExpression) In the expression: 3.14 :: MathExpression In an equation for `pi': pi = 3.14 :: MathExpression
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe