datatype 'a tree = empty | node of 'a * 'a tree * 'a tree ; fun lookup x empty = false | lookup x ( node(v,l,r) ) = ( x = v ) orelse ( x < v andalso (lookup x l) ) orelse ( lookup x r ) ; val mytree1 = node(2,node(1,empty,empty),node(3,empty,empty)) ; val mytree2 = node(8,node(7,empty,empty),node(9,empty,empty)) ; lookup 3 (node(5,mytree1,mytree2)) ; lookup 6 (node(5,mytree1,mytree2)) ; lookup 5 ( node(3,node(2,node(1,empty,empty), empty), node(4,empty, node(5,empty,empty))) ); lookup 8 ( node(3,node(2,node(1,empty,empty), empty), node(4,empty, node(5,empty,empty))) ); fun insert x empty = node( x , empty , empty ) | insert x ( node(v,l,r) ) = if x <= v then node( v , insert x l , r ) else node( v , l , insert x r ) ; val listinsert = foldl ( fn(x,t) => insert x t ) empty ; fun inorder t = let fun accinorder acc empty = acc | accinorder acc ( node(n,l,r) ) = accinorder (n :: accinorder acc r) l in accinorder [] t end ; val sort = inorder o listinsert ; sort [9,3,8,6,9,3,4,2,5,7,0,1,4,2,5,7,8,6,0,1] ;