A ternary tree type is defined as:
datatype ’a tree =
Leaf of ’a
| Node of ’a tree * ’a tree * ’a tree
I need to modify functions map & foldl to match the ternary tree...
fun tree_map (f : ’a -> ’b) (t : ’a tree) : ’b tree =
f,nil) = nil
| map (f,x::xs) = f(x) :: (map (f,xs))
fun tree_foldl (f : ’a * ’a -> ’a) (n: ’a) (t : ’a tree) : ’a =
(f,ie,nil) = ie
| foldl (f,ie,x::xs) = foldl (f, f(x,ie), xs);
I know this is probably a simple modification, but I can't seem to wrap my head around the logic. I don't understand how it would be different for a binary tree...any pointers?