Besides "just use C FFI" does anyone have a good tutorial for:
OCaml <-> Rust Interop
OCaml Rep <-> Rust Interop
I'm a big fan of the Rust language, but sometimes I'm really wishing I had a REPL where I could create a few objects, call a few trait functions, and send a few objects to some mpsc::Channels.
Of all the languages to interop with Rust, OCaml seems the nicest. Suggestions?
I would like to achieve the following. Can you provide guidance of roughly what to do:
At https://github.com/zshipko/ocaml-rs/tree/master/example/src you have sample code where (a) Rust side uses caml! macro and (b) OCaml side has some type signatures. There's also a dune file -- so that when we run "dune utop", we can then call the Rust functions.
Is there a way to do the above with an OCaml REPL embedded in a Rust app? I want a situation where (1) the Rust app starts running (2) it opens up some TCP port, say 8888 -- and (3) offers me an OCaml REPL (with lots of Rust functions) on that port.
Is there a way to make this work with wasm32? I want a situation where: I have a webapp written in Rust, but then it opens a textarea ... and gives me an OCaml REPL (with lots of exported Rust functions).
Using the Toploop or Optoploop ocaml modules as suggested by @zshipko should work fine to have access to a toplevel.
That's actually what utop or the jupyter ocaml kernel are using. I don't have a tutorial at hand but would suggest looking at eval_phrase in this file from the jupyter kernel. I recently worked on this to allow python code to call the ocaml top-level and this worked fine, hopefully the result will be released as open-source in the near future.