Ocaml 3.12 released

This notice comes a little late, but the latest version of OCaml, version 3.12, has been released. Surprisingly, for a point release there's a lot of interesting new language features:

Some of the highlights in release 3.12 are:

  • Polymorphic recursion is supported, using explicit type declarations on the recursively-defined identifiers.
  • First-class modules: module expressions can be embedded as values of the core language, then manipulated like any other first-class value, then projected back to the module level.
  • New operator to modify a signature a posteriori: S with type t := tau denotes signature S where the t type component is removed and substituted by the type tau elsewhere.
  • New notations for record expressions and record patterns: { lbl } as shorthand for { lbl = lbl }, and { ...; _ } marks record patterns where some labels were intentionally omitted.
  • Local open let open ... in ... now supported by popular demand.
  • Type variables can be bound as type parameters to functions; such types are treated like abstract types within the function body, and like type variables (possibly generalized) outside.
  • The module type of construct enables to recover the module type of a given module.
  • Explicit method override using the method! keyword, with associated warnings and errors.

I'm especially intrigued by first-class modules, and the destructive signature operations, both of which should make it much easier to write libraries.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Destructive Signatures

I've pleased to see that the destructive signatures solves an issue which arises when applying an OO design pattern to signatures. Namely, it makes it possible to formulate the signature-analogue of multiple inheritance, while sticking to the convention of bundling a type-component "t" with associated methods:

module type Identifiable = sig
    type t
    val eq : t -> t -> bool

module type A_partial_order = sig
    type t
    val leq : t -> t -> bool

module type A_total_order = sig
    type t
    include Identifiable with type t := t
    include A_partial_order with type t := t
    val cmp : t -> t -> int

That was maybe the main reason for this feature?

Destructive Signatures

Yes, it was as a result of us looking for a better way of encoding just this kind of pattern that the feature got added.