Reputation: 123
Let's say I want to declare a global variable using local variable : I can do (1)
let y = let x = 1 in x + 1;;
But now if I do (2)
let x = 1 in let y = x + 1;;
It seems ocaml doesn't understand this syntax, it stops at ;;, but I don't see why, because (3)
let x = 1 in 1;;
works, even if it's useless.
What happens at (2) ? How is ocaml trying to analyze this expression ?
Upvotes: 1
Views: 165
Reputation: 370152
The big difference between the two types of let
s is that let ... in ...
is an expression, but let
without in
is not. Now the part after in
in let ... in ...
must be an expression, so the in
less let
is not allowed there - it's only allowed at the top-level of a module.
Upvotes: 3