Converting Module Signatures ReasonML -> Rescript

I have this script in the playground which compiles in Reasonml but not rescript. playground

Syntax Errors

[E] Line 212, column 33:

Did you forget a `)` here?

[E] Line 213, column 0:

I'm not sure what to parse here when looking at ")".

Line 212 is bad rescript is:

module Same = (Na: N, Nb: N): (
  S with type number1 = Na.number with type number2 = Nb.number
) => {
  type number1 = Na.number
  type number2 = Nb.number
  let rec sim = ((n, m)) =>
    if Na.is_zero(n) {
      Nb.is_zero(m)
    } else {
      sim((Na.pred(n), Nb.pred(m)))
    }
  let similar = ((n, m)) =>
    try sim((n, m)) catch {
    | Na.Too_small => false
    | Nb.Too_small => false
    }
}

in compiling reasonml, its:

module Same =
       (Na: N, Nb: N)
       : (S with type number1 = Na.number with type number2 = Nb.number) => {
  type number1 = Na.number;
  type number2 = Nb.number;
  let rec sim = ((n, m)) =>
    if (Na.is_zero(n)) {
      Nb.is_zero(m);
    } else {
      sim((Na.pred(n), Nb.pred(m)));
    };
  let similar = ((n, m)) =>
    try (sim((n, m))) {
    | Na.Too_small => false
    | Nb.Too_small => false
    };
};

Anything jump out about how fix the syntax? Thank you.

I think you found a bug in the conversion tool when converting a functor signature with multiple sharing constraints to rescript.

should be:

module Same = (Na: N, Nb: N): (
  S with type number1 = Na.number and type number2 = Nb.number
)

I think you should open an issue on rescript-syntax repo with the repro.

2 Likes

Indeed. Thank you.

Issue posted.

Issue has been resolved here.

If you want to express this code you need extra parens for clarity:
(S with type number1 = Na.number) with type number2 = Nb.number
As @tsnobip pointed out, you might have intended the following instead: S with type number1 = Na.number and with type number2 = Nb.number? Which is a different thing?

These are very esoteric corners of the language, best to avoid them unless you absolutely need them.

1 Like

This topic was automatically closed after 14 days. New replies are no longer allowed.