[Haskell-cafe] Re: Best way to write endsWith

Lemmih lemmih at gmail.com
Sat Oct 21 12:07:36 EDT 2006


On 10/21/06, Stephan Walter <news at stephan.walter.name> wrote:
> John Ky wrote:
> > Hello,
> >
> > I have this function here:
> >
> >> endsWith :: Eq a => [a] -> [a] -> Bool
> >> endsWith suffix list
> >>   | lengthDifference < 0 = False
> >>   | otherwise = (drop lengthDifference list) == suffix
> >>   where lengthDifference = (length list) - (length suffix)
>
> I thinks that's what List.isSuffixOf does.

isSuffixOf x y          =  reverse x `isPrefixOf` reverse y

-- 
Cheers,
  Lemmih


More information about the Haskell-Cafe mailing list