check if a tree is complete standard ml

Posted by aizen92 on Stack Overflow See other posts from Stack Overflow or by aizen92
Published on 2012-03-29T14:57:58Z Indexed on 2012/03/29 17:29 UTC
Read the original article Hit count: 188

Filed under:
|
|
|

I want to make a function in standard ml that checks if a tree is complete or not, the function somehow works, but its giving me the wrong type and a warning of non-exhaustive cases

The tree code:

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;

Now the above function's type is: ''a tree -> bool but the required type is 'a tree -> bool

The warning I'm having is:

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) => ...

What is the problem I'm having?

© Stack Overflow or respective owner

Related posts about function

Related posts about types