[Git][ghc/ghc][master] Improved documentation for the Data.OldList.nub function

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Thu May 4 19:01:44 UTC 2023



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
b3226616 by Andrei Borzenkov at 2023-05-04T15:01:25-04:00
Improved documentation for the Data.OldList.nub function

There was recomentation to use map head . group . sort instead of nub
function, but containers library has more suitable and efficient
analogue

- - - - -


1 changed file:

- libraries/base/Data/OldList.hs


Changes:

=====================================
libraries/base/Data/OldList.hs
=====================================
@@ -448,10 +448,16 @@ isInfixOf needle haystack = any (isPrefixOf needle) (tails haystack)
 -- >>> nub [1,2,3,4,3,2,1,2,4,3,5]
 -- [1,2,3,4,5]
 --
--- If the order of outputs does not matter and there exists @instance Ord a@,
--- it's faster to use
+-- If there exists @instance Ord a@, it's faster to use `nubOrd` from the `containers` package
+-- ([link to the latest online documentation](https://hackage.haskell.org/package/containers/docs/Data-Containers-ListUtils.html#v:nubOrd)),
+-- which takes only \(\mathcal{O}(n \log d)\) time where `d` is the number of
+-- distinct elements in the list.
+--
+-- Another approach to speed up 'nub' is to use
 -- 'map' @Data.List.NonEmpty.@'Data.List.NonEmpty.head' . @Data.List.NonEmpty.@'Data.List.NonEmpty.group' . 'sort',
--- which takes only \(\mathcal{O}(n \log n)\) time.
+-- which takes \(\mathcal{O}(n \log n)\) time, requires @instance Ord a@ and doesn't
+-- preserve the order.
+
 --
 nub                     :: (Eq a) => [a] -> [a]
 nub                     =  nubBy (==)



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b3226616beaa8cd4d3289b8a9d4bb0a9b8936f8e

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b3226616beaa8cd4d3289b8a9d4bb0a9b8936f8e
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230504/780a56e6/attachment-0001.html>


More information about the ghc-commits mailing list