Skip to content

discuss: compiling rawlambda output to javascript #338

@bobzhang

Description

@bobzhang

This is just for discussion.

We know that there was another backend ocamljs which compiles lambda expression to javascript in 2010. That project was abandoned. However, things have changed a lot since then.

From ocaml side, all ocaml compiler libraries are installed, even driver/main.cmo and driver/optmain.cmo are installed, unlike ocamljs, there is basically no need to patch(or minimal) the compiler to get rawlambda output.

From javascript side, especially with the popularity of nodejs and es6, we can map one ocaml module into one js module. There are other tools like webpack which could bundle all js modules which means we don't even need a js linker, the javascript community is used to having a transpiler in their workflow.

The benefit is obvious, the -drawlambda output preserves most ocaml skeleton, and can be easily mapped into javascript high level constructs, we can generate really readable javascript output with function name preserved.

ocamljs is already a proof of concept that it will work. Since we are doing one module to module mapping, the FFI will be much more friendly. js_of_ocaml is an amazing tool, it can literally make almost any pure ocaml application into javascript, but that still keeps us in a very small community(OCaml is my favoriate language, but I miss javascript community and npm). But if we can generate readable javascript, I think that will be a game changer, it will be attractive to javascript community as well.

Given the similiarity between rawlambda output and javascript ast, I think the required work should be affordable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions