#3399: Generalize the type of Data.List.{deleteBy, deleteFirstsBy}
------------------------------+---------------------------------------------
Reporter: iago | Owner:
Type: proposal | Status: new
Priority: normal | Milestone:
Component: libraries/base | Version: 6.10.4
Severity: normal | Resolution:
Keywords: | Testcase:
Os: Unknown/Multiple | Architecture: Unknown/Multiple
------------------------------+---------------------------------------------
Comment (by maeder):
Your proposal shows to me that there is another generalization of `delete`
(I think a better one than `deleteBy`), let's call it `deleteFirst` which
is a variant of `filter` with a negated predicate, that stops immediately
after one element has been removed.
{{{
deleteFirst :: (a -> Bool) -> [a] -> [a]
deleteFirst p l =
let (ft, rt) = break p l
in ft ++ drop 1 rt
delete :: Eq a => a -> [a] -> [a]
delete a = deleteFirst (== a)
}}}
(In the type signature of your above function `deleteFirstsBy` the
argument lists '[a]' and '[b]' should be swapped, because the second
argument is taken away from the first one.)
Maybe a better alternative for `deleteFirstsBy` would be `deleteFirsts`:
{{{
deleteFirsts :: [a -> Bool] -> [a] -> [a]
deleteFirsts fs l = foldr deleteFirst l fs
deleteFirstsBy :: (b -> a -> Bool) -> [a] -> [b] -> [a]
deleteFirstsBy eq l r = deleteFirsts (map eq r) l
}}}
But, since hardly anybody wants to touch Data.List, I would vote for
closing this ticket
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/3399#comment:2>
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