我想打一個,如果條件是這樣的:SML - 如果病情有一些「或」
if
((head(c) = 1) or (head(c) = ~1) or (head(c) = ~5) or (head(c) = ~17) or (head(c) = 0))
count +1
else..
函數頭回「一個;
它給了我一個錯誤:operator is not a function [tycon dismatch]
操作:布爾 表達
問題是什麼?謝謝。
我想打一個,如果條件是這樣的:SML - 如果病情有一些「或」
if
((head(c) = 1) or (head(c) = ~1) or (head(c) = ~5) or (head(c) = ~17) or (head(c) = 0))
count +1
else..
函數頭回「一個;
它給了我一個錯誤:operator is not a function [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
,不只是or
和andalso
而不是and
。但是orelse
和andalso
不是功能。引用自標準編程ML '97:
Note in particular that andalso and orelse are not infix functions because they are not strict in their second argument—that is, they do not always force the evaluation of their second argument—and such functions cannot be defined in a strict programming language such as Standard ML. Thus we cannot apply the op keyword to andalso or orelse.