奇怪的`int_of_string`调用?

时间:2012-07-24 05:57:26

标签: ocaml

以下代码片段来自ocsigen source。我不理解用两个参数调用的“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")

我在顶层测试它,它会正常报告错误。

此致!

1 个答案:

答案 0 :(得分:5)

请注意该文件的顶部:

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