尝试为 Unix_error (Ocaml) 进行模式匹配时出错?
Getting error when try to pattern match for Unix_error (Ocaml)?
我一直在尝试为用户键入无效目录的情况设置模式:
# 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
你需要说 Unix.Unix_error
,而不仅仅是 Unix_error
。请注意,这是您的示例会话中显示的内容。
我一直在尝试为用户键入无效目录的情况设置模式:
# 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
你需要说 Unix.Unix_error
,而不仅仅是 Unix_error
。请注意,这是您的示例会话中显示的内容。