What's the reason of 'let rec' for impure functional language OCaml?

前端 未结 6 1822
梦谈多话
梦谈多话 2021-02-02 06:54

In the book Real World OCaml, the authors put why OCaml uses let rec for defining recursive functions.

OCaml distinguishes between nonrecurs

6条回答
  •  灰色年华
    2021-02-02 07:40

    I'd say that in OCaml they are trying to make REPL and source files work the same way. So, it's perfectly reasonable to redefine some function in REPL; therefore, they have to allow it in the source as well. Now, if you use the (redefined) function in itself, OCaml needs some way of knowing which of the definitions to use: the previous one or the new one.

    In Haskell they've just gave up and accepted that REPL works differentyle from source files.

提交回复
热议问题