ocaml/ocaml — pull request #88 by yallop (2014-08-04 16:06:06+00:00)
Title: Add punning for object copying expressions.

This little patch extends the "punning" pattern in the OCaml syntax to object override expressions. The punning pattern conflates label names and variable names in various contexts; for example, you can define functions with labeled arguments either by binding variables for each argument or by punning, borrowing the label name as a variable:

```ocaml
let f ~a:x ~b:y = x + y
let f ~a ~b = a + b
```

Similarly, you can pass labeled arguments either explicitly or by punning:

```ocaml
let x = 3 and y = 4 in f ~a:x ~b:y
let a = 3 and b = 4 in f ~a ~b
```

The same thing applies to record labels, both in patterns and expressions:

```ocaml
let conj { re = r ; im = i } = { re = r; im = -.i }
let conj { re; im } = { re; im = -.im }
```
This patch extends the pattern to object override expressions, which make copies of objects, changing the values of some fields. With the patch applied you can either use the existing syntax or the more concise version with punning:

```ocaml
object val a = 3 val b = 4 method m x y = {< a = x; b = y >} end
object val a = 3 val b = 4 method m x y = {< a; b >} end
```