[Haskell-cafe] ordNub

Joey Adams joeyadams3.14159 at gmail.com
Mon Jul 15 03:54:08 CEST 2013


On Sun, Jul 14, 2013 at 7:31 AM, Clark Gaebel <cgaebel at uwaterloo.ca> wrote:

> Similarly, I've always used:
>
> import qualified Data.HashSet as S
>
> nub :: Hashable a => [a] -> [a]
> nub = S.toList . S.fromList
>
> And i can't think of any type which i can't write a Hashable instance, so
> this is extremely practical.
>
This won't yield results lazily (e.g. nub (repeat 'x') = _|_ instead of 'x'
: _|_), but Niklas' ordNub will.  His ordNub can be translated directly to
HashSet and still have the stability and laziness properties.

A difficulty with putting ordNub in Data.List is that it depends on
containers, which is outside of the base package.  Some options:

 * Move the implementation of Set to base.

 * Implement a lean version of Set in base that only provides 'insert' and
'member'.

 * Define ordNub in Data.Set instead.

Adding a Hashable-based nub to base would be even more problematic, since
you'd need Hashable in base.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130714/3c9a7901/attachment.htm>


More information about the Haskell-Cafe mailing list