Proposal #1464: add dropPrefix to Data.List

Ian Lynagh igloo at
Fri Jun 29 20:35:28 EDT 2007

On Wed, Jun 27, 2007 at 02:26:05AM +0100, Ian Lynagh wrote:
>     dropPrefix :: Eq a => [a] -> [a] -> Maybe [a]
>     dropPrefix [] ys = Just ys
>     dropPrefix (x:xs) (y:ys)
>      | x == y = dropPrefix xs ys
>     dropPrefix _ _ = Nothing

Summary so far:

Something should go in.

The Maybe version seems more popular than generalisations, especially
because Data.List already uses Maybe for the same sort of task in other

I don't think I tend to want the extra generality of Conor's leftFactor,
and no-one else has "me-too"ed it either. Also, writing "(_, ([], zs))"
rather than "Just zs" would be a bit cumbersome, so I think I'd like
dropPrefix even if we also had leftFactor.

Thus, based on the feedback thus far, I think dropPrefix as defined
above should go in, with 'generalising Data.List functions' and
'implementing "leftFactor"' being left to possible future proposals.

On names, Stefan wrote "I'd name it differently---not sure how", as the
existing drop* functions always returns a list. Other names I considered
were stripPrefix and removePrefix, but I can't think of any commonality
between those names and existing functions off the top of my head.


More information about the Libraries mailing list