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.
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…
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.
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