It can be, but your way traverses the entire haystack *twice*. The memory needs are equivalent to the reversing version, which I consider unacceptable.

On Sat, Oct 11, 2014 at 5:57 AM, Andreas Abel <abela@chalmers.se> wrote:
David, the essence of your idea seems mutually drop the correct number of elements from needle and hay and then compare for equality.  Here is a concise implementation of your idea in terms of drop:

isSuffixOf        :: forall a . (Eq a) => [a] -> [a] -> Bool
[] `isSuffixOf` _  =  True
xs `isSuffixOf` ys =  xs == drop (length (drop (length xs) ys)) ys

This can be further simplified to

isSuffixOf        :: forall a . (Eq a) => [a] -> [a] -> Bool
[] `isSuffixOf` _  =  True
xs `isSuffixOf` ys =  xs == drop (length ys - length xs) ys

which is a very easy to understand program, I think, without need to reverse lists.