[Haskell-cafe] Combine list of sorted lists

Neil Mitchell ndmitchell at gmail.com
Fri Dec 29 04:08:44 EST 2006


>       f1 :: [Int] -> [[Int]]
>        f1 []     = []
>       f1 (a:as) = [a] : f1 as

f1 is simply a map

>       f3 la lb = let a = head la
>                       b = head lb
>                  in if sum a <= sum b then
>                         a : f3 (tail la) lb
>                      else
>                         b : f3 la (tail lb)

Why not use pattern matching to split up la and lb, rather than head/tail?

I would have thought the whole function could be written as a nice
foldr merge, where merge :: [Int] -> [Int] -> [Int]. Thats only a
guess at the top of my head though, not worked out properly.

Is this homework? If so its useful to state when you post the question :)



More information about the Haskell-Cafe mailing list