When and why OCaml removed the `where` keyword for local definitions?

Hello,

I am reading an OCaml book from 1995.

There is a where construct that allows writing local definitions after their usage point. It has the same semantics in haskell. Actually, while reading code from other people that I know nothing of, I happen to read it backward because I can’t guess what the many ancilliary helper functions do without a hint from the shape of the computation. All the let aux ... in become readable only after the principal function reads what it is doing. I find the where construct very natural in this regard.

Why did you remove it ?

I know this is history now, yet I ask for cultural reasons in addition to the rational of this choice.

example found :

let newton(f,start,dx,epsilon) =
  loop is_ok do_better start
  where is_ok x = abs_float (f x) <. epsilon
  and do_better x =
    let f' = deriv (f,dx) in
    (x -. f x /. f' x)
;;

AFAIR there were no where in OCaml or Caml-light. It’s hard to be sure because I don’t know what you are reading. But my wild guess would be that book describes camlp5 revised syntax where this keyword is present.

1 Like

The book title is “Approche fonctionnelle de la programmation” using CAML Light.

This was a course taught at ENS from 1990 to 1995 by Guy Cousineau with additional chapters from Michel Mauny.

Anecdote : I found it at a physical library in a university (and that’s how I came to discover OCaml).

book’s repository says Caml-Light 0.75

Translated in english:
ISBN here or here

This is one of my preferred CS books, and indeed there was a where keyword in Caml Light (I miss it!).

1 Like

This keyword existed in Caml Light (and maybe Caml Special Light), but was dropped in OCaml, I guess to reduce the syntactic surface as much as possible. Maybe @xavierleroy will be able to provide some more context…

Cheers,
Nicolas

1 Like

I also liked where. Perhaps the thing I miss most from caml-light is the | fun multiple-matching expression form, where multiple arguments could be matched on with multiple lists of patterns. I guess it was hard to compile well, but did allow some clear and concise code.

1 Like

I also asked before in the ocaml channel what was the historical reason of removing it from toplevel, it’s certainly a much less impactful change, but a curios one nonetheless (considering other mls from before ocaml’s time had it)

> 1 + 1;
val it : int = 2
> it * 3;
val it : int = 6
1 Like

Standard ML has this. It would be nice to re-introduce it as ocaml -it.

1 Like