[Haskell-cafe] Best way to write endsWith

John Ky newhoggy at gmail.com
Sat Oct 21 11:19:07 EDT 2006


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)

Would this be the preferred function argument order?  Or is the reverse (ie.
endsWith list suffix) better?

I like being able to say "abc" `endsWith` "c", but I also like to be able to
say map (endsWith 't') ["cat", dog"] but I can't have both.

By the way, is there a better way to write this function to be clearer and
more efficient?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20061022/2e7c2078/attachment.htm

More information about the Haskell-Cafe mailing list