Questions tagged [js-of-ocaml]

Js_of_ocaml is a compiler from OCaml bytecode to JavaScript, making it possible to run OCaml programs in a web browser.

Features

  • The whole language and most of the standard library are supported.
  • The compiler is easy to install: it only depends on Findlib and optionally .
  • The generated code is independent of Eliom and the Ocsigen server. You can use it with any web server.
  • You can use a standard installation of OCaml to compile your programs. In particular, you do not have to recompile a library to use it with Js_of_ocaml. You just have to link your program with a specific library to interface with browser APIs.

Useful resources

66 questions
0
votes
2 answers

vscode extension with a typed functional language

Is it possible to build a vscode extension from a javascript transpiler ? For example, is it possible to build an extension with "js of ocaml" or purescript. Those transpilers compiles to javascript. From what I understand, vscode extensions have to…
user2187032
  • 63
  • 1
  • 6
0
votes
1 answer

How to transform the Yojson Library of Ocaml into a .byte file using js_of_ocaml?

I am trying to transform the Yojson with the source code download online into a byte file using js_of_ocaml. I try the following commands: %: ocamlfind ocamlc -package yojson -linkpkg -g -o yojson.cmo %: ocamlfind ocamlc -package js_of_ocaml…
0
votes
0 answers

Convert OCaml Vdom Node to html string

I'm trying to use janestreet/virtual_dom both in the browser and on my server. In the browser, you don't use HTML directly, that's the whole point of vdom! But, on the server, I'm interested in trying to figure out how to render an HTML document…
cdaringe
  • 1,274
  • 2
  • 15
  • 33
0
votes
1 answer

TypeError: runtime is undefined

I'm trying to export a standalone library in JavaScript thanks to js_of_ocaml. To build the JavaScript file, I used this command: js_of_ocaml --wrap-with-fun=stringextCma --pretty --no-cmis \ -I ~/.opam/learn-ocaml/lib/stringext…
Maiste
  • 1
  • 1
0
votes
1 answer

How do I cast an OCaml object into a js_of_ocaml object?

Is it possible to cast or coerce an OCaml object into a js_of_ocaml object and back?
Olle Härstedt
  • 3,799
  • 1
  • 24
  • 57
0
votes
1 answer

Why is the ##. operator needed in js_of_ocaml?

Not sure why all those operators are needed. What's the rationale? Why is not the regular OCaml object syntax enough? obj##.m obj##.m := e obj##m Documentation here: http://ocsigen.org/js_of_ocaml/3.6.0/manual/ppx
Olle Härstedt
  • 3,799
  • 1
  • 24
  • 57
0
votes
0 answers

Unimplemented Javascript primitive caml_pure_js_expr (again)

I have a project in OCaml that could be compiled in Ubuntu long time ago. Today, I want to pick up the project and try to compile it in macOS Mojave 10.14.2. ocaml --version returns The OCaml toplevel, version 4.07.1, js_of_ocaml --version returns…
SoftTimur
  • 5,630
  • 38
  • 140
  • 292
0
votes
1 answer

How to compile a file that uses the JsooTop module?

I have this in a file named main.ml: let () = JsooTop.initialize () I tried compiling the file using: ocamlfind ocamlc -package js_of_ocaml -linkpkg -o main.byte main.ml But this error appears: File "main.ml", line 1, characters 9-27: Error:…
Flux
  • 9,805
  • 5
  • 46
  • 92
0
votes
1 answer

Use the value of a textarea with js_of_ocaml

I'm trying to use the value of a textarea with js_of_ocaml. Here is my source code : let matrix () = let text1 = get_textarea "input_1" in let btn1 = get_elem "btn_1" in text1##placeholder <- Js.string "Write your matrix !"; …
0
votes
1 answer

Flow (typescript checker) configuration to follow symlinks on windows

I cannot get flow (the facebook' type checker for javascript) to follow symbolic links directories created on Windows 10 (I do use Linux for this project, so not sure if it works there or not) Flow documentation states that Symbolic links will be…
V P
  • 845
  • 10
  • 28
0
votes
1 answer

How to create an optdef_prop with ppx syntax in js_of_ocaml?

How can I create an object property of type Js.optdef_prop with the PPX syntax in js_of_ocaml? I tried something like follow but with no success: type t = Js.t ... (object%js val foo = Js.Optdef (Js.string…
Antoine
  • 1,782
  • 1
  • 14
  • 32
0
votes
1 answer

js_of_ocaml Camlp4 Parse error in type definition

I'm trying to build this program using js_of_ocaml. According to this answer, I've got the following line in my makefile OCAMLC = ocamlfind ocamlc -package js_of_ocaml -package js_of_ocaml.syntax -syntax camlp4o -linkpkg -g -dtypes However,…
jmite
  • 8,171
  • 6
  • 40
  • 81
0
votes
1 answer

Ocamlbuild can't find Ocamlbuild_js_of_ocaml cmx file

I'm starting an web development project and was hoping to use Js_of_ocaml. However, when attempting to use OCamlbuild as my build tool, I've encountered the following error: Warning 58: no cmx file was found in path for module…
superlizardmo
  • 333
  • 1
  • 11
0
votes
1 answer

Wrapping fused getter-setter functions

I'm having trouble wrapping a subset of d3-force using jooc. The library does not use object properties and instead implements fused getter-setter functions, e.g. simulation.force("x", d3.forceX()) // setter simulation.force("x") //…
Sergei Lebedev
  • 2,659
  • 20
  • 23
0
votes
1 answer

Is it possible to wrap an asynchronous JS function and use it in OCaml?

We could use js_of_ocaml to wrap a JS function and thus call it within OCaml. I cannot make a working example when the JS function is asynchronous (ie, includes promises and takes time). The asynchronous JS function JSfun I want to wrap is as…
SoftTimur
  • 5,630
  • 38
  • 140
  • 292