Re: [Haskell-cafe] Question about data

2011-08-22 Thread David Barbour
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 = Sub

Re: [Haskell-cafe] Question about data

2011-08-19 Thread MigMit
Your MathExpression data type has nothing to do with numbers of any kind. Your "Float" data constructor doesn't mean that float numbers are a part of your type; instead it means that you have a SINGLE value of type MathExpression, and this value is named "Float". You should modify your data dec

Re: [Haskell-cafe] Question about data

2011-08-19 Thread Stephen Tetley
Others have pointed out your first bug. To get floating-point numeric literals you will need to define instances of Num and then Fractional for your symbolic type. On 19 August 2011 21:40, Paul Reiners wrote: > *Main> let pi = 3.14 :: MathExpression > __

Re: [Haskell-cafe] Question about data

2011-08-19 Thread Jason Dagit
On Fri, Aug 19, 2011 at 1:45 PM, Thomas DuBuisson wrote: > This is not a valid data declaration.  You can't have a "Float" field > without any constructor name and have it still of type And the reason why it accepts 'data MathExpr = Float', is because data constructors and types live in separate

Re: [Haskell-cafe] Question about data

2011-08-19 Thread Thomas DuBuisson
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