ocaml - 自 RWO 以来,OCaml 编译器是否发生了巨大变化?

标签 ocaml

真实世界 OCaml 第 60 页的示例

List.map ~f:((+) 3) [4;5;6;];;
Error: The function applied to this argument has type 'a list -> 'b list
This argument cannot be applied with label ~f

来自 RWO 的 HTML 托管版本的相同示例

List.map ~f:((+) 3) [4;5;6];;
- : int list = [7; 8; 9]
Error: The function applied to this argument has type 'a list -> 'b list
This argument cannot be applied with label ~f

显然发生了重大变化,对吧?为什么这些例子不起作用?有没有更好的书可以学习?

这门语言很棒,我想尽我所能学习,但资源稀缺。

最佳答案

尝试使用模块 ListLabels 而不是 List

这是关于标准库而不是编译器的问题,自 RWO 发布以来这一点一直没有改变。 RWO使用的是Jane Street Core,其功能类似于标准库中的ListLabels。特别是,ListLabels 和 Jane Street Core Listmap 的函数参数上都有一个标签 f,而标准的 List 没有。

Standard ListLabels

Standard List

Jane Street Core List

在浏览器中的每个页面上搜索 val map 以查看函数签名。

您可以从 RWO 代码顶部的语句 # open Core.Std;; 看出 RWO 使用的是 Jane Street Core。如果你想使用常规的标准模块 List,做

List.map ((+) 3) [4;5;6];;

不确定他们的在线顶级发生了什么。

关于ocaml - 自 RWO 以来,OCaml 编译器是否发生了巨大变化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31845665/

相关文章:

operators - OCaml:为什么我不能使用这个运算符中缀?

module - OCaml 模块 : bringing (interconnected) types from different modules into a new module

javascript - 如何使用 js_of_ocaml 添加 onclick 方法?

functional-programming - Ocaml 连接两个字符串使得 a ^ b = b ^ a

compiler-errors - 此表达式的类型为 a*b*c 但应为 int 类型

syntax-error - 将数组移位k的函数语法错误

error-handling - 使用 int_of_float 从浮点转换时如何处理 OCaml 中的整数溢出?

ocaml - 如何在 ocaml 顶层检查模块/签名?

Ocaml:获取进程的 CPU 使用率

ocaml - 电池和电芯各有什么优缺点?