value'', ``let'' being reserved to the
construction ``let..in'':
| OCaml | Revised |
|---|---|
| let x = 23;; | value x = 23; |
| let x = 23 in x + 7;; | let x = 23 in x + 7; |
value'', too, instead of
``val''.
| OCaml | Revised |
|---|---|
| val x : int;; | value x : int; |
do'' followed by ``{'' and terminated by ``}''
(it is possible to put a semicolon after the last expression):
| OCaml | Revised |
|---|---|
| e1; e2; e3; e4 | do { e1; e2; e3; e4 } |
for'' and ``while'' has the same
syntax:
| OCaml | Revised |
|---|---|
| while e1 do | while e1 do { |
| e2; e3; e4 | e2; e3; e4 |
| done | } |
| OCaml | Revised |
|---|---|
| 1, "hello", World | (1, "hello", World) |
['' and ``]''.
Their syntax is:
| list | ::= | [ elem-list opt-cons ] |
| elem-list | ::= | expression ; elem-list |
expression |
| opt-cons | ::= | :: expression | (*empty*) |
::'' and an expression, the whole being enclosed
by brackets.
Examples:
| OCaml | Revised |
|---|---|
| x::y | [x::y] |
| [x; y; z] | [x; y; z] |
| x::y::z::t | [x::[y::[z::t]]] |
| x::y::z::t | [x; y; z :: t] |
_''.
()''.
()'', are not said ``irrefutable''.function'' no longer exists. One must use
only ``fun''.fun'',
``match'' and ``try'' are closed with brackets: an open
bracket ``['' before the first case, and a close bracket
``]'' after the last one:
| OCaml | Revised |
|---|---|
| match e with | match e with |
| p1 -> e1 | [ p1 -> e1 |
| | p2 -> e2;; | | p2 -> e2 ]; |
| fun x -> x;; | fun [x -> x]; |
| OCaml | Revised |
|---|---|
| fun x -> x | fun x -> x |
| fun {foo=(y, _)} -> y | fun {foo=(y, _)} -> y |
fun'', but
only with irrefutable patterns:
| OCaml | Revised |
|---|---|
| fun x (y, z) -> t | fun x (y, z) -> t |
| fun x y (C z) -> t | fun x y -> fun [C z -> t] |
Match_failure'' whichever parameter is
applied, the empty ``match'', raising ``Match_failure'' after
having evaluated its expression, and the empty ``try'', equivalent to
its expression without try:
fun []
match e with []
try e with []
let'' and ``value'' must be
irrefutable. The following OCaml expression:
let f (x::y) = ...
must be written in Revised:
let f = fun [ [x::y] -> ...
where'' is back, but one can write only
one bind:
e where x = y
but not:
e where x = y and z = t
<-'' is written ``:='':
| OCaml | Revised |
|---|---|
| x.f <- y | x.f := y |
ref'' type is declared as a record type with one
field named ``val'', instead of ``contents''. The
operator ``!'' does not exist any more, and references are
assigned like the other mutables:
| OCaml | Revised |
|---|---|
| x := !x + y | x.val := x.val + y |
| OCaml | Revised |
|---|---|
| int list | list int |
| ('a, bool) Hashtbl.t | Hashtbl.t 'a bool |
| type 'a foo = | type foo 'a = |
| 'a list list;; | list (list 'a); |
| OCaml | Revised |
|---|---|
| type 'a foo;; | type foo 'a = 'b; |
| type bar;; | type bar = 'a; |
| OCaml | Revised |
|---|---|
| int * bool | (int * bool) |
| OCaml | Revised |
|---|---|
| type t = A of i | B;; | type t = [ A of i | B ]; |
type foo = [];
and''. In expressions and
patterns, this constructor parameters must be curryfied:
| OCaml | Revised |
|---|---|
| type t = C of t1 * t2;; | type t = [ C of t1 and t2 ]; |
| C (x, y);; | C x y; |
| OCaml | Revised |
|---|---|
| type t = D of (t1 * t2);; | type t = [ D of (t1 * t2) ]; |
| D (x, y);; | D (x, y); |
True'' and ``False''
start with an uppercase letter.mutable'' must appear
after the colon:
| OCaml | Revised |
|---|---|
| type t = {mutable x : t1};; | type t = {x : mutable t1}; |
| OCaml | Revised |
|---|---|
| type t = Set.Make(M).t;; | type t = (Set.Make M).t; |
camlp4o pr_r.cmo file.ml
else'' is mandatory in the ``if'' instruction:
| OCaml | Revised |
|---|---|
| if a then b | if a then b else () |
||'' and ``&&'':
| OCaml | Revised |
|---|---|
| a or b & c | a || b && c |
| a || b && c | a || b && c |
begin end'' construction. One must use
parentheses.| OCaml | Revised |
|---|---|
| (+) | \+ |
| (mod) | \mod |
declare'' and ``end''. Example in an interface:
declare
type foo = [ Foo of int | Bar ];
value f : foo -> int;
end;
This can be useful when extending the language structure or signature
items with a construction generating several items.[:'' and ``:]'' instead of ``[<'' and
``>]''.| OCaml | Revised |
|---|---|
| [< '1; '2; s; '3 >] | [: `1; `2; s; `3 :] |
['' and
``]'', like for ``fun'', ``match'' and
``try''. If there is one case, the brackets are not mandatory:
| OCaml | Revised |
|---|---|
| parser | parser |
| [< 'Foo >] -> e | [ [: `Foo :] -> e |
| | [< p = f >] -> f | | [: p = f :] -> f ] |
| parser [< 'x >] -> x | parser [ [: `x :] -> x ] |
| parser [< 'x >] -> x | parser [: `x :] -> x |
Stream.Failure''
whichever parameter is applied, and the empty stream matching always
raising ``Stream.Failure'':
parser []
match e with parser []