Proposal #2629: Data.List: Replace nub; add nubOrd, nubInt,
nubWith
apfelmus
apfelmus at quantentunnel.de
Mon Sep 29 12:40:39 EDT 2008
Alexander Dunlap wrote:
>
> This seems like a good idea but it's kind of strange to have three
> different exposed versions of nub. Would it be possible to hide them,
> hide the StopList typeclass and use {-# RULES #-} pragmas to use the
> faster versions when possible?
I don't think that using RULES pragmas is a good solution to the problem.
Instead, there's an old-fashioned way to use the name nub for all
cases: make it a member of the Eq typeclass!
class Eq a where
(==) :: a -> a -> Bool
(/=) :: a -> a -> Bool
nub :: [a] -> [a]
nub = -- default definition
Now, nub can be specialized at will.
Changing the default definition of nub to use Set if we have an Ord
class is tricky, though. Basically, we would need this proposal:
http://www.haskell.org/haskellwiki/Class_system_extension_proposal#Allowing_superclass_methods_to_be_overridden_in_derived_classes
Does it have a formal definition yet and guarantees that it works? In
any case, consider nub to be another example for the usefulness of
this proposal.
Regards,
apfelmus
More information about the Libraries
mailing list