奇怪的`int_of_string`调用?
问题描述:
以下代码片段来自ocsigen源代码。我DONOT理解“int_of_string”调用两个参数:奇怪的`int_of_string`调用?
try
let dppos = String.index ss':'
and len = String.length ss in
let host = String.sub ss 0 dppos
and port =
match String.sub ss (dppos+1) ((len - dppos) - 1) with
"*" -> None
| p -> Some (int_of_string "host" p)
in host, port
with
| Not_found -> ss, None
| Failure _ ->
raise (Config_file_error "bad port number")
我测试它在顶层,它通常报告错误。
真诚!
答
注意在该文件的顶部:
let blah_of_string f tag s =
try
f (String.remove_spaces s 0 ((String.length s) -1))
with Failure _ -> raise (Ocsigen_config.Config_file_error
("While parsing <"^tag^"> - "^s^
" is not a valid value."))
let int_of_string = blah_of_string int_of_string
let float_of_string = blah_of_string float_of_string
即它不是Pervasives.int_of_string
了!