Hi Daniel,

I love your solution. Very elegant.

Daniel Fischer wrote:
sortedProducts xs ys = foldr merge1 [] [map (*x) ys | x <- xs]

merge1 (x:xs) ys = x:merge xs ys
merge1 [] ys = ys

merge xs@(x:xt) ys@(y:yt)
    | x < y    = x:merge xt ys
    | otherwise = y:merge xs yt
(or remove duplicates, if you wish)

Small addition: if you want this to run on finite input as well, add this case:

> merge xs ys = xs ++ ys

Martijn.

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to