Empty array primitives
Motivation
Currently, there is no way to create an empty array without a value of the element type, since the only primitive to create a new array is newArray#
, which requires an element. For lifted element types, this is no problem, since you can use a bottom as a dummy element, but that doesn't work for unlifted types.
Proposal
I propose adding two new primitives:
emptyArray# :: forall {l :: Levity} (a :: TYPE (BoxedRep l)). Array# a
emptSmallyArray# :: forall {l :: Levity} (a :: TYPE (BoxedRep l)). SmallArray# a
This should be enough, since you can also use them to create empty mutable arrays (by using thawArray#
/thawSmallArray#
). One could also go the other way round, adding primitives to create mutable empty arrays instead, but I'd argue that empty immutable arrays are more common (e.g. primitive
has emptyArray
, but no emptyMutableArray
). It might still be beneficial to additionally add primitives for empty mutable arrays though.