ensures that implementation details do not leak. For example, since f is pure it cannot be used to determine in what order the elements of the set are traversed. If f was impure such details could leak, e.g. by passing a function that also prints the current element, revealing the internal element order inside the set. A higher-order function can also require that a function is impure. For example, the definition of List.foreach requires that its function argument f is impure: // The syntax a ~> Unit is short-hand for a -> Unit & Impure def foreach(f: a ~> Unit, xs: List[a]): Unit & Impure The requirement that f must be impure ensures that the code makes sense: It would be meaningless to call List.foreach with a pure function since it always returns Unit. The type and effect is sound, but not complete. That is, if a function is pure then it cannot cause an effect, whereas if a function is impure then it may, but not necessarily, cause an effect. For example, the following expression is impure even though it cannot produce an effect at run-time: if (1 == 2) Console.printLine("Hello World!") else () A higher-order function can also be effect polymorphic: its effect(s) can depend on its argument(s). For example, the standard library definition of List.map is effect polymorphic: def map(f: a -> b & e, xs: List[a]): List[b] & e The List.map function takes a function f from elements of type a to b with effect e. The effect of the map function is itself e. Consequently, if List.map is invoked with a pure function then the entire expression is pure whereas if it is invoked with an impure function then the entire expression is impure. It is effect polymorphic. A higher-order function that takes multiple function arguments may combine their effects. For example, the standard library definition of forward function composition >> is pure if both its function arguments are pure: def >>(f: a -> b & e1, g: b -> c & e2): a -> c & (e1 and e2) = x -> g(f(x)) The type and effect signature can be understood as follows: The >> function takes two function arguments: f with effect e1 and g with effect e2. The effect of >> is effect polymorphic in the conjunction of e1 and e2. If both are pure (their effect is true) then the overall