Is there a way to pattern match arrays of an unknown length in PureScript? As an example, here's how I would do it with a List
in Haskell:
addFirstTwo :: (Num a) => [a] -> a
addFirstTwo (x:y:_) = x + y
I tried something similar (using Array a
instead of [a]
) in PureScript, but got the following error:
Operator Data.Array.(:) cannot be used in a pattern as it is an alias for function Data.Array.cons. Only aliases for data constructors may be used in patterns.
I know I can use List
s in PureScript instead of Arrays, but I'd like to pattern match with arrays. I didn't see how to do this after reading the Array pattern matching section of PureScript by Example.