For example, Num a => a
.
I assumed they're just called "constrained types", but Googling didn't turn up many uses of that term so I'm curious to know if they go by some other name.
Constraints can be column level or table level. Column level constraints apply to a column, and table level constraints apply to the whole table. The following constraints are commonly used in SQL: NOT NULL - Ensures that a column cannot have a NULL value. UNIQUE - Ensures that all values in a column are different.
The where clause in a generic definition specifies constraints on the types that are used as arguments for type parameters in a generic type, method, delegate, or local function. Constraints can specify interfaces, base classes, or require a generic type to be a reference, value, or unmanaged type.
The three primary constraints that project managers should be familiar with are time, scope, and cost. These are frequently known as the triple constraints or the project management triangle.
A type constraint on a generic type parameter indicates a requirement that a type must fulfill in order to be accepted as a type argument for that type parameter. (For example, it might have to be a given class type or a subtype of that class type, or it might have to implement a given interface.)
Types with this particular kind of constraints are called "qualified types", and the feature itself sometimes "qualified polymorphism". I believe the terminology was originally introduced by Mark Jones' ESOP '92 paper.
Qualified types should not be confused with the more mainstream notion of "bounded polymorphism", on which generics in languages like Java are based. Bounded polymorphism essentially is the (rather complicated) combination of parametric polymorphism with subtyping, whereas qualified types get along without subtyping.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With