imandra-ai / imandra-reason-parser

Reason parser for Imandra (fork of reason's parser)
MIT License
3 stars 0 forks source link

Precendence issue with `(++)`? #2

Open actionshrimp opened 6 years ago

actionshrimp commented 6 years ago

If I execute these statements from a single jupyter cell, I get an error:

  switch (s) {
  | Some(X) => "X"
  | Some(O) => "O"
  | None => " "
  };

[@program] let doc_of_grid = (g: grid) => {
  let f = doc_of_square_state;
  Document.s(
    "\n"
    ++ f(g.a)
    ++ "|"
    ++ f(g.b)
    ++ "|"
    ++ f(g.c)
    ++ "\n"
    ++ "-----"
    ++ "\n"
    ++ f(g.d)
    ++ "|"
    ++ f(g.e)
    ++ "|"
    ++ f(g.f)
    ++ "\n"
    ++ "-----"
    ++ "\n"
    ++ f(g.g)
    ++ "|"
    ++ f(g.h)
    ++ "|"
    ++ f(g.i)
  );
};```

```val doc_of_square_state : square_state -> string = <fun>
File "jupyter cell 33", line 11, characters 4-8:
Error: This expression has type string but an expression was expected of type
         ('a -> 'b) ref```

But if I split the statements into two individual cells, and evaluate them separately they work fine.

Rewriting as ```
let doc_of_square_state = (s: square_state) =>
  switch (s) {
  | Some(X) => "X"
  | Some(O) => "O"
  | None => " "
  };

[@program] let doc_of_grid = (g: grid) => {
  let f = doc_of_square_state;
  Document.(Printf.sprintf("\n%s|%s|%s\n-----\n%s|%s|%s\n-----\n%s|%s|%s", f(g.a), f(g.b), f(g.c), f(g.d), f(g.e), f(g.f), f(g.g), f(g.h), f(g.i)));
};

works ok, so I'm wondering if it's something to do with (++)?

actionshrimp commented 6 years ago

Ah yep, here's a more minimal repro:

1;

"hello " ++ "there";