ocaml中的奇怪语法错误

时间:2013-06-11 12:34:49

标签: string parsing pattern-matching ocaml

嘿,我刚刚开始使用Ocaml,我得到了这个奇怪的语法错误,我无法理解! 这是我的计划:

let out x = Printf.printf " %s \n" x 
let _ = try
  while true do
    let line = input_line stdin in 
     begin
    match (Str.split (Str.regexp " ") line) with
            ["commit";code] -> out code;
            | ["diff"; _; before; after] -> out before;
        out after;
          let rec f (xpath: string list) : ( string list ) =
           (match  Str.split (Str.regexp "/") xpath  with 
                     | _ ::rest -> out (String.concat "/" rest)
                     | _ -> []
           )
            | _ -> ()
     end
   done
with
  End_of_file -> ()

1 个答案:

答案 0 :(得分:0)

你想用

做什么
let rec f (xpath: string list) : ( string list ) =
       (match  Str.split (Str.regexp "/") xpath  with 
                 | _ ::rest -> out (String.concat "/" rest)
                 | _ -> []
       )

这段代码与其余代码无关。

删除它,你的代码在语法上是正确的。