3

I'm trying to learn ReasonML and following the example for bs-json we can decode raw json into a type like this:

type point = {
  x: float,
  y: float
};

module Decode = {
  let point = json =>
    Json.Decode.{
      x: json |> field("x", float),
      y: json |> field("y", float)
    };
}

I'm a bit confused as to what this Json.Decode.{ ... } is. I understand we can open up a scope into a module using the .() dot parenthesis, but I haven't seen this dot curly braces before.

glennsl
  • 28,186
  • 12
  • 57
  • 75
Homan
  • 25,618
  • 22
  • 70
  • 107

1 Answers1

1

It means pretty much the same thing, that Json.Decode is opened in the scope of {}, which defines a record, as usual. Essentially just a short-hand for Json.Decode.({ .. }).

Edit: I just added a note to bs-jsons README, just below the example, to explain this syntax.

glennsl
  • 28,186
  • 12
  • 57
  • 75