Support expression sequences
michallepicki opened this issue · comments
Describe the bug
When combining multiple OCaml expressions with ( expr1 ; expr2 )
or begin expr1 ; expr2 end
, the resulting Erlang code is "flattened" and can have different result than expected or not compile at all.
To Reproduce
- Create a file
main.ml
containing
let print thing = Io.format "~0tp~n" [ thing ]
let main _ =
print
( print "hej" ;
true )
or
let print thing = Io.format "~0tp~n" [ thing ]
let main _ =
print
begin
print "hej" ;
true
end
- Run command
caramel compile main.ml && escript main.erl
- See error:
main.erl:10: function print/2 undefined
This happens because of this incorrect generated Erlang code:
% 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(_) -> print(print(<<"hej">>),
true).
Expected behavior
Erlang gets generated with:
-spec main(_) -> ok.
main(_) -> print(begin print(<<"hej">>), true end).
Environment (please complete the following information):
- OS: Ubuntu Linux 18.04
- Caramel version 0.1
- Erlang version 23.2.2
This may be a good point to start: https://github.com/AbstractMachinesLab/caramel/blob/main/caramel/compiler/ocaml_to_erlang/fun.ml#L399
I will look into this one
With #80 as of e2f88eb we're getting this output:
% 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(_) -> print(begin
print(<<"hej">>),
true
end).
and it runs:
$ caramel compile main.ml
Compiling main.erl OK
$ escript main.erl
<<"hej">>
true