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 UAA29562; Mon, 28 Apr 2003 20:17:25 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id UAA30226 for ; Mon, 28 Apr 2003 20:17:24 +0200 (MET DST) Received: from xanadu.ece.ucsb.edu (xanadu.ece.ucsb.edu [128.111.56.51]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h3SIHMH14467 for ; Mon, 28 Apr 2003 20:17:23 +0200 (MET DST) Received: from ece.ucsb.edu (gimli.ece.ucsb.edu [128.111.56.252]) by xanadu.ece.ucsb.edu (8.11.6+Sun/8.11.6) with ESMTP id h3SIHKe14924 for ; Mon, 28 Apr 2003 11:17:20 -0700 (PDT) Date: Mon, 28 Apr 2003 11:16:36 -0700 Subject: Re: [Caml-list] Easy solution in OCaml? Content-Type: text/plain; charset=US-ASCII; format=flowed Mime-Version: 1.0 (Apple Message framework v552) From: Shivkumar Chandrasekaran To: caml-list@inria.fr Content-Transfer-Encoding: 7bit In-Reply-To: Message-Id: <8C65E1FC-79A5-11D7-8161-000393942C76@ece.ucsb.edu> X-Mailer: Apple Mail (2.552) X-Spam: no; 0.00; shivkumar:01 shiv:01 caml-list:01 val:01 failwith:01 --shiv--:01 malc:01 siegfried:01 gonzi:01 bigloo:01 matlab:01 dependencies:01 quarterly:99 pulsesoft:01 bug:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Not quite, I think. How about: (* supplied by user *) val is_nan : 'a -> bool val add : 'a -> 'a -> 'a val div : 'a -> 'a -> 'a val from_int : int -> 'a (* that's all from the user *) let q_means is_nan add div from_int ms = function let sum a b c = let filter_nan n = if is_nan n then (from_int 0) else n in add (add (filter_nan a) (filter_nan b)) (filter_nan c) and cardinality a b c = let filter_nan n = if is_nan n then 0 else 1 in from_int ((filter_nan a) + (filter_nan b) + (filter_nan c)) in let rec qm ms = function a :: b :: c :: rest -> div (sum a b c) (cardinality a b c) :: qm rest | [] -> [] | _ -> failwith "Malformed list" in qm ms A good test case is: [-1;-1;-1] --shiv-- On Monday, April 28, 2003, at 10:45 AM, malc wrote: > On Fri, 25 Apr 2003, Siegfried Gonzi wrote: > >> Hi: >> >> First off: It is not homework. I am 29 and writing my PhD in physics. >> Often I am contemplating whether it would be possible to use OCaml in >> combination with my beloved Bigloo to perform statistical >> evaluations. I >> am not sure whether there are any out there who /can/ do this >> evaluations with OCaml what you normally would do with Matlab. The >> problem what arises: type system and working against the compiler. In >> Scheme changing a solution from lets say integer-array to double-array >> is easy, but in Clean for example you would have to change all your >> dependencies. >> I often skim over the libraries and came to the conclusion: C, C++, >> OCaml impossible for me to see any elegance; Clean a bit better; >> Bigloo/Scheme: I am not sure here, because everything looks the same >> maybe this is cheating, but I think it looks the most elegant and less >> intimitating from all. >> >> >> Rationale: given a list of 12 month. I would like to calculate the >> quarterly means and skip any nan. Easy? Yes it is but only on paper >> and >> in Scheme: >> >> e.g: [1,2,4,-1,45,56,45,56,8] >> >> nan=-1.0 >> >> result: [(1+2+3)/3, (45+56)/2, (45+56+8)/3] > > let nan = -1 > > let mean a b c = (a + b + c) / 3 > > let rec qmean = function > a :: b :: c :: rest -> mean a b c :: qmean rest > | [] -> [] > | otherwise -> failwith "malformed list" > > let _ = > let months = [1; 2; 4; -1; 45; 56; 45; 56; 8] in > let denan = List.map (fun x -> if x = nan then 0 else x) months in > qmean denan > > > -- > mailto:malc@pulsesoft.com > > ------------------- > 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 > --shiv-- ------------------- 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