总和和积之外是否存在代数数据类型? [英] Are there algebraic data types outside of sum and product?
问题描述
在大多数定义中,Haskell或Scala中常见或基本的代数数据类型为求和与乘积.示例: 1 ,代数数据类型是求和和积,也许是为了简化.>
但是,这些定义给人的印象是其他代数数据类型也是可能的,总和和乘积只是描述元素选择或组合的最有用的方法.
鉴于基本代数中存在减法,除法和整数运算,是否可以在编程中实现其他替代代数类型的实现,但它们没有用吗?
是否有任何编程语言都实现了不是求和和乘积类型的代数数据类型?
代数"来自范畴论.每个代数数据类型都是函子的初始代数.因此,原则上您可以用代数的方式调用函子中的任何东西,我认为这是一个很大的类.
将代数"解释为高中代数"(我并不是要屈尊,这只是指数对象,并且使用后一种表示法.有趣的是,看看是否可以证明定律 By most definitons the common or basic algebraic data types in Haskell or Scala are sum and product. Examples: 1, 2. Sometimes a definition just says algebraic data types are sum and product, perhaps for simplicity. However, the definitions leave an impression that other algebraic data types are possible, and sum and product are just the most useful to describe selection or combination of elements. Given there are subtraction, division, raising to an integer power operations in a basic algebra - is it correct some implementation of other alternative algebraic types in programming is possible, but they are not useful? Do any programming languages have algebraic data types implemented that are not sum and product types? "Algebraic" comes from category theory. Every algebraic data type is an initial algebra of a functor. So you could in principle call anything that comes from a functor in this way algebraic, and I think it's quite a large class. Interpreting "algebraic" to mean "high-school algebra" (I don't mean to be condescending, that's just how we refer to it) as you have, there are some nice analogies. 这篇关于总和和积之外是否存在代数数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! C A + B = C A ×C B
,方法是在相应类型之间写一个双射.
A -> B
is analogous to BA
. In category theory, when you consider a function ("morphism") as an object of a category, it's called an exponential object, and the latter notation is used. For fun, see if you can prove the law CA+B = CA × CB
by writing a bijection between the corresponding types.