Next: , Up: Type specialization   [Contents]


19.2.1 Syntax and semantics of type specialization pragmas

A declaration of the form

:- pragma type_spec(Name/Arity, Subst).
:- pragma type_spec(Name(Modes), Subst).

suggests to the compiler that a specialized version of predicate(s) or function(s) with name Name and arity Arity should be created with the type substitution given by Subst applied to the argument types. The second form of the declaration only suggests specialization of the specified mode of the predicate or function.

The substitution is written as a conjunction of bindings of the form ‘TypeVar = Type, for example ‘K = int or ‘(K = int, V = list(int)).

The declarations

:- pred map.lookup(map(K, V), K, V).
:- pragma type_spec(map.lookup/3, K = int).

give a hint to the compiler that a version of ‘map.lookup/3’ should be created for integer keys.

Implementations are free to ignore ‘pragma type_spec’ declarations. Implementations are also free to perform type specialization even in the absence of any ‘pragma type_spec’ declarations.