Would somebody help me to run this code?

let rec tic () =
  let () = print_endline "tic" in
  let* () = Lwt_unix.sleep 1.0 in
  tic ()

let _ = Lwt_main.run tic

I get the following error:

let _ = Lwt_main.run tic
                          ^^^
Error: This expression has type unit -> 'a Lwt.t
       but an expression was expected of type 'b Lwt.t
       Hint: Did you forget to provide `()' as argument?

You’re close - the error message given is correct about what you need to do. tic has type unit -> 'a Lwt.t, and Lwt_main.run has type 'a Lwt.t -> 'a. So you need to do Lwt_main.run (tic ()), because tic () will give you a value of type 'a Lwt.t.

1 Like

Yeah just figure out minute ago, haha! Thanks anyway!