ocaml/ocaml — pull request #116 by diml (2014-11-11 17:38:07+00:00)
Title: Type nonrec

This patch set adds a `nonrec` keyword to the language to denote non-recursivity of a binding construct. `nonrec` is allowed where `rec` is. For instance:

```ocaml
let nonrec x = 42
```

It also adds support for `rec` and `nonrec` flags on type definitions. The motivation for non-recursive type definitions is to allow these programming patterns without using an intermediate type:

```ocaml
type t = { ... }
let compare = ...

module Map = Map.Make(struct
type nonrec t = t
let compare = compare
end)
```

or in interfaces:

```ocaml
type t

module Stable : sig
module V1 : sig
type nonrec t = t
end
end
```

The default between `rec`/`nonrec` depends on the construction and is chosen using conservative rules:

- let-bindings are non-recursive by default
- type definitions are recursive by default

A search on github reveals no use of `nonrec` as an identifier in OCaml code. I think adding `nonrec` as a keyword is safe for the vast majority of existing code.