Hi I got a code like this:
data Digit = Zero | One | Two | Three | Four | Five | Six | Seven | Eight |
Nine
deriving (Eq, Show)
data Number = Single Digit | Many Digit Number deriving (Eq, Show)
data Expr = Lit Number
| Sub Expr
| Sum Expr Expr
| Mul Expr Expr
deriving (Eq, Show)
So the idea with this code is to have a string, like * + 2 3 * 2 + 6 - 2, which will be represented as ((2 + 3) * (2 * (6 - 2))), and then use this to put parts of the string in there types. And of course at the end find the result, in this case 40. The problem is that I don't know much about parsing, so I really don't know how I could parse an expression like this. I have seen some simple parsing where strings are been parsed into types, like person or something. But I think this is a bit more complex. If anyone have any suggestions, I would be really interested.
* + 2 3 * 2 - 6 2? This looks like prefix Polish notation.-is supposed to be unary negate, not binary subtract.Sum Expr Exprlooks right to me. The constructor at issue wasSub, notSum.