caramel icon indicating copy to clipboard operation
caramel copied to clipboard

Idiomatic Elixir wrappers for generated code

Open leostera opened this issue 4 years ago • 0 comments

Right now we're generating a bunch of Erlang code that can be clunky to call from Elixir. It should be relatively straightforward to generate Elixir wrappers that use defdelegate to call the underlying Erlang modules while looking more idiomatic.

After all, we have the entire module paths available as well when we flatten them out, so we can use them for namespacing as well.

So this Caramel code:

(* file: Math.ml *)
let add x y = x + y

Generates the following Erlang:

-module(math).

-export([add/2]).

add(X, Y) -> X + Y.

and the following Elixir:

defmodule Math do
  defdelegate add(_x, _y), to: :math
end

leostera avatar Mar 07 '21 08:03 leostera