coproduct 与 sum 类型相同吗?
Is coproduct the same as sum types?
我在看 this lecture from Bartosz Milewski 他在解释余积和求和类型。
在讲座中,他从一个转到另一个。
余积与求和类型相同吗?
基本上是的。副产品原则上更通用,但这不一定
就 Haskell 而言,你一定很关心。
余积不是求和类型的类别示例† 是 category of vector spaces,箭头为线性映射。在此类别中,不相交和类型没有多大意义,因为它们会给你两个不同的零向量元素。
相反,product 类型(在线性代数中称为 direct sums,但在实现方面它们是元组,而不是替代项)是一个此类别的副产品:
type LFun v w = v -> w
initial :: VectorSpace w => LFun () w
initial () = zeroV
(+++) :: VectorSpace w => LFun u w -> LFun v w -> LFun (u,v) w
(f+++g) (u,v) = f u ^+^ g v
(此类别的标准产品是主题相似的 SubHask
库中的 tensor product. Though it's possible to ignore this and use ordinary tuples as the product type, i.e. the actual coproducts. I think this has to do with the fact that any Hilbert space is isomorphic to its dual space. In my constrained-categories
/linearmap-category
library, the products are tuples, whereas Mike Izbicki has not done this。)参见 Derek Elkins ' 评论。
†我理解数据意义上的“求和类型”,即具有标记联合结构的代数数据类型。
我在看 this lecture from Bartosz Milewski 他在解释余积和求和类型。
在讲座中,他从一个转到另一个。
余积与求和类型相同吗?
基本上是的。副产品原则上更通用,但这不一定 就 Haskell 而言,你一定很关心。
余积不是求和类型的类别示例† 是 category of vector spaces,箭头为线性映射。在此类别中,不相交和类型没有多大意义,因为它们会给你两个不同的零向量元素。
相反,product 类型(在线性代数中称为 direct sums,但在实现方面它们是元组,而不是替代项)是一个此类别的副产品:
type LFun v w = v -> w
initial :: VectorSpace w => LFun () w
initial () = zeroV
(+++) :: VectorSpace w => LFun u w -> LFun v w -> LFun (u,v) w
(f+++g) (u,v) = f u ^+^ g v
(此类别的标准产品是主题相似的 参见 Derek Elkins ' 评论。SubHask
库中的 tensor product. Though it's possible to ignore this and use ordinary tuples as the product type, i.e. the actual coproducts. I think this has to do with the fact that any Hilbert space is isomorphic to its dual space. In my constrained-categories
/linearmap-category
library, the products are tuples, whereas Mike Izbicki has not done this。)
†我理解数据意义上的“求和类型”,即具有标记联合结构的代数数据类型。