[Teaching] anonymous records

John Whitington jgw25 at cam.ac.uk
Sat Jan 2 21:11:31 GMT 2016

Hi Robert,

Robert Muller wrote:
> Greetings. As I understand it, an upcoming release of OCaml is going to
> support anonymous (or were they called "inlined"??) records. This is
> going to be very helpful in an intro classroom where students will be
> able to work with more intuitive definitions of trees. I assume that
> we'll be able to write something like:
> type 'a tree = Leaf of 'a | Node of {info: 'a; left : 'a tree; right :
> 'a tree}
> and we won't have to fiddle around with mutually recursive type
> definitions. We will be distributing a VM to students at the start of
> class (January 19). I would prefer to distribute only one VM during the
> semester and I would prefer that the VM was configured with the compiler
> supporting anonymous records.

Not an answer to your question, but some students find intuition in 
simply reordering to put 'left' on the left and 'right' on the right, 
with the data in the middle:

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

Also a question: your type has data at the leaf as well as at nodes. 
Most people don't do that for a standard tree type, seeing the form I 
give above as more "natural" -- do you find your way has a teaching (or 
other) advantage?


More information about the Teaching mailing list