0
votes

I have a function delete_data which gives me an error "Unbound value delete_data" where it's "tree_map delete_data l". My delete function creates a new tree where the b is excluded in each node. As a homework rule, we aren't allowed to change the function to rec. What's the problem?

type 'a tree = Empty | Node of 'a * 'a tree * 'a tree

let rec tree_map f t = match t with
  | Empty -> Empty
  | Node(n, l, r) -> Node(f n , (tree_map f l), (tree_map f r));;

let delete_data t = match t with 
  Empty -> Empty
  | Node((a,b), l, r) -> Node(a, tree_map delete_data l, tree_map delete_data r);;
1

1 Answers

1
votes

You need to declare your function as recursive if you want to refer to it from within itself. Change let delete_data t = to let rec delete_data t =.