一阶参数多态性和一阶函数
我正在阅读论文 Generics of a Higher Kind
,第一句话是
使用 Java 5 和 C# 2.0,一阶 引入参数多态性 在主流的面向对象中 名称下的编程语言 泛型。
我不知道什么是一阶参数多态性,我也不太明白什么是一阶函数,我知道高阶函数是接受一个函数并返回一个函数的函数,但我不知道什么是零阶-阶函数,一阶函数。 我从这里看到了一个解释,如下所示:< br>
f-> g 是零阶
f -> g-> h 是一阶
f -> g-> h->我 是二阶
等等
谁能为我解释这两个术语?
I am reading the paper Generics of a Higher Kind
, the first sentence is
With Java 5 and C# 2.0, first-order
parametric polymorphism was introduced
in mainstream object-oriented
programming languages under the name
of generics.
I don't know what's first-order parametric polymorphism, I also do not quite understand what's first-order function, I know high-order function is function that takes a function and return a function, but I don't know what's zeroth-order function, first-order function.
I saw an explanation from here, like this:
f -> g is zeroth order
f -> g ->
h is first order
f -> g -> h -> i
is second order
Etc.
Can anyone explain these two terms for me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于高阶(又名更高种类)参数多态性,因此第一个值具有类型,如果您将参数类型视为类型函数(类型函数),那么类型现在具有类型,例如
IEnumerable< T>
是类型 * -> 的类型函数*,当你将一个类型应用到这个类型函数时,你会得到一个类型*。因此,通过将参数类型(类型构造函数)视为类型函数的观点,我们可以开始讨论高阶类型函数,这是一种可以接受/返回类型函数作为参数的类型函数。这被称为高级多态性,它是 Java 和 Java 等语言所缺乏的高度表达的类型系统功能。 C#。如果您了解 C++ 模板,那么通过模板模板参数(是的模板模板)对此类事物的支持有限但不一致且几乎无用。您可能想知道为什么拥有这样的功能会有用?它们允许人们表达更高层次的抽象和更通用的代码,例如 Monad 和 Monad。函子。标准 Haskell98 支持更高级的多态性。
对于您的一阶函数示例,首先您必须了解 lambda 演算中的所有函数仅采用一个参数,并且示例中的箭头实际上与右侧关联,因此这就是您实际拥有的:
f -> g 是零阶。
f-> (g -> h) 是一阶,函数返回一个函数。
f-> (g -> (h -> i)) 是二阶,函数返回一个函数,该函数返回一个函数。
同样的“仅一个参数”也适用于 type、kind、sorts(具有排序的种类)函数。
For higher-order (aka higher kinded) parametric polymorphism, so first values have a type, types have a kind now if you think of a parametric type as sort of a type function (function of types) so for example
IEnumerable<T>
is a type function of kind * -> *, when you apply a type to this type function you get a type of kind *. So with this view of parametric types (type constructors) as type functions we can start to talk about higher-order type functions, a type function which can take/return type functions as arguments. This is known as higher-kinded polymorphism and it is highly expressive type system feature lacking in languages such as Java & C#. If you know about C++ templates then there is a limited but inconsistant and almost useless support for such a thing via template template parameters (yes template template).You might wonder why would it be useful to have such a feature? well they allow one to express higher level abstractions and more generic code such as Monads & Functors. Standard Haskell98 supports higher-kinded polymorphism.
For your first-order function example, first you must understand that all functions in a lambda calculus only take one argument and the arrows in your example actually associates to the right so this is what you actually have:
f -> g is zeroth order.
f -> (g -> h) is first order, function returns a function.
f -> (g -> (h -> i)) is second order, function returns a function which returns a function.
The same 'one argument only' applies to type, kind, sorts (kinds having sorts) functions as well.