我的代码:
Term :
...
| VAR { try Hashtbl.find var_table $1
with Not_found ->
printf "no such variable '%s'\n" $1; 0.0 } /*(Line:75)*/
...
当我运行它时,
ocamlc -c parser.ml
我看到:
Error: This expression has type float but an expression was expected of type
Syntax.term
大家可以帮我证明这个问题吗?我知道第 75 行的类型与 Syntax.ml 和 Syntax.mll 中定义的类型 Syntax.term 不匹配,但我想将类型 0.0 指定给 Syntax.term 来证明这一点。我可以做吗??
- - - - - - - - - - 编辑 - - - - - - - - - :
术语类型:
type term =
TmTrue
| TmFalse
| TmIf of term * term * term
| TmAnd of term * term
| TmOr of term * term
| TmXor of term * term
| TmSum of term * term
| TmSub of term * term
| TmMult of term * term
| TmPow of term * term
| TmZero
| TmSucc of term
| TmPred of term
| TmIsZero of term
| TmNot of term
每件事都正常工作,我想在我的代码中添加分配,我使用上面的代码将 VAR 添加到 Term。我为它创建了哈希表和其他东西,但这部分让我感到困惑......
- - - - - - - - - - - /编辑 - - - - - - - - - - - -
tnx ;)