Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Parametric classes and weak types
[ 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] Parametric classes and weak types
Hello,


I'm facing the following problems.
I've written a parser using ocamlyacc, it generates
a object of a given class, that in turn itself contains
many fields of different classes and so on ...
It can be considered as being an abstract syntax tree,
except that each node of the tree has not a unique type.
Up to this point everything works perfectly.

Then I want to generate a new tree which consists of a totally
different set of classes (although semantically related).
But I want this mechanism to be as generic as possible
(that is, I don't want the first set of classes to be bound
to the second set of classes).
To do this, I've used parametric classes (for the first set
of classes) in combination with weak types.
But I'm facing real problems either at runtime, or even at compile
time. It seems that either the interpreter or the compiler is unable
to synthesize the types of my data structures, being locked during
either the interpretation of an expression, or the compilation of
a .ml.

I've tried to generate a small example that seems to generate
problems with the interpreter, since the original code is much too long
to be posted:


exception E
class ['a] ca =
  object (this)
    val mutable into = ([] : 'a list)
    method get_into = 
      match into with 
	[] -> raise E
      |[x] -> x
      |_ -> raise E
    method set_into x = into <- [x] 
    method set_transform = this#set_into
    method transform = 
      this#get_into this
  end
and ['a,'b] cb =
  object (this)
    val mutable into = ([] : 'a list)
    method get_into =
      match into with 
	[] -> raise E
      |[x] -> x
      |_ -> raise E
    method set_into x = into <- [x]
    val mutable atts = ([] : 'b ca list)
    method get_atts = atts
    method set_atts x = atts <- x
    method set_transform a b =
      this#set_into a ;
      List.iter (fun x -> x#set_transform b) atts
    method transform = 
      let cb = this#get_into this in
      let ca = List.fold_left ( fun a b -> [b#transform]@a ) [] atts in
      (cb,ca)
  end

Using ocaml 3.04 under solaris or linux, using the ocaml I have the
following problem:
# let ca1 = new ca ;;
val ca1 : ('a -> '_b) ca as 'a = <obj>
# let cb1 = new cb ;;
val cb1 : ('a -> '_b, 'c ca -> '_d as 'c) cb as 'a = <obj>
#  cb1#set_atts [ca1];;
- : unit = ()
#   cb1#set_transform (fun x -> x) (fun x -> x);;
- : unit = ()
#  cb1#transform ;;
- : (('a -> 'a, ('b ca as 'c) -> 'c as 'b) cb as 'a) * 'c list =
<obj>, [<obj>]
#  cb1#transform ;;

Here it hangs indefinitely.

Any idea ??

Frederic Tronel.
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr