为什么这段 OCaml 代码不受值限制
Why this OCaml code does not subject to the 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>
请教我为什么?
OCaml 有一个 "relaxed value restriction." 你可以在这里阅读它:
Jacques Garrigue, Relaxing the Value Restriction
这是之前关于 Whosebug 的讨论:
When does the relaxed value restriction kick in in OCaml?
不明白函数(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>
请教我为什么?
OCaml 有一个 "relaxed value restriction." 你可以在这里阅读它:
Jacques Garrigue, Relaxing the Value Restriction
这是之前关于 Whosebug 的讨论:
When does the relaxed value restriction kick in in OCaml?