我编写了一个按预期工作的函数,但我不明白为什么输出是这样的。
功能:
datatype prop = Atom of string | Not of prop | And of prop*prop | Or of prop*prop;
(* XOR = (A And Not B) OR (Not A Or B) *)
local
fun do_xor (alpha,beta) = Or( And( alpha, Not(beta) ), Or(Not(alpha), beta))
in
fun xor (alpha,beta) = do_xor(alpha,beta);
end;
Test:
val result = xor(Atom "a",Atom "b");
Output:
val result = Or (And (Atom #,Not #),Or (Not #,Atom #)) : prop
这只是一个输出限制(是的,这很令人困惑)——默认情况下,顶层(交互式 shell)中值打印输出的深度被限制为相当小的数字(即 5)。跳过的部分打印有#。
您可以使用 printDepth 变量覆盖此深度 - 至少在 SML-NJ 中:
Control.Print.printDepth := 1024;
附:顺便说一下,这里不需要单独的 do_xor 和本地函数 - 只需
fun xor(alpha, beta) = Or(...);
will do.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)