【发布时间】:2016-01-07 11:31:26
【问题描述】:
我现在正在学习 OCaml,在我这样做之后,
type aexp =
| Const of int
| Var of string
| Power of string * int
| Times of aexp list
| Sum of aexp list
let rec diff : aexp * string -> aexp
=fun (aexp,x) -> match aexp with
|Const a -> Const 0
|Var "x" -> Const 1
|Power ("x", a) -> (match a with
|2 -> Times[Const 2; Var "x"]
|1 -> Const 1
|0 -> Const 0
|_ -> Times[Const a; Power ("x", a-1)])
|Times [l] -> (match l with
|h::t -> (match t with
|Var "x" -> h
|Power ("x",a) -> Times [Times [h;Const a];diff(Power ("x",a),x)]))
我收到一个错误:
文件“”,第 11 行,字符 3-5:
错误:变体类型 aexp 没有构造函数 ::
我了解到 :: 是将单个元素连接到列表或列表的另一个元素。
它适用于我使用列表的其他代码。
为什么它在这里不起作用?
【问题讨论】:
标签: constructor ocaml ml