I have been brainstorming ways to share code between elm and elixir, might use it at work. Think some simple calculations like calculating price based on float input and some constants. Some options:
Rust, wasm, rustler
Gleam
Elixir / Erlang compile to js (haven’t found an active project)
Implement small DSL that serializes to json and interpret in each language
Use python (an existing language used in our stack elsewhere), ffi to python from elixir; brython or other python to js compiler
Don’t use shared language, just use a data driven test set in both languages to guarantee equivalent functionality
I mean why you would use a native interface if elm is used for frontend anyway, once you go over the network there is no reason to use anything beside https.
I assume you are suggesting making a network call to the backend to invoke the logic. I wanted something that could respond quickly (as checkboxes are clicked and unclicked, in a long form), so I didn’t keep “call the elixir backend” as an option for this case.
You never mentioned where the infrastructure will be located, if you plan on making a local application where you embed elixir and elm on same machine, then using some of your options might be possible (even though they don’t make much sense, there will be no visible performance gain).
If you need an active communication channel between server and client, then just use websockets. There is the phoenix_channels library that abstracts a messaging interface and luckily there is a client in elm also (if that doesn’t work well you can always use the official JS client), however at this point I would just use liveview as it already does what you want to implement from scratch.
Let’s say Amazon us east data center for backend, and California for client browser. Want library function calls (or network calls) to complete within 500 ms. I guess a websocket could support that need. We already use phoenix channels through elm on some pages.
Maybe ElixirScript would be useful, but I don’t know if it guarantees consistency between calculations done in JS in a browser and an Elixir backend. (It also hasn’t had a commit since 2019)
We ended up duplicating the code between elixir and elm and generating an elm test suite based on the elixir test suite to get assurance about equivalence. Will pursue phoenix channel next time