我刚开始学 Eliom,遇到了 The types of client values must be monomorphic from its usage or from its type annotation。这是我目前的例子。
let%server new_entry_form =
let open Html.D in
let field = Raw.input ~a:[a_input_type `Text] () in
let submit = Raw.button ~a:[a_class ["button"]] [txt "add"] in
ignore
[%client
let open Html.D in
let open Js_of_ocaml_lwt.Lwt_js_events in
let field = Html.To_dom.of_input ~%field in
(Lwt.async @@ fun() ->
clicks (Html.To_dom.of_element ~%submit)
(fun _ _ ->
let entered = field##value |> Js_of_ocaml.Js.to_string in
add_entry {id="5";name=entered;description=""};
Lwt.return_unit):unit
)];
div [
field;submit
]
我猜问题出在 ~%field 和 ~%submit 上。代码看起来很像教程里的例子,为什么会报错?我哪里做错了?
从英语翻译·查看原文I'm new to Eliom and encounter The types of client values must be monomorphic from its usage or from its type annotation. This is the example I've got so far:
let%server new_entry_form =
let open Html.D in
let field = Raw.input ~a:[a_input_type `Text] () in
let submit = Raw.button ~a:[a_class ["button"]] [txt "add"] in
ignore
[%client
let open Html.D in
let open Js_of_ocaml_lwt.Lwt_js_events in
let field = Html.To_dom.of_input ~%field in
(Lwt.async @@ fun() ->
clicks (Html.To_dom.of_element ~%submit)
(fun _ _ ->
let entered = field##value |> Js_of_ocaml.Js.to_string in
add_entry {id="5";name=entered;description=""};
Lwt.return_unit):unit
)];
div [
field;submit
]
I'm guessing ~%field and ~%submit are the trouble. Why does this produce an error when it looks much like the tutorial code? Where have I gone wrong?