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

* Re: [Caml-list] Problem with parametric classes
  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
  1 sibling, 0 replies; 5+ messages in thread
From: Sami Mäkelä @ 2002-04-22 10:10 UTC (permalink / raw)
  To: Frederic Tronel; +Cc: caml-list

Frederic Tronel wrote:
> 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; .. >

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

This is the same problem as "What does this mean?" thread last week.
The type of "countingObjects" would become
 < 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 > countingObjects,
but type comm is defined after countingObjects.
The solution is to move the definition of countingObjects.
-------------------
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

* Re: [Caml-list] Problem with parametric classes
  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
  1 sibling, 1 reply; 5+ messages in thread
From: John Max Skaller @ 2002-04-22 21:05 UTC (permalink / raw)
  To: Frederic Tronel; +Cc: caml-list

Frederic Tronel wrote:

>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:
>
I commented out the initialiser in specElement and got this error:

File "tmp.ml", line 30, characters 22-41:
The type of this expression,
< get_ident : int; set_ident : int -> unit; _.. > countingObjects,
contains type variables that cannot be generalized

and here on line 30 you are making an instance object without
binding the type variable ..

let countingObjects = new countingObjects ;;

That seems suspicious .. countingObjects is generic
here .. this is at global scope .. the initialiser
which fixes the type is inside a class ..
this has to be wrong ..

-- 
John Max Skaller, mailto:skaller@ozemail.com.au
snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia.
voice:61-2-9660-0850




-------------------
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

* Re: [Caml-list] Problem with parametric classes
  2002-04-22 21:05 ` John Max Skaller
@ 2002-04-23  7:40   ` Frederic Tronel
  2002-04-24  0:36     ` John Max Skaller
  0 siblings, 1 reply; 5+ messages in thread
From: Frederic Tronel @ 2002-04-23  7:40 UTC (permalink / raw)
  To: John Max Skaller, caml-list

John Max Skaller wrote:
> 
> Frederic Tronel wrote:
> 
> >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:
> >
> I commented out the initialiser in specElement and got this error:
> 
> File "tmp.ml", line 30, characters 22-41:
> The type of this expression,
> < get_ident : int; set_ident : int -> unit; _.. > countingObjects,
> contains type variables that cannot be generalized
> 
> and here on line 30 you are making an instance object without
> binding the type variable ..
> 
> let countingObjects = new countingObjects ;;
> 
> That seems suspicious .. countingObjects is generic
> here .. this is at global scope .. the initialiser
> which fixes the type is inside a class ..
> this has to be wrong ..

Why not ?
This code has worked for a long time, before I decided to add some
features (synchroAccounting class).


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

* Re: [Caml-list] Problem with parametric classes
  2002-04-23  7:40   ` Frederic Tronel
@ 2002-04-24  0:36     ` John Max Skaller
  0 siblings, 0 replies; 5+ messages in thread
From: John Max Skaller @ 2002-04-24  0:36 UTC (permalink / raw)
  To: Frederic Tronel; +Cc: caml-list

Frederic Tronel wrote:

>>
>>That seems suspicious .. countingObjects is generic
>>here .. this is at global scope .. the initialiser
>>which fixes the type is inside a class ..
>>this has to be wrong ..
>>
>
>Why not ?
>This code has worked for a long time, before I decided to add some
>features (synchroAccounting class).
>
Because the type of a global is being fixed by an implementation
detail of a class .. classes are supposed to encapsulate things.
If it worked before, it might be considered a bug in the ocaml
type checker: type inference shouldn't cross class boundaries like that.

In any case .. you have a global, and that is bad enough.
It should be passed as an argument to methods that use it,
including the initialiser.

-- 
John Max Skaller, mailto:skaller@ozemail.com.au
snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia.
voice:61-2-9660-0850




-------------------
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).