Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

js_of_ocaml and Core

I'm quite new to OCaml and to the js_of_ocaml compiler in particular.

Did someone manage to compile the application which uses Jane Street Core with js_of_ocaml? I get lots of "missing primitives" warnings during the compilation, and then when I try to run it with node they turn into an actual exceptions.

I understand that those are primitives which can't be ported from OCaml to JS and that their implementation should depend on the application, but for core there is literally thousands of them, whereas my program only uses output to stdout.

On a side note, I had trouble even compiling a simple "hello world" project, as IO functions weren't implemented in JS. Is there a "standard" JS file somewhere which could be used for this purpose? e.g. replacing caml_ml_output_char with console.log and other things, so that modules can be compiled to something useful without writing any custom javascript?

like image 323
George Karpenkov Avatar asked Feb 05 '14 12:02

George Karpenkov


3 Answers

Yes, it is possible to compile Core_kernel with js_of_ocaml, OCamlPro did a version of Try-OCaml with it. It requires to patch a few of its dependencies (sexplib, ounit, etc.) and to use the latest version of js_of_ocaml from the repository, that includes a bigarray implementation.

like image 50
Fabrice Le Fessant Avatar answered Nov 19 '22 05:11

Fabrice Le Fessant


as of today, core_kernel version 0.9, it works.

after compile to bytecode.

run js_of_ocaml

js_of_ocaml +weak.js +nat.js +base/runtime.js +core_kernel/runtime.js +bin_prot/runtime.js main.bc

or add the js_of_ocaml in jbuilder directly.

(js_of_ocaml (
    (flags (+weak.js +nat.js +base/runtime.js +core_kernel/runtime.js +bin_prot/runtime.js))))
like image 45
echo Avatar answered Nov 19 '22 04:11

echo


Yeah, missing primitives are the issue when using Core with js_of_ocaml. There is core_kernel library. It is a subset of Core which contains basic functions. UNIX-related functions from core are not included to Core_kernel. If I remember correctly, the main reason for extracting Core_kernel from Core is your issue.

Update. I have failed. It seems that developers have tried to allow using Core_kernel with js_of_ocaml but without success. It seems that you can't do it now. They are waiting for OCaml namespaces.

like image 39
Kakadu Avatar answered Nov 19 '22 05:11

Kakadu