SML/ML 中的 RPAREN EQALOP 和未绑定变量和构造函数错误
说我有 2 个 CNF 逻辑短语 a,b,我的 distrib 函数应该返回 a|b (a OR b) 的 CNF 形式。
我得到的替换规则是:
1) Replace p|(q&r) by (p|q)&(p|r)
2) Replace (q&r)|p by (q|p)&(r|p)
以这种方式定义的道具:
datatype prop = Atom of string | Not of prop | And of prop*prop | Or of prop*prop;
函数:
local
fun doOr(prop1,prop2) = (Or(prop1,prop2))
fun distrib1 (Or(Atom(sName1),Atom(sName2) ) ) = Or(Atom(sName1), Atom(sName2) )
|distrib1 (Or(Not(Atom(sName1) ),Atom(sName2) ) ) = Or(Not(Atom(sName1) ), Atom(sName2) )
| distrib1 (Or(Atom(sName1),Not(Atom(sName2) ) ) ) = Or(Atom(sName1), Not(Atom(sName2) ) )
| distrib1 (Or(Not(Atom(sName1)),Not(Atom(sName2) ) ) ) = Or(Not(Atom(sName1)), Not(Atom(sName2) ) )
| distrib1 (Or(prop1,And(prop2,prop3) ) ) = And( distrib1(Or(prop1,prop2) ), distrib1(Or(prop1,prop3) ) )
| distrib1 (Or(And(prop1, prop2), prop3) ) ) = And( distrib1(Or(prop1,prop3) ), distrib1(Or(prop2,prop3) ) )
in
fun distrib (prop1,prop2) = distrib1(doOr(prop1,prop2) );
end;
嗯,我不知道函数本身是否正确,尽管我刚刚浏览了所有基本选项和替换规则,但现在我得到了当 EQALOP 出现在 distrib1 函数之后时出现上述错误,并且构造函数错误出现在 distrib 函数之后。
为什么我会收到这些错误?我不确定,但也许我应该使用 let 而不是 local,但是如何将它转换为 let 结构?
谢谢。
Said I have got 2 CNF logical phrases a,b and my distrib function should return the CNF form of a|b (a OR b).
Replacing rules that I've got are:
1) Replace p|(q&r) by (p|q)&(p|r)
2) Replace (q&r)|p by (q|p)&(r|p)
A prop defined this way:
datatype prop = Atom of string | Not of prop | And of prop*prop | Or of prop*prop;
The function:
local
fun doOr(prop1,prop2) = (Or(prop1,prop2))
fun distrib1 (Or(Atom(sName1),Atom(sName2) ) ) = Or(Atom(sName1), Atom(sName2) )
|distrib1 (Or(Not(Atom(sName1) ),Atom(sName2) ) ) = Or(Not(Atom(sName1) ), Atom(sName2) )
| distrib1 (Or(Atom(sName1),Not(Atom(sName2) ) ) ) = Or(Atom(sName1), Not(Atom(sName2) ) )
| distrib1 (Or(Not(Atom(sName1)),Not(Atom(sName2) ) ) ) = Or(Not(Atom(sName1)), Not(Atom(sName2) ) )
| distrib1 (Or(prop1,And(prop2,prop3) ) ) = And( distrib1(Or(prop1,prop2) ), distrib1(Or(prop1,prop3) ) )
| distrib1 (Or(And(prop1, prop2), prop3) ) ) = And( distrib1(Or(prop1,prop3) ), distrib1(Or(prop2,prop3) ) )
in
fun distrib (prop1,prop2) = distrib1(doOr(prop1,prop2) );
end;
Well, I don't know if the function itself is right although I just went through all the base options and the replacing rules but for now I get the above errors when the EQALOP appear after the distrib1 function and the constructors error appear the distrib function.
Why I get those errors? I am not sure but maybe I am supposed to use let and not local but then how can I transform it to a let structure?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
distrib1
的最后一个例子中,总共有 3 个左括号,但有 4 个右括号:这就是为什么您会收到有关 RPAREN 的语法错误。
您在
distrib
中收到错误,因为distrib1
由于语法错误而尚未定义,因此它是一个未知变量。修复distrib1
中的语法错误也可以解决此问题。In the last case of
distrib1
you have a total of 3 opening parentheses, but 4 closing:Which is why you get the the syntax error about the RPAREN.
You're getting an error in
distrib
becausedistrib1
has not been defined due to the syntax errors and thus it is an unknown variable. Fixing the syntax error indistrib1
will fix this too.