我正在尝试理解这个Elm结构:
type Item = Item { name : String, data : String }
- 它看起来像是一条记录,但它的行为非常不同。
- 它有助于定义递归数据模型。
- 与
type alias Item = {...}
不同,它不提供“构造函数”。 - 我在Elm语法指南中找不到它。
- 我无法弄清如何访问它的字段:
> item = Item { name = "abc", data = "def" }
Item { name = "abc", data = "def" } : Repl.Item
> item.name
-- TYPE MISMATCH --------------------------------------------- repl-temp-000.elm
`item` does not have a field named `name`.
6| item.name
^^^^^^^^^ The type of `item` is:
Item
Which does not contain a field named `name`.
- 这个结构叫什么?
- 如何访问其中包含的字段?