Whiley / RFCs

Request for Comment (RFC) proposals for substantial changes to the Whiley language.
3 stars 2 forks source link

Is and Isnt Syntax #90

Open DavePearce opened 3 years ago

DavePearce commented 3 years ago

Consider the following:

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.