【问题标题】:What does Json.Decode.{} mean? The dot curly braces partJson.Decode.{} 是什么意思?点花括号部分
【发布时间】:2018-12-04 05:38:23
【问题描述】:

我正在尝试学习 ReasonML,并按照 bs-json 的示例,我们可以将原始 json 解码为如下类型:

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

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

我对@9​​87654322@ 是什么感到有些困惑。我知道我们可以使用.() 点括号将范围打开到模块中,但我以前没有见过这个点花括号。

【问题讨论】:

    标签: module reason bucklescript bs-json


    【解决方案1】:

    这意味着几乎相同的东西,Json.Decode{} 的范围内打开,它像往常一样定义了一条记录。本质上只是Json.Decode.({ .. }) 的简写。

    编辑:我刚刚在bs-jsons README 中添加了一条注释,就在the example 下方,以解释这种语法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-30
      • 2012-03-22
      • 2017-10-09
      • 1970-01-01
      • 2011-08-09
      • 2010-09-19
      相关资源
      最近更新 更多