Hi! I was trying to get the following example loaded on rtop:
let a = ref(0.0);
a := a^ +. a^;
And if I type it in manually it works just fine:
Reason # let a = ref(0.0);
let a: ref(float) = {contents: 0.};
Reason # a := 1.0;
- : unit = ()
Reason # a;
- : ref(float) = {contents: 1.}
Reason # a^;
- : float = 1.
Reason # a^ +. a^;
- : float = 2.
Reason # a := a^ +. a^;
- : unit = ()
But when loading the code with #use I see this:
Reason # #use "./Test.re";
let a: ref(float) = {contents: 0.};
File "./Test.re", line 3, characters 5-6:
Error: This expression has type ref(float)
but an expression was expected of type bool
Whereas I'd expect this to parse and run normally. I've recurred so far to using .contents instead of ^.
位 rtop -version
The universal toplevel for OCaml, version 2.1.0, compiled for OCaml version 4.02.3
位 bsb -version
3.1.4
Let me know if I can provide any other information!
As a follow up I understand that in the contrived example I provided I could have rebound a, but in my own code I need to mutate from different scopes and thus rebinding is not an option.
rtop hasn't gotten a ton of attention afaik :/
I think I know what's going on though! Somehow we've got a double conversion, because:
a^ in reason becomes !a in ocaml,
and !a in reason becomes not a in ocaml.
I hit this bug today. Narrow this down to Reason_toolchain.RE.use_file https://github.com/facebook/reason/blob/69837eab531c18af1afb35c9fdf6e3931ce951d8/src/rtop/reason_toploop.ml#L17-L19
Most helpful comment
rtop hasn't gotten a ton of attention afaik :/
I think I know what's going on though! Somehow we've got a double conversion, because:
a^in reason becomes!ain ocaml,and
!ain reason becomesnot ain ocaml.