elm-nonempty-list
elm-nonempty-list copied to clipboard
Wouldn't it make more sense to call the main type NonEmptyList?
TLDR
I want to write:
import List.Nonempty exposing (NonEmptyList)
things : NonEmptyList Thing
Long explanation
Hey! Thanks for this useful package. I hope you won't find this too much of nitpicking. If you do, feel free to ignore the issue.
Maybe I'm missing something, but when I use this package I import it like this:
import List.Nonempty
Then if I want to annotate something I have to type:
things : List.Nonempty.Nonempty Thing
That's long and cumbersome. Alternatively I could expose the type:
import List.Nonempty exposing (Nonempty)
things : Nonempty Thing
But that's confusing. Now this annotation doesn't tell me what kind of collection is non-empty.
The current name of the type would only make sense if I would "merge" the import with the core List module, like this:
import List.Nonempty as List
things : List.Nonempty Thing
But that's not even possible because of clashing names (map, filter etc.). Also I wouldn't really want that, as non-empty list has different semantics.
So what I end up doing every time is:
import List.Nonempty
type alias NonEmptyList a =
List.Nonempty.Nonempty a
things : NonEmptyList Thing
So why shouldn't I be able to write it like below?
import List.Nonempty exposing (NonEmptyList)
things : NonEmptyList Thing
I can make a PR if you want. To avoid a breaking change we could start with aliasing the type, so old code would still work.
Does it make sense? Am I missing something?
I agree that "Nonempty List" is the most complete description. However, NonemptyList
is even longer and more cumbersome than Nonempty
, which is already cumbersome relative to List
because of the lack of syntax sugar for everything. So I want this prefix to be as short as possible, I even used NEList
for a while instead. In the elm world, I don't know of any other data type simply called Nonempty
. So anyone familiar with this package will immediately know what it is, and anyone who isn't (and can't tell by the usage that it's obviously a list) won't gain much from the additional word (it does not save you from having to check the docs on how it works, for example).