Some new things in 4.02

Gabriel Scherer

OCaml Paris Meeting, May 22st

Time machine

I made an OUPS talk on May 21, 2013. Some quotes:

We already do have a lot of external contributors on the bugtracker!

Breaking changes are not accepted.

Bugfixes and contributions for OCamlbuild are desirable and welcome.

review proposed patches: read the code to give an opinion, improve on the implementation, or test them against your own software

Today

Some new things in 4.02

Please ask questions,

but I don't have all the answers.

Fresh from the changelog:

Language features:

(Camlp4, Labltk split off the distribution)

Attributes and extension nodes

General idea: a robust syntax to robustly express a subset of Camlp4 extensions. Attach information to AST nodes, or fill new nodes.

Alternative syntax for string literals {id|...|id} (can break comments) (Alain Frisch)

.

(* find good and bad nodes in {w|u<=w} *)

Examples from extensions.ml

In the future: ulex, maybe lwt...

Merlin support?

Generative functors

Allow opening a first-class module or applying a generative functor in the body of a generative functor. Allow it also in the body of an applicative functor if no types are created (Jacques Garrigue, suggestion by Leo White)

Module aliases

(toplevel demo)

Use this to avoid module clashes: mylib_format.ml, mylib_url.ml, and mylib.ml with:

module Format = Mylib_format
module Url = Mylib_url
...

Then your users can open Mylib and use Format, Url etc.

Immutable strings

let reverse str =
  let len = String.length str in
  let res = String.create len in
  for i = 0 to len - 1 do
    res.[i] <- str.[len - 1 - i] (* boo! *)
  done;
  res

let reverse str =
  let len = String.length str in
  let res = String.create len in
  for i = 0 to len - 1 do
    res.[i] <- str.[len - 1 - i] (* boo! *)
  done;
  res
let reverse str =
  let len = String.length str in
  let res = Bytes.create len in
  for i = 0 to len - 1 do
    Bytes.set res i str.[len - 1 - i]
  done;
  Bytes.unsafe_to_string res (* hmm... *)

match with exception

let rec read_all () =
  try input_line () :: read_all ()
  with End_of_input -> []

let rec read_all () =
  try input_line () :: read_all ()
  with End_of_input -> []

let rec read_all acc =
  match input_line () with
  | line -> read_all (line :: acc)
  | exception End_of_input -> List.rev acc

let read_all () = read_all []

Even better than let try! ("Exceptional Syntax", Nick Benton and Andrew Kennedy, 2001)

Extensible sum types

An extension of exceptions (add new constructors).

type 'a foo = ..

type 'a foo +=
    A of 'a list
  | B: int foo

You will probably never need it, but someone in a far galaxy...

("Polymorphic typed defunctionalized", François Pottier and Nadji Gauthier)

Other things

Thanks. Questions?