在OCaml中让rec的限制 [英] Limitations of let rec in OCaml

查看:110
本文介绍了在OCaml中让rec的限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在学习OCaml,并遇到了这个问题:

OCaml限制了它可以放在let rec的右侧。像这样的



 让memo_rec f_norec = 
让REC F = memoize的(乐趣X - > f_norec FX)中
F ;;
错误:这种表达式不允许作为'let rec'的右手边



<其中,memoize是一个函数,它使用一个函数并将其转换为带有Hashtable的记忆版本。这是显而易见的是,OCaml有关于在让REC右手边利用结构的一些限制,但我真的不明白,任何人都可以解释更多关于这一点?


解决方案

这允许通过来束缚那种表达式让REC 第7.3节。具体而言,不允许涉及 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):

Informally, the class of accepted definitions consists of those definitions where the defined names occur only inside function bodies or as argument to a data constructor.

这篇关于在OCaml中让rec的限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆