From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 0C340BB81 for ; Fri, 22 Jul 2005 17:26:54 +0200 (CEST) Received: from irsun282.ifp.fr (ns1.ifp.fr [81.255.42.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j6MFQrEf020860 for ; Fri, 22 Jul 2005 17:26:53 +0200 Received: from smtp.ifp.fr by irsun282.ifp.fr (V35.12) with ESMTP X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4927.1200 Received: from irnts70.ifp.fr ([156.118.220.36]) by irnts70 with Microsoft SMTPSVC(5.0.2195.6713); Fri, 22 Jul 2005 17:26:53 +0200 Received: From irsun165.ifp.fr ([156.118.22.211]) by irnts70.ifp.fr (WebShield SMTP v4.5 MR1a P0803.345); id 1122046012956; Fri, 22 Jul 2005 17:26:52 +0200 Received: from [156.118.21.21] (irlin234 [156.118.21.21]) by irsun165.ifp.fr (8.8.5/8.8.5) with ESMTP id RAA20153 for ; Fri, 22 Jul 2005 17:26:52 +0200 (MET DST) Message-ID: <42E1103C.4020602@ifp.fr> Date: Fri, 22 Jul 2005 17:26:52 +0200 From: Christophe Dehlinger User-Agent: Mozilla Thunderbird 0.8 (X11/20040913) X-Accept-Language: en-us, en MIME-Version: 1.0 To: caml-list@yquem.inria.fr Subject: Re: [SPAM_PROBABLE] - [Caml-list] How to do this properly with OCaml? - Bayesian Filter detected spam References: In-Reply-To: Content-Type: text/plain; format=flowed; charset="ISO-8859-1" Content-Transfer-Encoding: quoted-printable X-OriginalArrivalTime: 22 Jul 2005 15:26:53.0362 (UTC) FILETIME=[C9B99920:01C58ED1] X-Miltered: at nez-perce with ID 42E1103D.002 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; christophe:01 christophe:01 caml-list:01 ocaml:01 ocaml:01 indirection:01 arrays:01 arrays:01 flatten:01 flatten:01 val:01 rec:01 foo:01 foo:01 right-hand:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 Thomas Fischbacher wrote: > Please don't tell me that "well, OCaml is not Lisp, after all". > This I already know. But is there no proper way to get around that > (technically speaking) unnecessary extra level of indirection that is > forced upon me due to static type checking? > Hi Thomas, What you're trying to build looks a lot like Extlib's dynamic=20 (resizable) arrays. I gave their implementation a cursory look: it seems to rely heavily on=20 the Obj module. So I guess there probably is no clean and efficient way to do this. Of course, it is pretty awkward having to scan for the first element in > the first nonempty array in an array of arrays, especially as that=20 > element > really does not play a that special role. > > Could anyone please tell me how to do all this in a more appropriate = way? > Here's imho a more elegant way to flatten arrays : let flatten arar =3D let cur_length =3D ref (-1) in let ai =3D ref (-1) in let i =3D ref (-1) in let total_length =3D Array.fold_left (fun accu ar -> accu +=20 (Array.length ar)) 0 arar in let initfun _ =3D incr i ; while !i >=3D !cur_length do incr ai ; cur_length :=3D Array.length arar.(!ai) ; i :=3D 0 done ; arar.(!ai).(!i) in Array.init total_length initfun;; val flatten : 'a array array -> 'a array =3D # flatten [| [|1;2;3|]; [|4|]; [| |]; [|5; 6|] |] ;; - : int array =3D [|1; 2; 3; 4; 5; 6|] However, this is very different from the first problem, as - you know at the time of creation of the array both its length and its=20 contents - its length will not change after its creation I have my own array-related problem, so I'll plug it here :) A couple of times, I would have liked to build arrays of functions whose = body uses the array itself, like: #let rec foo =3D Array.init 5 (fun n () -> if n=3D0 then 0 else = foo.(n/2) ()) This kind of expression is not allowed as right-hand side of `let rec' Why is this kind of construct forbidden ? Cheers, Christophe __________________________ Ce message (et toutes ses pi=E8ces jointes =E9ventuelles) est = confidentiel et =E9tabli =E0 l'intention exclusive de ses destinataires. = Toute utilisation de ce message non conforme =E0 sa destination, toute = diffusion ou toute publication, totale ou partielle, est interdite, sauf = autorisation expresse. L'IFP d=E9cline toute responsabilit=E9 au titre = de ce message. This message and any attachments (the message) are confidential and = intended solely for the addressees. Any unauthorised use or = dissemination is prohibited. IFP should not be liable for this message. Visitez notre site Web / Visit our web site : http://www.ifp.fr __________________________