ocamljs-of-ocaml

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?


Solution

  • 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.