Reasonml type with multiple arguments, Error exception Failure("nth")

Viewed 267

I have got Error while compiling the following code

type shape =
  | Circle int
  | Square int
  | Rectangle int int;

let myShape = Circle 10;

let area =
  switch myShape {
  | Circle r => float_of_int (r * r) *. 3.14
  | Square w => float_of_int (w * w)
  | Rectangle w h => float_of_int (w * h)
  };

Js.log area;

Fatal error: exception Failure("nth")
ninja: build stopped: subcommand failed.

When I change the Rectangle to tuple (int, int), it works

type shape =
  | Circle int
  | Square int
  | Rectangle (int, int);

let myShape = Circle 10;

let area =
  switch myShape {
  | Circle r => float_of_int (r * r) *. 3.14
  | Square w => float_of_int (w * w)
  | Rectangle (w, h) => float_of_int (w * h)
  };

Js.log area;

Is it not possible to have multiple arguments on a data constructor?

thanks

Issue has been submitted to buckelscript https://github.com/BuckleScript/bucklescript/issues/1822

1 Answers
Related