Next: , Up: Higher-order impurity   [Contents]

15.8.1 Purity annotations on higher-order types

Ordinary higher-order types, such as ‘pred(T1, T2)’ and ‘func(T1, T2) = T’, represent only pure predicates or pure functions. But for each ordinary higher-order type Foo, there are two corresponding types ‘semipure Foo’ and ‘impure Foo’. These types can be used for higher-order code that needs to manipulate impure or semipure procedures. For example the type ‘impure func(int) = int’ represents impure functions from int to int.

There are no implicit conversions and no subtyping relationship between ordinary higher-order types and the corresponding impure or semipure higher-order types. However, a value of an ordinary higher-order type can be explicitly “converted” to a value of an impure (or semipure) higher-order type by wrapping it in an impure (or semipure) lambda expression that just calls the pure higher-order term.