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

Fun references of operators have the wrong arity and module name

leostera opened this issue · comments

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.

May be related to #10 fixed in 1b4e6b8 ? At least it may be a good starting point to dive in

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