Browse thread
[Caml-list] help
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Jon Harrop <jdh30@c...> |
| Subject: | Re: [Caml-list] help |
I sent you this as an e-mail on Friday:
The following types are a start for your conversion:
type fnum=int and fval=float;
type word = { wnum: fnum ref; weight: fval }
type doc = { docnum: int; queryid: int; costfactor: float; twonorm_sq: float;
words: word array }
type model = { sv_num: int; at_upper_bound: int; b: float; supvec: doc array;
alpha: float };
The following line creates an example "model" with its values filled in:
let test_model = { sv_num=0; at_upper_bound=0; b=0.; supvec=Array.make 1
{ docnum=0; queryid=0; costfactor=0.; twonorm_sq=0.; words=Array.make 1
{ wnum=ref 0; weight=0. } }; alpha=0. };
I deliberately made "wnum" a reference so that it can be set:
test_model.supvec.(0).words.(0).wnum := 1;
If you want to do a really direct conversion then you probably want to make
each of the fields in each of the records a reference (as I did with "wnum").
However, you may wish to exercise the functional programming side of ocaml
and write functions which replace data structures, instead of altering them
in an imperative style. Although this is unintuitive at first, because an
imperative language would do lots of copying and deleting of data structures,
the ocaml compiler is very adept at performing only the changes which are
made to a data structure...
HTH.
Cheers,
Jon.
-------------------
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