问题描述
我现在正在学习OCaml,并遇到了这个问题:
OCaml限制了它可以放在let rec的右侧。像这样的
让memo_rec f_norec =
让REC F = memoize的(乐趣X - > f_norec FX)中
F ;;
错误:这种表达式不允许作为'let rec'的右手边
这允许通过来束缚那种表达式让REC
在。具体而言,不允许涉及 let rec
定义名称的函数应用程序。
粗略总结链路):
I'm studying OCaml these days and came across this:
OCaml has limits on what it can put on the righthand side of a let rec. Like this one
let memo_rec f_norec =
let rec f = memoize (fun x -> f_norec f x) in
f;;
Error: This kind of expression is not allowed as right-hand side of `let rec'
in which, the memoize is a function that take a function and turns it into a memorized version with Hashtable. It's apparent that OCaml has some restriction on the use of constructs at the right-hand side of 'let rec', but I don't really get it, could anyone explain a bit more on this?
The kind of expressions that are allowed to be bound by let rec
are described in section 7.3 of the manual. Specifically, function applications involving the let rec
defined names are not allowed.
A rough summary (taken from that very link):
这篇关于在OCaml中让rec的限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!