From robert.muller2 at gmail.com Sat Jan 2 21:01:18 2016 From: robert.muller2 at gmail.com (Robert Muller) Date: Sat, 2 Jan 2016 16:01:18 -0500 Subject: [Teaching] anonymous records Message-ID: 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. Can someone let me know how these chips are going to fall? Thanks! Bob Muller -------------- next part -------------- An HTML attachment was scrubbed... URL: From jgw25 at cam.ac.uk Sat Jan 2 21:11:31 2016 From: jgw25 at cam.ac.uk (John Whitington) Date: Sat, 02 Jan 2016 21:11:31 +0000 Subject: [Teaching] anonymous records In-Reply-To: References: Message-ID: <56883D03.1030803@cam.ac.uk> 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 From robert.muller2 at gmail.com Sat Jan 2 21:23:53 2016 From: robert.muller2 at gmail.com (Robert Muller) Date: Sat, 2 Jan 2016 16:23:53 -0500 Subject: [Teaching] anonymous records In-Reply-To: <56883D03.1030803@cam.ac.uk> References: <56883D03.1030803@cam.ac.uk> Message-ID: 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. Bob On Sat, Jan 2, 2016 at 4:11 PM, John Whitington 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: