datatype BoolList = TRUE of BoolList | FALSE of BoolList | NULL fun getTrueCount (NULL) = 0 | getTrueCount (TRUE(x)) = 1 + getTrueCount x | getTrueCount (FALSE(x)) = getTrueCount x; fun xor x = getTrueCount x mod 2; fun remove (flag, NULL) = NULL | remove (flag, TRUE(x)) = if flag then remove(flag, x) else TRUE(remove(flag, x)) | remove (flag, FALSE(x))= if flag then FALSE(remove(flag, x)) else remove(flag, x); fun toString (TRUE(x)) = "TRUE " ^ toString(x) | toString (FALSE(x)) = "FALSE " ^ toString(x) | toString (NULL) = ""; fun processList (t, f, n) NULL = n(NULL) | processList (t, f, n) (TRUE(x)) = t(processList (t, f, n) x) | processList (t, f, n) (FALSE(x))= f(processList (t, f, n) x); val getTrueCount1 = processList(fn x => x + 1, fn x => x , fn x => 0); val xor1 = processList(fn x => (x+1) mod 2, fn x => 0, fn x => 0); fun remove1 (flag) = if flag then processList(fn x => x, fn x => FALSE(x), fn x => x) else processList(fn x => TRUE(x), fn x => x, fn x => x); val toString1 = processList(fn x => "TRUE " ^ x, fn x => "FALSE " ^ x, fn x => "");