caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: [Caml-list] help
@ 2004-04-25 16:30 mohammad siddiqui
  2004-04-25  1:53 ` mohammad siddiqui
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: mohammad siddiqui @ 2004-04-25 16:30 UTC (permalink / raw)
  To: jdh30, caml-list


John,

I tried exactly what you have told. Its is fine when we just have one 
element in an array of words. If we have more than one, changing the value 
of one changes the values of the rest of the elements.

for example , if the test_model is initialiazed like this:

let test_model =
{ sv_num=0; at_upper_bound=0; b=0.; supvec=Array.make 2
{ docnum=0; queryid=0; costfactor=0.; twonorm_sq=0.; words=Array.make 1
{ wnum=ref 0; weight=0. } }; alpha=0. };

now if i change the values , it chnages all th elements of the array 
"supvec" in model

test_model.supvec.(0).words.(0).wnum := 1;

# test_model;;
- : model =
{sv_num = 0; at_upper_bound = 0; b = 0.;
supvec =
  [|{docnum = 0; queryid = 0; costfactor = 0.; twonorm_sq = 0.;
     words = [|{wnum = {contents = 1}; weight = 0.}|]};
    {docnum = 0; queryid = 0; costfactor = 0.; twonorm_sq = 0.;
     words = [|{wnum = {contents = 1}; weight = 0.}|]}|];
alpha = 0.}

Thanks,

Mohammad S Siddiqui.


it changes the values of wnum in all elements of model.supvec.
{ sv_num=0; at_upper_bound=0; b=0.; supvec=[
{ docnum=0; queryid=0; costfactor=0.; twonorm_sq=0.; words=Array.make 1
{ wnum=ref 0; weight=0. } }; alpha=0. };


>From: Jon Harrop <jdh30@cam.ac.uk>
>To: caml-list@inria.fr
>Subject: Re: [Caml-list] help
>Date: Sun, 25 Apr 2004 13:13:37 +0100
>
>
>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

_________________________________________________________________
Test your ‘Travel Quotient’ and get the chance to win your dream trip! 
http://travel.msn.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


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2004-04-26 22:38 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-25 16:30 [Caml-list] help mohammad siddiqui
2004-04-25  1:53 ` mohammad siddiqui
2004-04-25 12:13   ` Jon Harrop
2004-04-25 12:45     ` Henri DF
2004-04-26 19:13       ` Jon Harrop
2004-04-26 22:38         ` Andrew Lenharth
2004-04-25 16:44   ` [Caml-list] help Brian Hurt
2004-04-25 17:28   ` [Caml-list] help Matt Gushee
2004-04-25 17:06 ` Jon Harrop
2004-04-25 17:39   ` Matt Gushee
2004-04-26  0:45 ` skaller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).