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.
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-json
s README, just below the example, to explain this syntax.