leostera / caramel

:candy: a functional language for building type-safe, scalable, and maintainable applications
https://caramel.run
Apache License 2.0
1.06k stars 25 forks source link

Idiomatic Elixir wrappers for generated code #76

Open leostera opened 3 years ago

leostera commented 3 years ago

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