Idea is to enable dispatch of Julia
methods depending not only on the type (including type parameters), but on special properties of argument types.
As we want to extend the method dispatching system, which is based on type hierarchies, the mentioned properties are expressed as function calls with the type as single argument. The return value of the function must be an abstract or concrete type by itself.
The syntax of the where clause is extended by allowing the type variable to be replaced by a function call to the variable. It may be restricted by upper - and lower bounds.
function foo1(x::T) where {basetype(T)<:SparseMatrixCSC}
end
Symmetric{T, P} where {T,basetype(P)<:Array}
A where clause of the form where L<:func(T)<:U
restricts the lhs to all types T
, for which method call func(T)
returns a value. to arguments of type Type{T}
, and for which L<:func(T)<:U
is true. L
and U
as usually default to Union{}
respectively Any
.
The used function must be defined before it can be used in a where clause. Its evaluation must be possible at complile time.
Just read this discourse request-type-functions-for-parametric-dispatch, which kind of discouraged me.