Search code examples
treetreemapmlnon-exhaustive-patterns

Match nonexhaustive im ML treemap function


Hello I am new to ML and am writing a treemap function for the following datatype :

     datatype tree = NIL | CONS of (tree * tree) | LEAF of int;

This is my treemap function:

fun treemap f = fn LEAF x => LEAF (f x)
            | CONS(y,z) => CONS (treemap f y, treemap f z);

I know I'm getting the nonexhaustive warning because I am not checking the NIL case, but how do I check for it? When I add another or I get an EQUALOP error. Any help is appreciated, thanks.


Solution

  • for the NIL case, try ad |NIL => NIL;