Proposal #1464: add dropPrefix to Data.List

Simon Marlow simonmarhaskell at gmail.com
Mon Jul 2 07:09:05 EDT 2007


Ian Lynagh wrote:
> 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
> functions.
> 
> 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.

FWIW, the version in GHC is called "matchPrefixMaybe".

Cheers,
	Simon


More information about the Libraries mailing list