私は標準 ML を初めて使用するので、このタイプの不一致エラーが発生する理由がわかりません。
fun number_in_month (month : int, dates : int list) =
if null dates
then 0
else if (month = (hd (tl (hd dates))))
then number_in_month(month, (tl dates)) + 1
else number_in_month(month, (tl dates))
この関数を評価すると、次のエラーが発生します。
Error: operator and operand don't agree [tycon mismatch]
5 operator domain: 'Z list
6 operand: int
7 in expression:
8 tl (hd dates)
ただし、REPL で、次のようにすると:
val x = [[84, 12, 23], [83, 01, 18]]
12 = (hd (tl (hd x))) (* -> val it = true : bool *)
この場合の型チェック規則が何であるかはわかりません。同じ式が REPL で機能する理由がわかりませんが、関数内の部分式を評価しようとすると機能しません。