Open vrom911 opened 3 years ago
@vrom911 Awesome idea! I think the Slist.NonEmpty
module would be a great place for this data type 🙂
The :|
constructor is taken by the NonEmpty
, unfortunatately. But maybe we don't need fancy operators. I see two options: introduce something similar to Cons
for ordinary lists, e.g. "non-empty" cons:
data SNonEmpty a = NCons a (Slist a)
Or maybe even use a record:
data SNonEmpty a = SNonEmpty
{ sNonEmptyHead :: a
, sNonEmptyTail :: Slist a
}
But I think we want to provide ergonomic pattern-matching, as probably most of the time we want to pattern-match like this:
case snelist of
NCons x xs -> ...
Create another data structure similar to
NonEmpty
implemented through the ordinary list. Something like this: