Reason: [rtop] ^ deref becomes `not` when loading files with #use

Created on 2 Jun 2018  路  3Comments  路  Source: reasonml/reason

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 ^.

Toolchain

位 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!

BUG Rtop

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 !a in ocaml,
and !a in reason becomes not a in ocaml.

All 3 comments

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

Was this page helpful?
0 / 5 - 0 ratings