plow-technologies / inferno

A statically-typed functional scripting language
MIT License
4 stars 1 forks source link

Add array indexing and pattern matching #55

Closed siddharth-krishna closed 1 year ago

siddharth-krishna commented 1 year ago

This PR adds support for array indexing [1, 2, 3] !! 2 == Array.get [1, 2, 3] 2 == 3 and array pattern matching:

fun a -> match a with { | [] -> 0 | [x] -> 1 | [_, y] -> 2 | _ -> 3 }

Currently we only allow literal patterns like [x, _, ...], but no cons-style patterns like Haskell's x : xs. This means you must have a final | _ -> ... or | a -> ... pattern in order for the pattern match to be exhaustive.

siddharth-krishna commented 1 year ago

Thanks @ngua -- I've done as you suggested, and also added a logging message as discussed with Scott so that we can monitor if people are doing a lot of slow random access, and if so we can move to using Vector in a future PR.