From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA18536; Sun, 27 Apr 2003 17:25:10 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA18539 for ; Sun, 27 Apr 2003 17:25:09 +0200 (MET DST) Received: from teutates.kfunigraz.ac.at (TEUTATES.kfunigraz.ac.at [143.50.129.26]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h3RFP8T12792 for ; Sun, 27 Apr 2003 17:25:08 +0200 (MET DST) Received: from localhost (localhost.localdomain [127.0.0.1]) by teutates.kfunigraz.ac.at (Postfix) with ESMTP id A834B3D2225; Sun, 27 Apr 2003 17:25:07 +0200 (CEST) Received: from teutates.kfunigraz.ac.at ([127.0.0.1]) by localhost (teutates.kfunigraz.ac.at [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 32567-09; Sun, 27 Apr 2003 17:25:07 +0200 (CEST) Received: from stud.uni-graz.at (IGAM08AV.kfunigraz.ac.at [143.50.39.35]) by teutates.kfunigraz.ac.at (Postfix) with ESMTP id ACA563D2221; Sun, 27 Apr 2003 17:25:06 +0200 (CEST) Message-ID: <3EABE583.802@stud.uni-graz.at> Date: Sun, 27 Apr 2003 16:13:23 +0200 From: Siegfried Gonzi User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.8) Gecko/20020204 X-Accept-Language: en-us MIME-Version: 1.0 To: Markus Mottl Cc: caml-list@inria.fr Subject: Re: [Caml-list] Easy solution in OCaml? References: <3EA8D012.8040700@stud.uni-graz.at> <20030425165944.GC6284@erle.ai.univie.ac.at> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at stud.uni-graz.at X-Spam: no; 0.00; siegfried:01 gonzi:01 stud:99 caml-list:01 elegantly:01 0.0:01 failwith:01 erg:01 ocaml:01 int:01 rec:01 mottl:02 float:02 comparison:02 module:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > > > >Markus Mottl wrote: > >> > >Or in OCaml, if you know how to do it elegantly and reasonably efficiently: > > let coll (len, sum as acc) n = if n >= 0 then len + 1, sum + n else acc > > let qmeans = > let rec loop acc = function > | a :: b :: c :: t -> > let len, sum = coll (coll (coll (0, 0) a) b) c in > loop ((if len = 0 then 0.0 else float sum /. float len) :: acc) t > | [] -> List.rev acc > | _ -> failwith "qmeans: illegal list" in > loop [] > As comparison I post my Clean version (it is more general or could be made general, lets say for a list with 24 hours). But I am still not contended, because why isn't it possible to use more elegant "functional-constructs" which lead to short, easy to read and easy to comprehend solutions (see also my post on comp.lang.functional): == module stat import StdEnv quarter:: [Real] Real -> [Real] quarter ls nan = sum_it 0 0.0 0 ls [] where sum_it:: Int Real Int [Real] [Real] -> [Real] sum_it counter sum n [] erg = reverse erg sum_it counter sum n [h:t] erg | (counter == 2) | n > 0 = sum_it 0 0.0 0 t [(sum/toReal(n)):erg] = sum_it 0 0.0 0 t [nan:erg] | h > nan = sum_it (counter+1) (sum+h) (n+1) t erg | otherwise = sum_it (counter+1) sum n t erg Start = quarter [1.0,2.0,-1.0,3.4,3.4,-1.0,-1.0,2.3,3.4,-1.0,-1.0,-1.0] (-1.0) == Regards, S. Gonzi ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners