
On 12/29/06, Neil Mitchell
Hi
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 :)
Hi Neil, I am not sure how to express f1 with map? how do I say (lambda (ls) (map (lambda (x) (list x)) ls)) in Haskell? map ([]) ? Here is my new f3: f3 :: [[Int]] -> [[Int]] -> [[Int]] f3 [] lb = lb f3 la [] = la f3 la@(a:as) lb@(b:bs) = if sum a <= sum b then a : f3 as lb else b : f3 la bs (btw, yes this is homework assigned by prof. Quan in quantum computing class :)) Thanks, Quan