I wrote this piece of code with Lwt 2.7.0 :
open Lwt
let listen_address = Unix.inet_addr_loopback
let port = 9000
let backlog = 1
let () = Lwt_log.add_rule "*" Lwt_log.Info
let create_socket () =
let open Lwt_unix in
let sock = socket PF_INET SOCK_STREAM 0 in
let sockaddr = ADDR_INET(listen_address, port) in
let%lwt () = Lwt_unix.Versioned.bind_2 sock sockaddr in
listen sock backlog;
sock
And I got this error (on the last line, i.e. sock
) :
Error: This expression has type Lwt_unix.file_descr
but an expression was expected of type 'a Lwt.t
Well, yes, sock
is of type Lwt_unix.file_descr
, why would the compiler throw this program and force the type 'a Lwt.t
? (when I ask what type was found for create_socket
it tells me it's of type unit -> '_a
)
P.S. : Thanks to Daniil Baturin : http://baturin.org/code/lwt-counter-server/