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

Fun references of operators have the wrong arity and module name #70

Closed leostera closed 3 years ago

leostera commented 3 years ago

From #57 by @michallepicki:

This leads to another related issue, currently:

Lists.foldl ( + ) 1 [1; 2; 3]

generates

lists:foldl(fun '+'/0, 1, [1 | [2 | [3 | []]]])

where it lacks the erlang: prefix and the arity is wrong. Not sure if this is something that should be supported right now or not.

michallepicki commented 3 years ago

May be related to https://github.com/AbstractMachinesLab/caramel/issues/10 fixed in https://github.com/AbstractMachinesLab/caramel/commit/1b4e6b80083920a748b9e4ebda88cb48271bd740 ? At least it may be a good starting point to dive in

michallepicki commented 3 years ago

This may or may not be related, fun references of regular functions (not operators) cannot be used this way:

let print thing = Io.format "~0tp~n" [ thing ]
let main _ =
  let transforms = [ Binary.first; Binary.last ] in
     print (Lists.map (fun g -> g "Hello World") transforms)

results in

% Source code generated with Caramel.
-module(main).

-export([main/1]).
-export([print/1]).

-spec print(_) -> ok.
print(Thing) -> io:format(<<"~0tp~n">>, [Thing | []]).

-spec main(_) -> ok.
main(_) ->
  Transforms = [binary:first | [binary:last | []]],
  print(lists:map(fun
  (G) -> G(<<"Hello World">>)
end, Transforms)).

fun and the /arity is missing