I am doing OCaml 99, and can't quite understand some terms in this problem.
A string representation of binary trees. (medium)
Somebody represents binary trees as strings of the following type (see example): "a(b(d,e),c(,f(g,)))".
- Write an OCaml function which generates this string representation, if the tree is given as usual (as
Empty
orNode(x,l,r)
term). - Then write a function which does this inverse; i.e. given the string representation, construct the tree in the usual form.
- Finally,
combine the two predicates in a single function tree_string
which can be used in both directions. - Write the same predicate tree_string using
difference lists
and a single predicate tree_dlist which does the conversion between a tree and a difference list in both directions.
For simplicity, suppose the information in the nodes is a single letter and there are no spaces in the string.
Here are my questions:
- What does
predicate
mean in this problem? - For the 3rd point, it asks to make a function which can be used in both directions, i.e., can accept a tree and output a string or accept a string and output a tree. Should I use
functor
or something like that? - I totally can't understand the 4th point. What is
difference lists
?