
I think David's proposed definition is the easiest to read form with good
performance so far.
As to definedness, the change in semantics doesn't matter to me. But I
think calling isSuffixOf on possibly infinite lists is a bad idea anyway.
John L.
On Oct 10, 2014 5:35 AM, "Milan Straka"
Hi all,
-----Original message----- From: David Feuer
Sent: 10 Oct 2014, 05:23 On Fri, Oct 10, 2014 at 5:18 AM, Jon Fairbairn <
jon.fairbairn@cl.cam.ac.uk>
wrote:
That seems rather wordy to me. Can we get anywhere starting with
It is rather wordy; I just don't know how to do better.
What about something like the following? It uses exactly the same algorithm, it just avoids the maybe combinator and Maybe internal result, and renames stuff:
isSuffixOf :: (Eq a) => [a] -> [a] -> Bool [] `isSuffixOf` _ = True needle `isSuffixOf` hay = subtract_and_compare needle hay where subtract_and_compare [] diff = skip_and_compare diff hay subtract_and_compare _ [] = False -- needle longer than hay subtract_and_compare (n:ns) (h:hs) = subtract_and_compare ns hs
skip_and_compare [] suffix = needle == suffix skip_and_compare _ [] = True -- first argument must also be [] skip_and_compare (d:ds) (s:ss) = skip_and_compare ds ss
The redundant skip_and_compare case is there just for completeness and readability.
Cheers, Milan _______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries