2

我一直在尝试针对用户键入无效目录的情况进行模式化:

# let dir = Unix.opendir "adfalf";;
Exception: Unix.Unix_error (Unix.ENOENT, "opendir", "adfalf"). 

我的功能如下:

let files_of_dir d = 
    try 
      let dir = Unix.opendir d in
      ...
    with
       Unix_error (uerr, ucommand, dir) -> raise Not_found

除了我不断收到编译错误:

Error: This variant pattern is expected to have type exn
       The constructor Unix_error does not belong to type exn

我不明白我在模式匹配方面做错了什么。如果有人可以帮助我,将不胜感激!


其他一些注意事项:

我一直在终端上使用以下命令编译我的代码:

ocamlbuild filename.byte
4

1 回答 1

1

你需要说Unix.Unix_error,不只是Unix_error。请注意,这是您的示例会话中出现的内容。

于 2016-10-01T22:12:00.507 回答