[Haskell-cafe] Re: Best way to write endsWith
Stephan Walter
news at stephan.walter.name
Sat Oct 21 11:33:29 EDT 2006
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.
> 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.
import List
"c" `isSuffixOf` "abc"
map ("t" `isSuffixOf`) ["cat", "dog"]
--Stephan
More information about the Haskell-Cafe
mailing list