#2406: Data.List.sortFun
--------------------------------+-------------------------------------------
    Reporter:  lpsmith          |       Owner:                
        Type:  feature request  |      Status:  new           
    Priority:  normal           |   Component:  libraries/base
     Version:  6.8.3            |    Severity:  normal        
    Keywords:                   |    Testcase:                
Architecture:  Unknown          |          Os:  Unknown       
--------------------------------+-------------------------------------------
 I've found these two functions useful often enough to suggest adding it to
 Data.List:

 {{{
 {-# RULES
        "sortFun/fst"   forall .  sortFun fst = sortFun' fst
        "sortFun/snd"   forall .  sortFun snd = sortFun' snd
  #-}

 sortFun :: Ord b => (a -> b) -> [a] -> [a]
 sortFun f  = map snd . sortFun' fst .  map (\x -> (f x, x))

 sortFun' :: Ord b => (a -> b) -> [a] -> [a]
 sortFun' f = Data.List.sortBy (\x y -> compare (f x) (f y))
 }}}

 I am not terribly fond of the name "sortFun".   If anybody has a better
 suggestion...

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2406>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to