I'm having trouble fork execing in the following manner because the child process returns a Core_kernel.Std.never_returns
and the parent is attempting to return ()
.
I get the error This expression has type unit but an expression was expected of type Core_kernel.Std.never_returns = Core_kernel.Nothing0.t
. Can't seem to find the propper way of doing this with 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 *)
The never_returns
type is specially designed to be consumed with never_returns
function. This is to require a programmer to state clearly in the code, that he understands that the expression doesn't terminate. Here is a working example:
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 _ -> ()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With