caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Parametric classes and weak types
@ 2002-01-31  8:52 Frederic Tronel
  2002-01-31  9:09 ` Jacques Garrigue
  0 siblings, 1 reply; 4+ messages in thread
From: Frederic Tronel @ 2002-01-31  8:52 UTC (permalink / raw)
  To: caml-list

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


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

* Re: [Caml-list] Parametric classes and weak types
  2002-01-31  8:52 [Caml-list] Parametric classes and weak types Frederic Tronel
@ 2002-01-31  9:09 ` Jacques Garrigue
  2002-01-31  9:19   ` Frederic Tronel
  0 siblings, 1 reply; 4+ messages in thread
From: Jacques Garrigue @ 2002-01-31  9:09 UTC (permalink / raw)
  To: Frederic.Tronel; +Cc: caml-list

Hi,

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

I'm working on the problem. Curiously, what triggers it seems to be
the printer: as long as values of the above type are not printed, type
inference works fine.

It's touching a very sensitive part of ocaml, the combination of
recursive types and type abbreviations. Maybe Jerome can also have a
look at the bug report ? Hint: the loop is in a call to expand_head,
inside moregeneral.

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


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

* Re: [Caml-list] Parametric classes and weak types
  2002-01-31  9:09 ` Jacques Garrigue
@ 2002-01-31  9:19   ` Frederic Tronel
  0 siblings, 0 replies; 4+ messages in thread
From: Frederic Tronel @ 2002-01-31  9:19 UTC (permalink / raw)
  To: Jacques Garrigue; +Cc: caml-list

Jacques Garrigue wrote:
> 
> 
> I'm working on the problem. Curiously, what triggers it seems to be
> the printer: as long as values of the above type are not printed, type
> inference works fine.

Yes indeed, in this example it works perfectly if you do not print
the type (by compiling). But in my original example, I have been able
to make the compiler hangs. I can provide you with the complete example,
if it can help.

> 
> It's touching a very sensitive part of ocaml, the combination of
> recursive types and type abbreviations. Maybe Jerome can also have a
> look at the bug report ? Hint: the loop is in a call to expand_head,
> inside moregeneral.

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


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

* [Caml-list] Parametric classes and weak types
@ 2002-01-30 10:02 Frederic Tronel
  0 siblings, 0 replies; 4+ messages in thread
From: Frederic Tronel @ 2002-01-30 10:02 UTC (permalink / raw)
  To: caml-list

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


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

end of thread, other threads:[~2002-01-31  9:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-31  8:52 [Caml-list] Parametric classes and weak types Frederic Tronel
2002-01-31  9:09 ` Jacques Garrigue
2002-01-31  9:19   ` Frederic Tronel
  -- strict thread matches above, loose matches on Subject: below --
2002-01-30 10:02 Frederic Tronel

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