SML-如果';s条件与一些;或;

SML-如果';s条件与一些;或;,sml,Sml,我想做一个这样的if条件: if ((head(c) = 1) or (head(c) = ~1) or (head(c) = ~5) or (head(c) = ~17) or (head(c) = 0)) count +1 else.. 函数头返回“a” 它给了我下一个错误:运算符不是函数[tycon dismatch] 接线员:布尔 表达 有什么问题?谢谢。我想它在SML中被称为orelse。对于这个例子,你也可以写: let val h = head c in if List.ex

我想做一个这样的if条件:

if

 ((head(c) = 1) or (head(c) = ~1) or (head(c) = ~5) or (head(c) = ~17) or (head(c) = 0))
count +1
else..
函数头返回“a”

它给了我下一个错误:
运算符不是函数[tycon dismatch]
接线员:布尔 表达


有什么问题?谢谢。

我想它在SML中被称为
orelse

对于这个例子,你也可以写:

let val h = head c in
if List.exists (fn x => x = h) [1, ~1, ~5, ~17, 0]
then count + 1
else ...
end

它被称为
orelse
,而不仅仅是
以及
而不是
。但是
orelse
andalso
不是函数。引用标准ML'97中的编程:

请特别注意,andalso和orelse不是中缀函数,因为它们的第二个参数不严格,即,它们并不总是强制计算它们的第二个参数,并且这些函数不能用严格的编程语言(如标准ML)定义。因此,我们不能将op关键字应用于andalso或orelse