我一直在测试使用Lwt的ocsigen.我猜Lwt的意思是"轻量级线程",对吗?如果是这样,我们怎么称它为"轻量级"?
似乎Lwt使用OS的线程并不轻(与Erlang和Haskell相比).
请点亮我,谢谢!
我偶然发现了OCaml中的以下编译消息:
This simple coercion was not fully general. Consider using a double coercion.
Run Code Online (Sandbox Code Playgroud)
它发生在相当复杂的源代码中,但这是一个MNWE:
open Eliom_content.Html.D
let f_link s =
let arg : Html_types.phrasing_without_interactive elt list = [pcdata "test"] in
[ Raw.a ~a:[a_href (uri_of_string (fun () -> "test.com"))] arg ]
type tfull = (string -> Html_types.flow5 elt list)
type tphrasing = (string -> Html_types.phrasing elt list)
let a : tfull = ((f_link :> tphrasing) :> tfull)
let b : tfull = (f_link :> tfull)
Run Code Online (Sandbox Code Playgroud)
您可以在ocamlfind ocamlc -c -package eliom.server …
现在我们已成功使用ocsigen来托管旧的python cgi应用程序.但是,我们需要详细研究ocsigen,以决定是否使用OCaml语言开发新的Web应用程序.
任何建议表示赞赏!
配置文件test.conf如下:
<ocsigen>
<server>
<port>*:8000</port>
<logdir>/home/zaxis/tmp/log/</logdir>
<datadir>/home/zaxis/tmp/data</datadir>
<user>zaxis</user>
<group>wheel</group>
<charset>utf-8</charset>
......
<extension findlib-package="ocsigen_ext.cgimod">
<cgitimeout value="30"/>
</extension>
<extension findlib-package="ocsigen_ext.staticmod"/>
......
<site path="qachina" charset="utf-8">
<cgi root="cgi-bin" dir="/media/E/www/qachina/cgi-bin"/>
<static dir="/media/E/www/qachina" />
</site>
....
<commandpipe>/home/zaxis/tmp/ocsigen_command</commandpipe>
</server>
</ocsigen>
Run Code Online (Sandbox Code Playgroud)
然后我运行Ocsigen:
ocsigeocsigen -c test.conf
我可以访问http://127.0.0.1:8000/qachina/index.htm.但是,Ocsigen不会在cgi-bin中执行我的python脚本,但希望浏览器下载它.
顺便说一句,所有python脚本文件都可以直接在shell中运行.
>head cgi-bin/nav.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-enter code here
...
Run Code Online (Sandbox Code Playgroud)
我无法访问Ocsigen的邮件列表,所以我在这里发帖寻求建议.
该Ocsigen/Eliom教程开始与提供了一个应用实例"你好,世界!" 作为HTML:
open Eliom_content.Html5.D
let main_service =
Eliom_registration.Html5.register_service
~path:["graff"]
~get_params:Eliom_parameter.unit
(fun () () ->
Lwt.return
(html
(head (title (pcdata "Page title")) [])
(body [h1 [pcdata "Graffiti"]])))
Run Code Online (Sandbox Code Playgroud)
如何将其作为JSON服务呢?具体来说,如何注册JSON服务,以及应该使用哪些库/组合器来生成/序列化JSON(js_of_ocaml?)?
可以使用Lwt.return作为递归函数的最终调用吗?
我有一个编译正常但功能不正常的函数,它看起来像f下面的函数.请假设g在此示例中提供的任何功能都没有问题,我基本上只是试图找出是否可以使用以下形式的函数,或者是否有更好/更简单(和Lwt兼容)的方式做以下事情:
let rec f (x : string list) (g : string -> unit Lwt.t) =
match List.length x with
| 0 -> Lwt.return ()
| _ -> g (List.hd x) >>= fun () -> f (List.tl x) g
;;
val f : string list -> (string -> unit Lwt.t) -> unit Lwt.t = <fun>
Run Code Online (Sandbox Code Playgroud)
我很确定我做错了.但是我使用的实际功能比这个例子复杂得多,所以我很难调试它.