OCaml Core_unix.fork 与 Core_unix.exec 从不 returns
OCaml Core_unix.fork with Core_unix.exec never returns
我无法通过以下方式执行 fork,因为子进程 return 是 Core_kernel.Std.never_returns
而父进程正试图 return ()
.
我收到错误 This expression has type unit but an expression was expected of type Core_kernel.Std.never_returns = Core_kernel.Nothing0.t
。似乎无法找到使用 Core.Std
.
执行此操作的正确方法
open Core.Std
open Unix
let () =
let prog = "ls" in
let args = ["ls"; "-l"] in
match Unix.fork () with
| `In_the_child ->
Unix.exec ~prog:prog ~args:args ();
| `In_the_parent _ ->
(* continue on with the program *)
never_returns
类型专门设计用于与 never_returns
函数一起使用。这是要求程序员在代码中明确声明,他理解表达式不会终止。这是一个工作示例:
let () =
let prog = "ls" in
let args = ["ls"; "-l"] in
match Unix.fork () with
| `In_the_child ->
Unix.exec ~prog ~args () |>
never_returns
| `In_the_parent _ -> ()
我无法通过以下方式执行 fork,因为子进程 return 是 Core_kernel.Std.never_returns
而父进程正试图 return ()
.
我收到错误 This expression has type unit but an expression was expected of type Core_kernel.Std.never_returns = Core_kernel.Nothing0.t
。似乎无法找到使用 Core.Std
.
open Core.Std
open Unix
let () =
let prog = "ls" in
let args = ["ls"; "-l"] in
match Unix.fork () with
| `In_the_child ->
Unix.exec ~prog:prog ~args:args ();
| `In_the_parent _ ->
(* continue on with the program *)
never_returns
类型专门设计用于与 never_returns
函数一起使用。这是要求程序员在代码中明确声明,他理解表达式不会终止。这是一个工作示例:
let () =
let prog = "ls" in
let args = ["ls"; "-l"] in
match Unix.fork () with
| `In_the_child ->
Unix.exec ~prog ~args () |>
never_returns
| `In_the_parent _ -> ()