Proposal: Add Data.List.sortNub and sortNubBy
Pepe Iborra
mnislaih at gmail.com
Tue Mar 13 13:35:25 EDT 2007
On 13/03/2007, at 18:25, John Meacham wrote:
> once we have ordNub, we can create lots of RULES like the following
>
> {-# RULES "nub/ordNub" nub = ordNub :: [String] -> [String] #-}
> {-# RULES "nub/ordNub" nub = ordNub :: [Int] -> [Int] #-}
> {-# RULES "nub/ordNub" nub = ordNub :: [Integer] -> [Integer] #-}
>
> actually, we probably want one that uses IntMap for ints. it is
> signifigantly faster.
very nice idea!
> I don't suppose there is a way to match a RULE to a class
> constraint? I
> don't see how it would be implemented in any easy way since classes
> get
> desugared away pretty early... but it would be an interesting
> feature..
>
> {-# RULES "nub/ordNub" forall (a::*) . Ord a => nub = ordNub :: [a]
> -> [a] #-}
> or something...
I think yes, the right syntax would be something like:
> {-# RULES "nub/ordNub" forall (x::Ord a => a). nub x = ordNub x #-}
But hopefully someone else will confirm.
Also, what happens if the general Ord rule is added. Is it possible
to convince GHC to use the more specific rule for Int before the
general one?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/libraries/attachments/20070313/00f56423/attachment.htm
More information about the Libraries
mailing list