Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] help
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-04-25 (01:53)
From: mohammad siddiqui <writetosafi@h...>
Subject: [Caml-list] help

I am having problem dealing with data structures in OCAML, I am translating 
code from C to OCAML. As shown below one structure contains array of other 
structures as its field. One of the guys here told me that we can’t “inline” 
structures into other structures in OCAML.
I don’t how to deal with this, I already spent like 2 days on it. Should I 
make use of objects and let some member of it array of other objects? I am 
not sure this will do the purpose. I really appreciate if anyone helps me 
out this.

For example if try to change the value model.supvec. (1).words. (1).wnum, it 
changes the values of all elements of the array model.supvec. I tried using 
references, mutable fields, Array.set function for modifying the contents of 
individual element.

The structures in OCAML are:

type word = { mutable wnum:int;	       (* word number *)
	     mutable weight:float };;	       (* word weight *)

type doc =  {
	      mutable docnum:int;              (* Document ID *)
	      mutable   queryid:
	      mutable costfactor:float;
	      mutable  twonorm_sq:float;
	      mutable   words:word array

type model =         {
                        mutable   sv_num:int;
                        mutable  at_upper_bound:int;
                        mutable  b:float;
                        mutable  supvec:doc array;
			 mutable alpha: int array;

                       } ;;

The Structures in C are

typedef struct word {
int wnum;
float weight;

typedef struct doc {
  long    docnum;
  long    queryid;
  double  costfactor;
  double  twonorm_sq;
  WORD    *words;
} DOC;

typedef struct model {
  long    sv_num;
  long    at_upper_bound;
  double   b;
  DOC     **supvec;
  Double  *alpha;

FREE pop-up blocking with the new MSN Toolbar – get it now!

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: