Erlang or Elixir + Ocaml, via NIF

I’m familiar with the matter in general, but I’ve worked only with C and C++ for interracting with Elixir/Erlang. I’ve not found any simple example for that in OCaml.

How to do it? Without any third-party libraries, but directly: Erlang <-> OCaml, via NIF.

Or, perhaps, only if there’s no direct way: Erlang <-> C <-> OCaml,

Based on what I know of OCaml’s FFI and NIFs (which isn’t a whole lot) I think you’d need to have some C wrappers. From what I understand about NIFs is they’re basically a C ABI for external code, and calling OCaml directly requires a bit of nuance depending on what you’re doing:

There most likely would have to be some kind of translation between OCaml value types and Erlang value types as I don’t think they’d be usable by one another directly (but happy to be corrected :slight_smile:). If using ports instead is an option it seems that route is much easier:

Out of curiosity, why not say Rust for a safer NIF?

1 Like