In Haskell, declaration order in let/where constructs does not matter, for example:
f x = let g1 x y = if x>y then show x else g2 y x
g2 p q = g1 q p
in ...
where g2 used in g1 before its declaration.
But this is not a case in Ocaml:
# let a = b in
let b = 5 in
a;;
Warning 26: unused variable b.
Error: Unbound value b
Is there a reason why OCaml doesn’t behave like Haskell? In the absence of forward declaration, this feature seems useful to me.
Is it because of strict evaluation in OCaml but lazy in Haskell?
Not the strictness as such, but that’s a symptom of the same problem.
Ocaml is not purely functional, which is to say that arbitrary function calls can do arbitrary I/O. This requires them to run in a predictable order, which requires both strictness and the let-ordering you’ve noticed.