阅读维基百科对 polymorphism 的定义,我提出一个问题:
Haskell 支持哪些多态类型,哪些不支持?
看起来维基百科不包含一些多态类型的描述,如 Levity Polymorphism这对我来说是新的,并在 Haskell 中得到支持。
我想知道 Haskell Polymorphism 的扩展列表接着举例深入探讨。
看起来主要的两个是:
最佳答案
在当前的 Haskell 中,至少有四件事可以算作多态性:
在 Haskell 的 future 版本中可能会引入另外两种类型的多态性:
有人可能会问,为什么会有这么多的多态性? Haskell 中似乎存在一个总体设计原则,即只要可以通过子类型化或多态性解决某些挑战,就应该首选多态性。
例如,来自 levity 多态性论文:
We can now present the main idea of the paper: replace sub-kinding with kind polymorphism.
从介绍匹配性多态性的论文中:
At first you might think that we need subtyping, but instead we turn to polymorphism
来自线性 Haskell 论文:
The lack of subtyping is a deliberate choice in our design
西蒙·佩顿·琼斯本人在 47:00 上指出了这一点在 this talk .
Whenever you want to use subtyping, use polymorphism instead.
关于haskell - Haskell 支持哪些多态类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56326016/