arithmetic-typing 0.3.0

Hindley-Milner type inference for arithmetic expressions.
Documentation
//! Version of the quicksort sample from the eval README
//! with a couple of necessary type annotations.

quick_sort = |xs, quick_sort: (_, any) -> [Num]| {
    // `any` is necessary because `quick_sort` is recursive otherwise.

    if(xs as [Num] == (), || () as [Num], || {
        (pivot, ...rest) = xs as any;
        lesser_part = rest.filter(|x| x < pivot).quick_sort(quick_sort);
        greater_part = rest.filter(|x| x >= pivot).quick_sort(quick_sort);
        lesser_part.push(pivot).merge(greater_part)
    })()
};

sort = |xs| xs.quick_sort(quick_sort);

assert_eq((1, 7, -3, 2, -1, 4, 2).sort(), (-3, -1, 1, 2, 2, 4, 7));

xs = array(1000, |_| rand_num(0, 100)).sort();
{ sorted } = xs.fold(
    #{ prev: -1, sorted: true },
    |{ prev, sorted }, x| #{
        prev: x,
        sorted: sorted && prev <= x
    },
);
assert(sorted);