为什么此OCaml代码不受价值限制

时间:2016-04-29 20:47:38

标签: ocaml value-restriction

我不明白该函数( my_path_mapper )不受价值限制。

# let rec my_map ~f l =
  match l with
    [] -> []
  | h::t -> f h::my_map f t;;
      val my_map : f:('a -> 'b) -> 'a list -> 'b list = <fun>
# let my_path_mapper =
  my_map ["/usr/sbin"; "/usr/bin"; "/sbin"; "/bin"; "/usr/games"; "/usr/local/games"];;
  val my_path_mapper : f:(string -> 'a) -> 'a list = <fun>

请教我为什么?

1 个答案:

答案 0 :(得分:1)

OCaml有“放宽价值限制”。你可以在这里阅读:

Jacques Garrigue, Relaxing the Value Restriction

以前是关于StackOverflow的讨论:

When does the relaxed value restriction kick in in OCaml?