leostera / caramel

:candy: a functional language for building type-safe, scalable, and maintainable applications

Home Page:https://caramel.run

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Idiomatic Elixir wrappers for generated code

leostera opened this issue · 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