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.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 700D1BC6B for ; Tue, 30 Oct 2007 09:01:38 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAE+CJkfUGyodimdsb2JhbACOXwIBCAQGEREH X-IronPort-AV: E=Sophos;i="4.21,346,1188770400"; d="scan'208";a="3819933" Received: from smtp3-g19.free.fr ([212.27.42.29]) by mail1-smtp-roc.national.inria.fr with ESMTP; 30 Oct 2007 09:01:38 +0100 Received: from smtp3-g19.free.fr (localhost.localdomain [127.0.0.1]) by smtp3-g19.free.fr (Postfix) with ESMTP id 0B79217B52D; Tue, 30 Oct 2007 09:01:38 +0100 (CET) Received: from [192.168.0.4] (rke75-3-82-229-183-156.fbx.proxad.net [82.229.183.156]) by smtp3-g19.free.fr (Postfix) with ESMTP id C8AE517B573; Tue, 30 Oct 2007 09:01:37 +0100 (CET) Message-ID: <4726E433.7060408@frisch.fr> Date: Tue, 30 Oct 2007 08:58:43 +0100 From: Alain Frisch User-Agent: Thunderbird 2.0.0.6 (Windows/20070728) MIME-Version: 1.0 To: skaller Cc: Julien Moutinho , caml-list@yquem.inria.fr Subject: Re: [Caml-list] Preferred Way to Split a List References: <47266DB7.1020009@SmokejumperIT.com> <20071030012012.GA29836@localhost> <1193723182.6129.66.camel@rosella.wigram> In-Reply-To: <1193723182.6129.66.camel@rosella.wigram> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; frisch:01 frisch:01 wrote:01 rec:01 caml-list:01 alain:01 alain:01 argument:02 match:02 slower:02 let:03 let:03 split:08 split:08 maybe:10 skaller wrote: > The fastest way is: How can you be so sure? Do you have a proof or some intuitive argument? Or maybe you tried all the possible other implementations? The following should not be that much slower (I did not try it, though, and of course, it is not tail-rec): let split l n = let l2 = ref [] in let rec aux l n = if n = 0 then (l2 := l; []) else match l with | [] -> [] | hd :: tl -> hd :: (aux tl (n - 1)) in let l1 = aux l n in (l1, !l2) Alain