总和和积之外是否存在代数数据类型? [英] Are there algebraic data types outside of sum and product?

查看:68
本文介绍了总和和积之外是否存在代数数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在大多数定义中,Haskell或Scala中常见或基本的代数数据类型为求和与乘积.示例: 1 代数数据类型是求和和积,也许是为了简化.

但是,这些定义给人的印象是其他代数数据类型也是可能的,总和和乘积只是描述元素选择或组合的最有用的方法.

鉴于基本代数中存在减法,除法和整数运算,是否可以在编程中实现其他替代代数类型的实现,但它们没有用吗?

是否有任何编程语言都实现了不是求和和乘积类型的代数数据类型?

解决方案

代数"来自范畴论.每个代数数据类型都是函子的初始代数.因此,原则上您可以用代数的方式调用函子中的任何东西,我认为这是一个很大的类.

将代数"解释为高中代数"(我并不是要屈尊,这只是指数对象,并且使用后一种表示法.有趣的是,看看是否可以证明定律 C A + B = C A ×C B ,方法是在相应类型之间写一个双射.

  • 除法类似于商类型,这是一个引人入胜的研究领域,涉及同伦类型理论一样热门和流行.商与除的类比不如乘积的产品类型强,因为必须用等价关系除.
  • 以这样的速度,您可能希望减法与之相像,但是a,我不知道.丹·皮波尼(Dan Piponi)通过反对角线对其进行了一些探索,但这远非一般的比喻.
  • 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.

    • Arbitrary powers, not just integer powers, are closely analogous to function types, that is, 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.
    • Division is analogous to quotient types, which is a fascinating area of research that reaches into things as hott and trendy as homotopy type theory. The analogy of quotients to division is not as strong as product types with multiplication, as you have to divide by an equivalence relation.
    • At this rate, you would expect subtraction to have some beautiful analogy to go with it, but alas I know of none. Dan Piponi has explored it a little through the antidiagonal, but it is far from a general analogy.

    这篇关于总和和积之外是否存在代数数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆