Proposal #1464: add dropPrefix to Data.List

Chris Smith cdsmith at twu.net
Tue Jun 26 22:07:30 EDT 2007


Ian Lynagh wrote:
> The definition is:
>
>    dropPrefix :: Eq a => [a] -> [a] -> Maybe [a]
>    dropPrefix [] ys = Just ys
>    dropPrefix (x:xs) (y:ys)
>     | x == y = dropPrefix xs ys
>    dropPrefix _ _ = Nothing

Hmm.  That would replace a function I write today if only it were:

    dropPrefix :: (Monad m, Eq a) => [a] -> [a] -> m [a]
    dropPrefix [] ys = return ys
    dropPrefix (x:xs) (y:ys)
     | x == y = dropPrefix xs ys
    dropPrefix _ _ = fail "parse error"

I don't know if you'd consider this desire common enough to do the standard 
library that way, but I noticed this, so I figured I'd mention something.

-- 
Chris Smith



More information about the Libraries mailing list