为什么会出现这些错误,我该如何解决? [英] Why am I getting these errors, and how can I solve them?
本文介绍了为什么会出现这些错误,我该如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在用Standard ML编写解释器,但是该函数的语法有问题,我无法弄清楚出了什么问题.
I'm writing an interpreter in Standard ML but I'm having trouble with my the syntax in this function, and I cannot figure out what's wrong.
以下是相关代码:
| eval (rho, SetExp (name, value)) =
(case rhoContains rho name of
true => rhoSet rho name value (rho, value)
| false => globalSet (name, value))
fun rhoSet [] key value = [(key, value)]
| rhoSet ((elt as (k, v)) :: tail) key value =
if key = k then (key, value) :: tail else elt :: rhoSet tail key value
fun rhoContains rho name =
case rhoGet rho name of SOME _ => true | NONE => false
这是SetExp的来源:
This is where SetExp comes from:
datatype expression =
SetExp of (string * expression)
运行此命令会给我列出很多错误,但是我认为这是相关的部分.第62行是eval
中以true
开头的行:
Running this gives me a long list of errors but I think this is the relevant section. Line 62 is the line that starts with true
in eval
:
eval.sml:62: error: Type error in function application.
Function: rhoSet rho name value : (string * expression) list
Argument: (rho, value) : (string * expression) list * expression
Reason: Value being applied does not have a function type
推荐答案
您要将太多参数传递给rhoSet
-删除尾随对.
You're passing too many arguments to rhoSet
- remove the trailing pair.
| eval (rho, SetExp (name, value)) =
(case rhoContains rho name of
true => rhoSet rho name value
| false => globalSet (name, value))
您还可以通过条件使此内容更具可读性:
You can also make this more readable with a conditional:
| eval (rho, SetExp (name, value)) =
if rhoContains rho name
then rhoSet rho name value
else globalSet (name, value)
这篇关于为什么会出现这些错误,我该如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文