Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NonEmpty Slist #44

Open
vrom911 opened this issue Feb 9, 2021 · 1 comment
Open

NonEmpty Slist #44

vrom911 opened this issue Feb 9, 2021 · 1 comment
Labels

Comments

@vrom911
Copy link
Member

vrom911 commented Feb 9, 2021

Create another data structure similar to NonEmpty implemented through the ordinary list. Something like this:

data SNonEmpty a = a :| Slist a
@vrom911 vrom911 added the idea label Feb 9, 2021
@chshersh
Copy link
Contributor

chshersh commented Feb 9, 2021

@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 -> ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants