diff options
author | Artyom <yom@artyom.me> | 2016-12-23 14:36:55 -0500 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2016-12-23 16:44:48 -0500 |
commit | 94d2cce6742235d36efb71cf704acd1327a68481 (patch) | |
tree | 75492511b8822c09a4a33fdb99b8449d6d1a3680 /libraries/base | |
parent | 1b06231ea9063d753a2755a7fc4aeadcc2fc58b9 (diff) | |
download | haskell-94d2cce6742235d36efb71cf704acd1327a68481.tar.gz |
base: Override Foldable.{toList,length} for NonEmpty
Previously the Foldable instance for NonEmpty used default
implementations for toList and length.
I assume that the existing implementations
(i.e. Data.List.NonEmpty.{toList,length}) are better than
the default ones, and frankly can't see a good reason why they
might be worse – but if they are, instead of this commit
we'd have to switch Data.List.NonEmpty.{toList,length}
to use Foldable.
Reviewers: austin, hvr, bgamari
Reviewed By: bgamari
Subscribers: int-index, thomie
Differential Revision: https://phabricator.haskell.org/D2882
Diffstat (limited to 'libraries/base')
-rw-r--r-- | libraries/base/Data/List/NonEmpty.hs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/libraries/base/Data/List/NonEmpty.hs b/libraries/base/Data/List/NonEmpty.hs index b4da532b1d..c5f6169024 100644 --- a/libraries/base/Data/List/NonEmpty.hs +++ b/libraries/base/Data/List/NonEmpty.hs @@ -228,6 +228,8 @@ instance Foldable NonEmpty where foldl1 f ~(a :| as) = foldl f a as foldMap f ~(a :| as) = f a `mappend` foldMap f as fold ~(m :| ms) = m `mappend` fold ms + length = length + toList = toList -- | Extract the first element of the stream. head :: NonEmpty a -> a @@ -507,8 +509,8 @@ nubBy eq (a :| as) = a :| List.nubBy eq (List.filter (\b -> not (eq a b)) as) -- > transpose . transpose /= id transpose :: NonEmpty (NonEmpty a) -> NonEmpty (NonEmpty a) transpose = fmap fromList - . fromList . List.transpose . Foldable.toList - . fmap Foldable.toList + . fromList . List.transpose . toList + . fmap toList -- | 'sortBy' for 'NonEmpty', behaves the same as 'Data.List.sortBy' sortBy :: (a -> a -> Ordering) -> NonEmpty a -> NonEmpty a |