Skip to content

Type constructor

在阅读wikipedia Covariance and contravariance (computer science) 时,其中有很多关于 type constructor的描述,比如:

Depending on the variance of the type constructor, the subtyping relation of the simple types may be either preserved, reversed, or ignored for the respective complex types.

A programming language designer will consider variance when devising(设计) typing rules for language features such as arrays, inheritance, and generic datatypes. By making type constructors covariant or contravariant instead of invariant, more programs will be accepted as well-typed.

通过 wikipedia Covariance and contravariance (computer science) 中的内容,我对 Type constructor 的直观认知是:

1) 它让programmer基于现有 type 来构造新的 type

2) 通过type constructor,programmer可以构建新的type,从而扩展programming language的现有的type。

现代programming language普遍支持各种各样的type constructor,这是programmer需要了解的,并且与type constructor的variance属性是非常重要的内容,需要programmer进行了解。本章将对type constructor以及它的variance属性进行深入分析。

Wikipedia Type constructor

In the area of mathematical logic and computer science known as type theory, a type constructor is a feature of a typed formal language that builds new types from old ones. Typical type constructors encountered are product types, function types, power types and list types. Basic types are considered nullary (0元)type constructors. New types can be defined by recursively composing type constructors.

See also