我正在浏览Imp教程,发现我什至无法编译提供的代码软件基础:
Coercion AId : string >-> aexp.
Coercion ANum : nat >-> aexp.
Definition bool_to_bexp (b: bool) : bexp :=
if b then BTrue else BFalse.
Coercion bool_to_bexp : bool >-> bexp.
Bind Scope aexp_scope with aexp.
Infix "+" := APlus : aexp_scope.
Infix "-" := AMinus : aexp_scope.
Infix "*" := AMult : aexp_scope.
Bind Scope bexp_scope with bexp.
Infix "<=" := BLe : bexp_scope.
Infix "=" := BEq : bexp_scope.
Infix "&&" := BAnd : bexp_scope.
Notation "'!' b" := (BNot b) (at level 60) : bexp_scope.
(** We can now write [3 + (X * 2)] instead of [APlus 3 (AMult X 2)],
and [true && !(X <= 4)] instead of [BAnd true (BNot (BLe X 4))]. *)
(* ================================================================= *)
(** ** Evaluation *)
(** The arith and boolean evaluators are extended to handle
variables in the obvious way, taking a state as an extra
argument: *)
Fixpoint aeval (st : state) (a : aexp) : nat :=
match a with
| ANum n => n
| AId x => st x (* <----- NEW *)
| APlus a1 a2 => (aeval st a1) + (aeval st a2)
| AMinus a1 a2 => (aeval st a1) - (aeval st a2)
| AMult a1 a2 => (aeval st a1) * (aeval st a2)
end.
我得到的错误:
In environment
aeval : state -> aexp -> nat
st : state
a : aexp
x : string
The term "x" has type "string" while it is expected to have type "id".
In environment
aeval : state -> aexp -> nat
st : state
a : aexp
x : string
The term "x" has type "string" while it is expected to have type "id".
如果输出类型是nat,为什么Coq期望类型id
不应该期望类型nat
?