我想编写一种数据类型来评估像这样的表达式:
a 被评估为 a
a + b * c / d -e 被评估为 a + (b * (c / (d - e)))
因此,第一个参数始终是数字,第二个参数是数字或表达式
我试图定义这样的数据类型
data Exp = Single Int
| Mult (Single Int) Exp
Run Code Online (Sandbox Code Playgroud)
但这给了我这个编译错误:
Not in scope: type constructor or class ‘Single’
A data constructor of that name is in scope; did you mean DataKinds?
|
9 | | Mult (Single Integer ) Exp
|
Run Code Online (Sandbox Code Playgroud)
我可以这样定义:
data Exp = Single Integer
| Mult Exp Exp
Run Code Online (Sandbox Code Playgroud)
但是它没有给出我想要的类型的精确定义。我该如何定义?