1
我正在按照教程解釋如何在OCaml中使用lwt
和Cohttp
來製作簡單的Web服務器。錯誤:未綁定的記錄字段Server.callback - Ocaml
我有一個_tags
文件,其中包含以下內容:
true: package(lwt), package(cohttp), package(cohttp.lwt)
並有webserver.ml
:
open Lwt
open Cohttp
open Cohttp_lwt_unix
let make_server() =
let callback conn_id req body =
let uri = Request.uri req in
match Uri.path uri with
| "/" -> Server.respond_string ~status:`OK ~body:"hello!\n"()
| _ -> Server.respond_string ~status:`Not_found ~body:"Route not found"()
in
let conn_closed conn_id() =() in
Server.create { Server.callback; Server.conn_closed }
let _ =
Lwt_unix.run (make_server())
然後,ocamlbuild -use-ocamlfind webserver.native
觸發以下錯誤:
Error: Unbound record field callback
Command exited with code 2.
如果我改變到:Server.create { callback; conn_closed }
它也會t rigger:
Error: Unbound record field callback
Command exited with code 2.
我不知道如何解決這個問題,所以在此先感謝您進行調查。
它呢!感謝您的非常詳細的答案。 –