代码之家  ›  专栏  ›  技术社区  ›  Andrew Cheong

如何修改这行OCaml以不返回函数?

  •  0
  • Andrew Cheong  · 技术社区  · 6 年前

    在不理解OCaml的情况下,我试图通过这个错误来运行命令行实用程序。

    $ dune build
    File "_none_", line 1:
    Warning 58: no cmx file was found in path for module Toploop, and its interface was not compiled with -opaque
    File "vendor/notty/lwt/notty_lwt.ml", line 68, characters 25-64:
    Error: This expression has type (unit -> unit) Lwt.t
           but an expression was expected of type unit Lwt.t
           Hint: Did you forget to provide `()' as argument?
    

    第68行如下:

        Lwt.async (fun () -> Lwt_stream.closed stream >|= fun _ -> f);
    

      let input_stream ~nosig fd stop =
        let `Revert f = setup_tcattr ~nosig (Lwt_unix.unix_file_descr fd) in
        let stream =
          let flt  = Unescape.create ()
          and ibuf = Bytes.create bsize in
          let rec next () =
            match Unescape.next flt with
            | #Unescape.event as r -> Lwt.return_some r
            | `End   -> Lwt.return_none
            | `Await ->
                (Lwt_unix.read fd ibuf 0 bsize <??> stop) >>= function
                  | Left n  -> Unescape.input flt ibuf 0 n; next ()
                  | Right _ -> Lwt.return_none
          in Lwt_stream.from next in
        Lwt.async (fun () -> Lwt_stream.closed stream >|= fun _ -> f);
        stream
    

    现在,我在堆栈溢出上发现了另一个问题,该问题描述了相同的错误: OCaml: Lwt expression was expected of type unit Lwt.t . 这里,回答者建议更换

    let create_server sock =
      let serve () =
        Lwt_unix.accept sock >>= accept_connection
      in serve (* serve is a function, not a thread *)
    

    具有

    let create_server sock =
      Lwt_unix.accept sock >>= accept_connection
    

    如果必须的话,我会去学习一些OCaml和这个让我想起lambdas的奇怪语法。但我所要做的就是安装一个基于终端的游戏计时器,这样我就可以玩我的游戏了,而且我已经在这个兔子洞里走得比我想玩的更远了。任何帮助都将不胜感激。

    0 回复  |  直到 6 年前
        1
  •  2
  •   OlivierBlanvillain    6 年前
    Lwt.async (fun () -> Lwt_stream.closed stream >|= fun _ -> f ());
    
    推荐文章