Combining sequences

Is there a simple way to combine two sequences that are in ascending order into a single sequence that's also in ascending order? An example would be the squares [1,4,9,16,25..] combined with the cubes [1,8,27,64,125..] to form [1,1,4,8,9,16,25,27..]. Michael

Here's a pretty straightforward approach:
combine [] ys = ys
combine xs [] = xs
combine (x:xs) (y:ys) | x <= y = x : combine xs (y:ys)
| otherwise = y : combine (x:xs) ys
On Sat, Apr 4, 2009 at 8:40 PM, michael rice
Is there a simple way to combine two sequences that are in ascending order into a single sequence that's also in ascending order? An example would be the squares [1,4,9,16,25..] combined with the cubes [1,8,27,64,125..] to form [1,1,4,8,9,16,25,27..].
Michael
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Sat, 4 Apr 2009, michael rice wrote:
Is there a simple way to combine two sequences that are in ascending order into a single sequence that's also in ascending order? An example would be the squares [1,4,9,16,25..] combined with the cubes [1,8,27,64,125..] to form [1,1,4,8,9,16,25,27..].
http://hackage.haskell.org/packages/archive/utility-ht/0.0.4/doc/html/Data-L...
participants (3)
-
Andrew Wagner
-
Henning Thielemann
-
michael rice