[Teaching] anonymous records

Robert Muller robert.muller2 at gmail.com
Sat Jan 2 21:23:53 GMT 2016

Greetings John. Fair enough. What I usually use is something along the
lines of:

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

I would prefer to use a record for the Node case but in my experience
having to cobble together mutually recursive types as in:

*type* 'a node = {info: 'a; left: 'a tree; right: 'a tree}
> *and* 'a tree = Empty | Node of 'a node

is basically a show stopper for many --- it needlessly obscures the natural
recursive structure of the tree.


On Sat, Jan 2, 2016 at 4:11 PM, John Whitington <jgw25 at cam.ac.uk> wrote:

> 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?
> John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ocaml.org/pipermail/teaching/attachments/20160102/481e3504/attachment.html>

More information about the Teaching mailing list