Another alternative to diag [[f x y | x < - xs] | y <- ys] is
to write it as diagWith f xs ys where:

diagWith f []     ys = []
diagWith f xs     [] = []
diagWith f (x:xs) ys = d [x] xs ys
  where
  d xs' xs ys = zipWith f xs' ys ++ d' xs ys
    where
    d' []     []     = []
    d' []     (y:ys) = d xs' [] ys
    d' (x:xs) ys     = d (x:xs') xs ys

The ++ could be eliminated for the price of a zipWith variant
with a continuation argument.




Reply via email to