[Haskell-cafe] Separate a string into a list of strings

Neil Mitchell ndmitchell at gmail.com
Mon Jun 12 19:44:32 EDT 2006


Hi

> beginsWith []       []     = True
> beginsWith _        []     = True
> beginsWith []       _      = False
> beginsWith (a:aa)   (b:bb)
>     | a == b               = aa `beginsWith` bb
>     | otherwise            = False

I used to have this in my library then I discovered isPrefixOf :) (or
flip isPrefixOf, I think in this case)

> endsWith a b = beginsWith (reverse a) (reverse b)
ditto, isSuffixOf

Thanks

Neil


More information about the Haskell-Cafe mailing list