Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Problem with parametric classes
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Frederic Tronel <Frederic.Tronel@i...>
Subject: [Caml-list] Problem with parametric classes
Hello,

I'm using Ocaml 3.04 (plus a patch applied to circumvent a 
problem with parametric classes bug id 841).

I'm trying to compile the following piece of code (more
precisely, this is a significant excerpt of the faulty code).
which fails with the following error:

File "essai.ml", line 71, characters 5-491:
The abbreviation specElement expands to type
< get_ident : int; get_name : string; mytype : specelement;
  recv : string * comm list -> string * string list -> unit;
  send : comm -> string -> unit; set_ident : int -> unit;
  set_name : string -> unit >
but is used with type < get_ident : int; set_ident : int -> unit; .. >


open Hashtbl;;


type specelement = 
    [`Spec | `Activite | `Conteneur 
  | `Controleur | `ControleParent 
  | `ControleEnfant | `Deploiement 
  | `DeploiementEnfant | `ConfigurationComposite
  | `ExportationService | `DeploiementAgent
  | `DeploiementControleur | `ConfigurationAgent 
  | `ConfigurationControleur | `Attente
  | `ReconfigurationParesseuse | `Configuration
  | `Importation |`Controle | `InstantiationAsynchrone 
  | `Initialisation | `LiaisonTardive | `Referentiel]

class ['a] countingObjects =
  object (this)
    val mutable elements = ([] : 'a list)
   (* Identificateur 0 est non attribue *)
    val mutable id = 0
    method identify x =
      if not (List.memq x elements) then (
	elements <- [x]@elements ;
	id <- id+1 ; x#set_ident id 
       )
   method retrieveObject (id:int) =
      List.find (fun x -> x#get_ident = id) elements
  end


let countingObjects = new countingObjects ;;

type comm = 
    Direct of int
  | ControleurParent
  | Referentiel
  | ComposantControle

class synchronisationAccounting =
  object (this)
    val mutable synchroRecv = create 10
    val mutable synchroSend = create 10
    method private addToTable table cle1 cle2 obj =
      if(not(mem table cle1)) then (
	let ht = create 10 in
 	add ht cle2 obj ;
	add table cle1 ht
       )
      else (
	let ht = find table cle1 in
	if (not(mem ht cle2)) then 
	  add ht cle2 obj
	else
	  let all = find_all ht cle2 in
	  if(not(List.mem obj all)) then
	    add ht cle2 obj
       );
    method send fid tid event =
      this#addToTable synchroSend fid tid event ;
      match (fid,tid) with 
	(Direct idf, Direct idt) -> Printf.fprintf stdout "%s" event 
      |	(_,_) -> failwith "Not yet implemented"
    method recv fidd tid eventd =
      match (fidd,eventd) with 
	((fidn,fidl),(eventn,eventl)) ->
	  List.iter (fun fid -> (List.iter (fun event -> this#addToTable
synchroRecv fid tid event) eventl)) fidl ; 
	  Printf.fprintf stdout "%s %s" eventn fidn ;
  end

let synchroAccounting = new synchronisationAccounting ;;

class specElement =
  fun  (x:specelement)  ->
  object (this)
    val mutable ident = 0
    val mutable name = "" 
    method mytype = x 
    method set_ident id = ident <- id 
    method get_ident = ident
    method set_name x = name <- x
    method get_name = name
    method send tid event = synchroAccounting#send (Direct ident) tid
event
    method recv fid event =  synchroAccounting#recv fid (Direct ident)
event
   
    initializer countingObjects#identify (this:>specElement)
  end


What is the problem ???
It does compile if I comment out send and recv methods of class
specElement.
Any help would be really appreciated.

Best regards,

Frederic Tronel.
-------------------
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