Why isn’t the "non-empty list" type in the Haskell core libraries?

This type may be

data NonEmptyList a = NEL a [a] 

The functions head , tail and others will become methods of the newly created class of type Listable . Some functions can already fit into an existing class type (cards / folds / walks / monads).

Why is this type not included in the Haskell standard library?

+5
source share
3 answers

The list of packages that define this type is pretty messy in itself: there are at least six of them:

The Haskell Wiki has a whole page about non-empty lists.

Your question: why are non-empty lists not in the base package more difficult to answer. But the type is an instance of many useful classes from the database ( Foldable , Zip ), so the mechanism for their use already exists, and for this you need only a small number of instance definitions.

+9
source

Type really exists.

You need to import

 Data.List.NonEmpty 

Additional information: http://hackage.haskell.org/package/semigroups-0.16.0.1/docs/Data-List-NonEmpty.html

+7
source

Starting with GHC 8.0.1, base now has the NonEmpty list NonEmpty in Data.List.NonEmpty :

https://hackage.haskell.org/package/base-4.9.0.0/docs/Data-List-NonEmpty.html

+6
source

Source: https://habr.com/ru/post/1210066/


All Articles