From: Shivkumar Chandrasekaran <shiv@ece.ucsb.edu>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Easy solution in OCaml?
Date: Mon, 28 Apr 2003 11:16:36 -0700 [thread overview]
Message-ID: <8C65E1FC-79A5-11D7-8161-000393942C76@ece.ucsb.edu> (raw)
In-Reply-To: <Pine.LNX.4.55.0304282143540.588@home.oyster.ru>
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
next prev parent reply other threads:[~2003-04-28 18:17 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-04-25 6:05 Siegfried Gonzi
2003-04-25 8:19 ` sebastien FURIC
2003-04-25 15:46 ` Brian Hurt
2003-04-25 16:34 ` Ville-Pertti Keinonen
2003-04-26 13:45 ` Siegfried Gonzi
2003-04-26 21:51 ` Brian Hurt
2003-04-27 15:01 ` Siegfried Gonzi
2003-04-28 15:43 ` Brian Hurt
2003-04-29 5:46 ` John Max Skaller
2003-04-27 16:33 ` [Caml-list] Re: IEEE-754 (was: Easy solution in OCaml?) Christophe TROESTLER
2003-04-25 16:59 ` [Caml-list] Easy solution in OCaml? Markus Mottl
2003-04-26 6:25 ` Siegfried Gonzi
2003-04-27 14:13 ` Siegfried Gonzi
2003-04-27 16:54 ` Eray Ozkural
2003-04-28 5:00 ` Siegfried Gonzi
2003-04-28 17:45 ` malc
2003-04-28 18:16 ` Shivkumar Chandrasekaran [this message]
[not found] <20030427164326.34082.qmail@web41211.mail.yahoo.com>
2003-04-28 12:05 ` Siegfried Gonzi
2003-04-28 13:54 ` Noel Welsh
2003-04-28 14:22 ` David Brown
2003-04-28 14:38 ` sebastien FURIC
2003-04-28 18:14 ` Eray Ozkural
2003-05-03 14:37 ` John Max Skaller
2003-05-03 16:57 ` Eray Ozkural
2003-04-28 15:27 isaac gouy
2003-04-28 16:38 ` brogoff
2003-04-28 17:13 ` isaac gouy
2003-04-28 17:48 ` Brian Hurt
2003-04-28 17:50 ` brogoff
2003-04-28 18:31 ` Eray Ozkural
2003-04-29 6:46 ` Siegfried Gonzi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8C65E1FC-79A5-11D7-8161-000393942C76@ece.ucsb.edu \
--to=shiv@ece.ucsb.edu \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox