caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Problem with parametric classes
@ 2002-04-22  8:43 Frederic Tronel
  2002-04-22 10:10 ` Sami Mäkelä
  2002-04-22 21:05 ` John Max Skaller
  0 siblings, 2 replies; 5+ messages in thread
From: Frederic Tronel @ 2002-04-22  8:43 UTC (permalink / raw)
  To: caml-list

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


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

end of thread, other threads:[~2002-04-24  0:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-22  8:43 [Caml-list] Problem with parametric classes Frederic Tronel
2002-04-22 10:10 ` Sami Mäkelä
2002-04-22 21:05 ` John Max Skaller
2002-04-23  7:40   ` Frederic Tronel
2002-04-24  0:36     ` John Max 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).