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 undefined for many externals from the Core module #56

Closed michallepicki closed 3 years ago

michallepicki commented 3 years ago

Describe the bug When using many of the automatically included functions from the Core module, the Caramel code compiles, but Erlang code does not compile with function x/N undefined errors.

To Reproduce

  1. Create a file main.ml with

    let print thing = Io.format "~0tp~n" [ thing ]
    
    let main _ =
    print_int 1 ;
    print_string "asdf" ;
    1 |> print ;
    print @@ 1 ;
    print (succ 1) ;
    print (pred 1) ;
    print (1 lsr 2) ;
    print (1.0 ** 2.0) ;
    print (expm1 2.0) ;
    print (log1p 2.0) ;
    print (hypot 2.0 2.0) ;
    print (copysign 2.0 2.0) ;
    print (mod_float 2.0 2.0) ;
    print (frexp 2.0) ;
    print (modf 2.0) ;
    print (int_of_char 'x') ;
    print (ignore 2) ;
    print (int_of_string "1") ;
    print (float_of_string "1.0") ;
    print (fst (1, 2)) ;
    print (snd (1, 2)) ;
    raise Exit ;
    raise_notrace Exit ;
    ()
  2. Run command caramel compile main.ml && escript main.erl

  3. See errors:

    $ escript main.erl
    [...]
    main.erl:18:9: function '**'/2 undefined
    main.erl:14:3: function '@@'/2 undefined
    main.erl:22:9: function copysign/2 undefined
    main.erl:19:9: function expm1/1 undefined
    main.erl:29:9: function float_of_string/1 undefined
    main.erl:24:9: function frexp/1 undefined
    main.erl:30:9: function fst/1 undefined
    main.erl:21:9: function hypot/2 undefined
    main.erl:27:9: function ignore/1 undefined
    main.erl:26:9: function int_of_char/1 undefined
    main.erl:28:9: function int_of_string/1 undefined
    main.erl:20:9: function log1p/1 undefined
    main.erl:17:9: function lsr/2 undefined
    main.erl:23:9: function mod_float/2 undefined
    main.erl:25:9: function modf/1 undefined
    main.erl:16:9: function pred/1 undefined
    main.erl:11:3: function print_int/1 undefined
    main.erl:12:3: function print_string/1 undefined
    main.erl:32:3: function raise/1 undefined
    main.erl:33:3: function raise_notrace/1 undefined
    main.erl:31:9: function snd/1 undefined
    main.erl:15:9: function succ/1 undefined
    main.erl:13:3: function '|>'/2 undefined
    escript: There were compilation errors.

Expected behavior When Caramel code compiles, Erlang code compiles. It's possible that not all of the above functions are necessary to be implemented for now, but I think it wouldn't be too hard to get them working?

Environment (please complete the following information):

michallepicki commented 3 years ago

I submitted https://github.com/AbstractMachinesLab/caramel/pull/63 and https://github.com/AbstractMachinesLab/caramel/pull/64 for the low-hanging fruits, I will update the issue description to reflect the state of main if/when the second one gets merged. edit: updated.

michallepicki commented 3 years ago

@ostera I am not sure what to do about the remaining ones, as they don't directly translate to Erlang operators or functions in the :erlang module (I think, I may be wrong about some of them). Are any of these very common and expected to be working in OCaml code? Or should we remove them all from Core for now?

leostera commented 3 years ago

At this point feel free to trim down the stdlib whenever you find something that doeesn't immediately make sense. We'll have to time to harden and stabilize it before we get to 1.0.