type List is null | { int data, List next }
function len(List l) -> (int r):
//
int x = 0
// iterate to the end
while !(l is null):
l = l.next
x = x + 1
//
return x
This clarifies a pretty common pattern, where we don't want to explicitly name each bound of a union. Using !(l is null) is ugly and could be replaced with l isnt null.
Consider the following:
This clarifies a pretty common pattern, where we don't want to explicitly name each bound of a union. Using
!(l is null)
is ugly and could be replaced withl isnt null
.