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.4 required=5.0 tests=AWL,DATE_IN_PAST_12_24 autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 58E9CBC6B for ; Tue, 30 Oct 2007 10:31:53 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAO6WJkfUGyoei2dsb2JhbACOXwIBCAQGCQgRB4ET X-IronPort-AV: E=Sophos;i="4.21,346,1188770400"; d="asc'?vcf'?scan'208";a="5272476" Received: from smtp4-g19.free.fr ([212.27.42.30]) by mail3-smtp-sop.national.inria.fr with ESMTP; 30 Oct 2007 10:31:53 +0100 Received: from smtp4-g19.free.fr (localhost.localdomain [127.0.0.1]) by smtp4-g19.free.fr (Postfix) with ESMTP id AF8BF3EA145; Tue, 30 Oct 2007 10:31:52 +0100 (CET) Received: from [192.168.144.128] (unknown [82.250.89.14]) by smtp4-g19.free.fr (Postfix) with ESMTP id 267523EA0E5; Tue, 30 Oct 2007 10:31:52 +0100 (CET) Message-ID: <4725A915.3020005@univ-savoie.fr> Date: Mon, 29 Oct 2007 10:34:13 +0100 From: Christophe Raffalli User-Agent: Thunderbird 2.0.0.6 (X11/20071008) MIME-Version: 1.0 To: Alain Frisch Cc: skaller , 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> <4726E433.7060408@frisch.fr> In-Reply-To: <4726E433.7060408@frisch.fr> X-Enigmail-Version: 0.95.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigA87C95BB5A608517D04C2BB3" X-Spam: no; 0.00; christophe:01 raffalli:01 christophe:01 raffalli:01 univ-savoie:01 recursive:01 val:01 cheers:01 beginner's:01 ocaml:01 bug:01 grey:98 beginners:01 rec:01 caml-list:01 X-Attachments: cset="utf-8" name="Christophe.Raffalli.vcf" name="Christophe.Raffalli.vcf" type="application/pgp-signature" name="signature.asc" name="signature.asc" This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigA87C95BB5A608517D04C2BB3 Content-Type: multipart/mixed; boundary="------------030400090100060307060501" This is a multi-part message in MIME format. --------------030400090100060307060501 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Or let split l n =3D let rec aux acc l n =3D if n =3D 0 then List.rev acc, l else match l with [] -> List.rev acc, [] | hd::l -> aux (hd::acc) l (n-1) in aux [] l n This is tail recursive, it does not use magic nor references and keed the original ordering of the list. Finally, I did in the past some testing comparing a tail-rec append or m= ap using magic and the composition of rev and rev-append or rev-map ... There was no noticable difference, because the extra cost of mutability (regarding the managment of the grey val list) compensate the extra call to reverse. So I think I would write split the way shown above if ordering matters. Cheers, Christophe > > Alain > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs --------------030400090100060307060501 Content-Type: text/x-vcard; charset=utf-8; name="Christophe.Raffalli.vcf" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="Christophe.Raffalli.vcf" begin:vcard fn:Christophe Raffalli n:Raffalli;Christophe org:LAMA (UMR 5127) email;internet:Christophe.Raffalli@univ-savoie.fr title;quoted-printable:Ma=3DC3=3DAEtre de conf=3DC3=3DA9rences tel;work:+33 4 79 75 81 03 note;quoted-printable:Message sign=3DC3=3DA9 cryptographiquement avec pgp= , la clef publique est sur=3D subkeys.pgp.net x-mozilla-html:TRUE version:2.1 end:vcard --------------030400090100060307060501-- --------------enigA87C95BB5A608517D04C2BB3 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFHJakai9jr/RgYAS4RArOeAKDSc8i8aIGjzGJo8tdbi1hHFL7uiwCgw7tm DUESTNpLMbC3iE/x2s+3pnY= =XYVf -----END PGP SIGNATURE----- --------------enigA87C95BB5A608517D04C2BB3--