gpt4 book ai didi

ocaml - 使用命名参数时为 "Error: The function applied to this argument has type ..."

转载 作者:行者123 更新时间:2023-12-03 01:02:33 26 4
gpt4 key购买 nike

我目前正在研究“Real Word OCaml”,带有命名/标记参数的基本示例之一似乎不起作用(使用 utop 4.01.0):

let languages = ["OCaml"; "Perl"; "C"];;
List.map ~f:String.length languages;;

产品:

Error: The function applied to this argument has type 'a list -> 'b list
This argument cannot be applied with label ~f

鉴于:

List.map String.length languages;;

产生预期的输出[5; 4; 1].

caml.inria.fr提到:

In the core language, as in most languages, arguments are anonymous.

这是否意味着我必须包含某种外部库才能使该代码正常工作?

编辑这是我的 ~/.ocamlinit 文件(根据 installation instructions for the book ):

(* Added by OPAM. *)
let () =
try Topdirs.dir_directory (Sys.getenv "OCAML_TOPLEVEL_PATH")
with Not_found -> ()
;;

#use "topfind"
#camlp4o
#thread
#require "core.top"
#require "core.syntax"

最佳答案

正如 @rafix 的评论中提到的,这可以通过放置来修复

open Core.Std ;;

首先。

关于ocaml - 使用命名参数时为 "Error: The function applied to this argument has type ...",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21498575/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com