Ocaml 如何将用户类型从Eliom客户端传递到coservice?

Ocaml 如何将用户类型从Eliom客户端传递到coservice?,ocaml,json-rpc,ocsigen,Ocaml,Json Rpc,Ocsigen,显示接受用户定义类型的GET服务的示例。我想从客户端调用用户类型为的coservice,在客户端调用相同类型的coservice。这似乎是可能的,但我明白了 ocsigenserver: main: Exn during page generation: Failure("User service parameters 'foo' type not supported client side.") (sending 500) 当我尝试 {shared{ open Eliom_lib o

显示接受用户定义类型的GET服务的示例。我想从客户端调用用户类型为的coservice,在客户端调用相同类型的coservice。这似乎是可能的,但我明白了

ocsigenserver: main: Exn during page generation: Failure("User service parameters 'foo' type not supported client side.") (sending 500)
当我尝试

{shared{
  open Eliom_lib
  open Eliom_content
  open Html5.D

  type foo = A | B
  let foo_of_string = function "a" -> A | "b" -> B | _ -> raise (Failure "foo_of_string: unsupported foo")
  let string_of_foo = function A -> "a" | B -> "b"
}}

let foo_to_div foo : Html5_types.div Html5.elt Lwt.t = match foo with A -> Lwt.return (div [pcdata "aye"]) | B -> Lwt.return (div [pcdata "bee"])
let foo_service =
  Eliom_registration.Ocaml.register_post_coservice'
    ~post_params:Eliom_parameter.(user_type foo_of_string string_of_foo "foo")
    (fun () foo -> foo_to_div foo)

{client{
  let test () =
    Eliom_client.call_ocaml_service ~service:%foo_service () A
 }}


(* Boilerplate from eliom-distillery: *)
module Testing_app = Eliom_registration.App
  (struct let application_name = "testing" end)
let main_service =
  Eliom_service.App.service ~path:[] ~get_params:Eliom_parameter.unit ()
let () =
  Testing_app.register ~service:main_service
    (fun () () -> Lwt.return (Eliom_tools.F.html ~title:"foo"
                                Html5.F.(body [ pcdata "bar" ])))

我还尝试使用,但后来遇到了如何将div恢复为json的问题;做

type div_elt = Html5_types.div Eliom_content.Html5.elt
let div_elt_json = Json.t<div_elt>
type div\u elt=Html5\u types.div Eliom\u content.Html5.elt
让div_elt_json=json.t

给我错误:未绑定模块Html5\u types.Json\u div

在阅读服务器函数后,我偶然向下滚动了一点,找到了说要做的

{shared{ 
  type foo = A | B deriving (Json)
  type foo_json = Json.t<foo>
}}
let foo_service =
  Eliom_registration.Ocaml.register_post_coservice'
    ~post_params:Eliom_parameter.(ocaml "param" foo_json)
    (fun () foo -> foo_to_div foo)
{共享{
类型foo=A | B派生(Json)
输入foo_json=json.t
}}
让富奥服务=
Eliom\u registration.Ocaml.register\u post\u coservice'
~post_params:Eliom_参数。(ocaml“param”foo_json)
(fun()foo->foo_to_div foo)
这个有效=D

(尽管我还是更喜欢使用服务器功能,这似乎更简洁一些。)