ツリーが完全であるかどうかをチェックする関数を標準mlで作成したいのですが、関数はどういうわけか機能しますが、間違ったタイプと非網羅的なケースの警告が表示されます
ツリーコード:
datatype 'data tree =
EMPTY
| NODE of 'data tree * 'data * 'data tree;
fun isComplete EMPTY = true
| isComplete (NODE(x, y, z)) = if (x = EMPTY andalso z <> EMPTY) orelse (x <> EMPTY andalso z = EMPTY) then false else true;
上記の関数のタイプは次のとおりです''a tree -> bool
が、必要なタイプは次のとおりです。'a tree -> bool
私が持っている警告は次のとおりです。
stdIn:169.8 Warning: calling polyEqual
stdIn:169.26 Warning: calling polyEqual
stdIn:169.45-169.47 Warning: calling polyEqual
stdIn:169.64-169.66 Warning: calling polyEqual
stdIn:124.1-169.94 Warning: match nonexhaustive
NODE (x,y,z) => ...
私が抱えている問題は何ですか?
編集:
Michaelのおかげで、コードを修正し、機能するようになりました。
- fun isComplete EMPTY = true
| isComplete (NODE(EMPTY, _, EMPTY)) = true
| isComplete (NODE(NODE(x, y, z), _, NODE(a, b, c))) = true
| isComplete (EMPTY, _, NODE(x, y, z)) = false
| isComplete (NODE(x, y, z), _, EMPTY) = false;