ForAllType
ForAllType[x,type]
represents a type parameterized by x.
ForAllType[x,cond,type]
represents a type satisfying cond.
ForAllType[{x1,x1,…},cond,type]
represents a type with multiple parameters.
Details

- ForAllType does not evaluate on its own but can be used inside functions that accept types including Typed, FunctionDeclaration, etc.
- ForAllType is used to specify the type of polymorphic functions.
- Possible forms for cond include:
-
Element[x,"absType"] assert that x is a member of an abstract type TypeEvaluate[…] run an arbitrary function - cond can take the form Element[xi,"absType"], where "absType" is an abstract type. »
- TypeEvaluate can be used in cond. »
- cond can be given as a list of conditions.
Examples
open allclose allBasic Examples (1)
Represent the type of a function that accepts a list of objects with type t and returns a single object with type t:
Represent a declaration of a polymorphic function with this type:
Compile a program using the polymorphic function:
Compile another program using the polymorphic function with a different concrete type:
Scope (4)
Represent the type of a function that takes any packed array and returns an array of higher rank:
Declare a function with that type and call that function on a concrete example:
Represent the type of a function that is polymorphic in its output:
Compile a function with the type:
Represent the type of a function that only accepts integers:
Represent a function with the type:
Compile a program that calls the function on an integer type:
Compilation fails when the function is given a noninteger type:

Represent the type of a function that only accepts packed arrays with a rank less than 3:
Represent a function with the type:
Compile a program that applies the function to a packed array with rank 2:
Compilation fails when the inputted packed array has rank 3:

Text
Wolfram Research (2022), ForAllType, Wolfram Language function, https://reference.wolfram.com/language/ref/ForAllType.html.
CMS
Wolfram Language. 2022. "ForAllType." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/ForAllType.html.
APA
Wolfram Language. (2022). ForAllType. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ForAllType.html