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

Function references have the wrong arity #10

Closed leostera closed 4 years ago

leostera commented 4 years ago

After the last refactor of the Erlang printer, we no longer look up the arity of a function at print time, and thus the default arity that's set to zero here is always printed out.

So this OCaml:

let f g = g ()
let rec g _ = f g

that should compile to this Erlang:

f(G) -> G().
g(_) -> f(fun g/1).

Compiles instead to this erlang:

f(G) -> G().
g(_) -> f(fun g/0).

Note the arity of g is obviously 1 since it takes one parameter, but the function reference does not have this information anymore.

To fix this we should change the way that function references are being created here and use the identifier found to lookup the arity of the function.

This could be done by:

The second approach would be a little cleaner (considering we've gone so far without any mutable state in the translation), and it happily relies on the assumption that every function will be defined before it is used.

The first approach might be easier to hack on.