[英]Records in PureScript
I don't quite understand why this works: 我不太明白为什么这样做:
module Records where
type Element e = { element :: String, label :: String | e }
type Sel = ( value :: Number, values :: [Number] )
type Select = Element Sel
while this says Cannot unify # * with *
. 虽然这说
Cannot unify # * with *
。
module Records where
type Element e = { element :: String, label :: String | e }
type Sel = { value :: Number, values :: [Number] }
type Select = Element Sel
(Note the '()' around the right hand side of Sel instead of the '{}'.) (注意Sel右侧的'()'而不是'{}'。)
I've read here https://leanpub.com/purescript/read#leanpub-auto-objects-and-rows that forall r. { firstName :: String, lastName :: String | r }
我在这里阅读了https://leanpub.com/purescript/read#leanpub-auto-objects-and-rows
forall r. { firstName :: String, lastName :: String | r }
forall r. { firstName :: String, lastName :: String | r }
forall r. { firstName :: String, lastName :: String | r }
desugars to forall r. Object (firstName :: String, lastName :: String | r)
forall r. { firstName :: String, lastName :: String | r }
desugars to forall r. Object (firstName :: String, lastName :: String | r)
forall r. Object (firstName :: String, lastName :: String | r)
I'm still a bit confused, why you can't use the record-sugar for extending records. 我仍然有点困惑,为什么你不能使用唱片糖来扩展记录。
The Object
type constructor is parameterized by a row of types . Object
类型构造函数由一行类型参数化 。 In kind notation, Object
has kind # * -> *
. 实物符号,
Object
有类 # * -> *
。 That is, it takes a row of types to a type. 也就是说,它需要一种类型的类型。
( value :: Number, values :: [Number] )
denotes a row of types (something of kind # *
), so it can be passed to Object
to construct a type, namely ( value :: Number, values :: [Number] )
表示一行类型 (某种类型# *
),因此可以传递给Object
来构造一个类型,即
Object ( value :: Number, values :: [Number] )
Note that { ... }
is just syntactic sugar for the Object type constructor, so this is the same as 请注意,
{ ... }
只是Object类型构造函数的语法糖,所以这与
{ value :: Number, values :: [Number] }
Both have kind *
, so it doesn't make sense to pass this thing as an argument to Element
, since the type variable e
in Element
has kind # *
. 两者都有那种
*
,所以它没有任何意义通过这件事情作为参数传递给Element
,因为类型变量e
的Element
有种# *
。
Put another way, Element Sel
in your second example unrolls to 换句话说,你的第二个例子中的
Element Sel
展开了
{ element :: String, label :: String | { value :: Number, values :: [Number] } }
which desugars to 不好意思
Object (element :: String, label :: String | Object (value :: Number, values :: [Number]) )
which fails to kind-check due to the thing of kind *
in the tail of the outer row. 由于外排尾部的那种东西
*
未能进行检查。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.