Next: , Previous: Purity annotations on higher-order types, Up: Higher-order impurity   [Contents]


16.8.2 Purity annotations on lambda expressions

Purity annotations are required on lambda expressions that call semipure or impure code. Lambda expressions can be declared as ‘semipure’ or ‘impure’ by including such an annotation before the ‘pred’ or ‘func’ identifier in the lambda expression. Such lambda expressions have the corresponding ‘semipure’ or ‘impure’ higher-order type. For example, the expression

(impure func(X) = Y :- semipure get_max(Y), impure set_max(X))

is an example of an impure function lambda expression with type ‘(impure func(int) = int)’, and the expression

(impure pred(X::in, Y::out) is det :-
    semipure get_max(Y),
    impure set_max(X))

is an example of an impure predicate lambda expression with type ‘impure pred(int, int)’.