From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=AWL,SPF_SOFTFAIL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id ADA29BC69 for ; Mon, 5 Mar 2007 07:06:14 +0100 (CET) Received: from mail.rsise.anu.edu.au (mail.rsise.anu.edu.au [150.203.208.4]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l2566BoG023062 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 5 Mar 2007 07:06:14 +0100 Received: from localhost (localhost [127.0.0.1]) by mail.rsise.anu.edu.au (Postfix) with ESMTP id C60E9545B2 for ; Mon, 5 Mar 2007 17:05:58 +1100 (EST) Received: from mail.rsise.anu.edu.au ([150.203.208.4]) by localhost (mail [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 32337-06 for ; Mon, 5 Mar 2007 17:05:58 +1100 (EST) Received: from pulp.rsise.anu.edu.au (pulp.rsise.anu.edu.au [150.203.208.49]) by mail.rsise.anu.edu.au (Postfix) with ESMTP id A8A35545A2 for ; Mon, 5 Mar 2007 17:05:55 +1100 (EST) Received: by pulp.rsise.anu.edu.au (Postfix, from userid 1560) id 2DCB7A0AFCC; Mon, 5 Mar 2007 17:10:50 +1100 (EST) Date: Mon, 5 Mar 2007 17:10:50 +1100 From: Pietro Abate To: ocaml ml Subject: to merge list of lists Message-ID: <20070305061050.GA21256@pulp.rsise.anu.edu.au> Mail-Followup-To: Pietro Abate , ocaml ml MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Operating-System: GNU/Linux X-Organization: Research School of Information Science and Engineering (Australian National University) User-Agent: Mutt/1.5.13 (2006-08-11) X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at mail.rsise.anu.edu.au X-Miltered: at concorde with ID 45EBB353.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; flatten:01 blog:98 blog:98 rec:01 rec:01 int:01 primitives:01 match:02 overly:02 philosophy:02 let:03 let:03 notion:04 hints:04 generalize:04 Hi all, I want to write a small function to merge a list of lists mergel [] [[1;2;3];[4;5;6];[7;8;9]];; - : int list list = [[1; 4; 7]; [2; 5; 8]; [3; 6; 9]] I've written it down, but to me, it looks overly complicated : let rec mergel acc ll = let rec aux (al,all) = function [] -> (List.rev al,List.rev all) | [] :: tl -> aux (al,all) tl | (h :: l) :: tl -> aux ((h::al),(l::all)) tl in match aux ([],[]) ll with |([],[]) -> List.rev acc |(l,[]) -> l::acc |(l,tl) -> mergel (l::acc) tl ;; Since my goal is to write it lazily, I'm wondering if there is a way of re-write the same function just by using list primitives (map, flatten, ...). (?) I always feel that when solving these kind of problems I miss some greater truth ... for example, by using list comprehensions it's easy to generalize a class of combinatorial problems. Is there a similar notion I can use in this case ? Any hints ? :) p -- ++ Blog: http://blog.rsise.anu.edu.au/?q=pietro ++ ++ "All great truths begin as blasphemies." -George Bernard Shaw ++ Please avoid sending me Word or PowerPoint attachments. See http://www.fsf.org/philosophy/no-word-attachments.html