为什么会出现这些错误,我该如何解决?

编程入门 行业动态 更新时间:2024-10-09 18:20:40
本文介绍了为什么会出现这些错误,我该如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在用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)

更多推荐

为什么会出现这些错误,我该如何解决?

本文发布于:2023-11-28 00:00:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1640140.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:我该   如何解决   错误

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!