OnWorks favicon

js_of_ocaml - Online in the Cloud

Run js_of_ocaml in OnWorks free hosting provider over Ubuntu Online, Fedora Online, Windows online emulator or MAC OS online emulator

This is the command js_of_ocaml that can be run in the OnWorks free hosting provider using one of our multiple free online workstations such as Ubuntu Online, Fedora Online, Windows online emulator or MAC OS online emulator



js_of_ocaml - OCaml bytecode to Javascript compiler


js_of_ocaml(1) is a compiler from OCaml bytecode programs to Javascript. It makes it
possible to write OCaml programs that run on web browsers.

It comes with bindings for a large part of the browser APIs, and the generated programs
have been measured to typically run faster the OCaml bytecode interpreter.


Your program must be first compiled using the OCaml bytecode compiler ocamlc(1).
Javascript bindings, as well as a corresponding syntax extension, are provided by the
js_of_ocaml package.

ocamlfind ocamlc -package js_of_ocaml -package js_of_ocaml.syntax \
-syntax camlp4o -linkpkg -o input_file.byte input_file.ml

Then, run the js_of_ocaml(1) compiler to produce Javascript code.

js_of_ocaml [ options ] input_file.byte


The following command-line options are recognized by js_of_ocaml(1).

-debug name
debug module name

-disable name
disable optimization name

pretty print the output

output debug info

disable inlining

do not include the standard runtime

compile a toplevel

-I dir Add dir to the list of include directories

-o file
set output file name to file

-help Display the list of options

--help Display the list of options


The whole OCaml standard library should be supported, except for input/output channels,
weak references, and most functions of the Sys module. Extra libraries such as Bigarray,
Unix, Thread or Str are not supported.

Tail call is not optimized in general. However, self-recursive functions (when the tail
calls are to the function itself) are compiled into a loop.

Recursive modules are not supported at the moment.

Data representation differs from the usual one, for performance reasons. Most notably,
integers are 32 bit (instead of 31 or 63 bits) and floats are not boxed. As a consequence,
marshalling, polymorphic comparison, and hashing functions can yield results different
than usual:

· marshalling of floats is not supported (unmarshalling works);

· the polymorphic hash function will not give the same results on data structures
containing floats;

· these functions may be more prone to stack overflow, as the Javascript stack is small.

Use js_of_ocaml online using onworks.net services

Free Servers & Workstations

Download Windows & Linux apps

Linux commands