Here's yet another version:

> (//) :: [a] -> [b] -> [(a,b)]
> xs//ys = concat ([zip xs (reverse ys') | ys' <- inits ys] ++
>                  [zip xs' (reverse ys) | xs' <- tails (tail xs)])

(It only tries to reverse ys if the first comprehension comes to the end
of ys.)

This has reasonable behaviour as long as the subexpression (reverse ys)
is lifted out of the second comprehension.  It could be speeded up slightly
by transforming the first comprehension using the equation

        map reverse . inits = scanl (flip (:)) []

-- Ross Paterson


Reply via email to