The expression if
Ec
then
Et
else
Ef
is a conditional expression.
It executes as follows:
The type of if
Ec
then
Et
else
Ef
is the join of the types of Et
and Ef
.
Additionally, Ec
must have type Boolean
.
{- Binary search in a sorted array. -} def binary_search(x,a) = def searchIn(lo, hi) = if (lo >= hi) then false else ( val mid = (lo+hi) / 2 val y = a(mid)? if (x = y) then true else if (x <: y) then searchIn(lo, mid) else searchIn(mid+1, hi) ) searchIn(0, a.length?) val a = Array(15) for(0, 15) >i> a(i) := 2*i >> stop ; binary_search(19, a) | binary_search(22, a) {- OUTPUT:PERMUTABLE true false -}