From Real World OCaml (beta):

OCaml distinguishes between non-recursive definitions (using let) and recursive definitions (using let rec) largely for technical reasons: the type-inference algorithm needs to know when a set of function definitions are mutually recursive, and for reasons that don't apply to a pure language like Haskell, these have to be marked explicitly by the programmer.

Why is this the case (what is the technical reason, exactly), and why does a pure language like Haskell “get away” with not having to tag functions as recursive?

  • 6
    @Simon I disagree. This question is about type inference specifically, and neither that question nor its answers address that. – user7043 Jul 11 '13 at 14:06
  • 1
    I support @delnan on this. The question is good, we simply want to know the "reasons that don't apply to a pure language". In the answers to the other questions, historical and scoping issues are mentioned, but those have nothing to do with type inference. – Ingo Jul 11 '13 at 14:40
  • 2
    In an interesting coincidence, there is currently a long discussion on Haskell Cafe about making a non-recursive let. Grass always look greener... – Daniel Gratzer Jul 11 '13 at 15:43
  • @jozefg Yeah, interesting, though i find the example less convincing. You can't say let s = "foo"; x=3; s = "bar" in s (can you?), so I feel Oleg's example should not even compile (as different things are bound to the same name at the same scope). If it does compile, however due to early desugaring of let, the compiler could as well emit a warning. – Ingo Jul 11 '13 at 16:17