From: Frederic Tronel <Frederic.Tronel@inrialpes.fr>
To: caml-list@inria.fr
Subject: [Caml-list] Parametric classes and weak types
Date: Thu, 31 Jan 2002 09:52:31 +0100 [thread overview]
Message-ID: <3C5905CF.A09E2519@inrialpes.fr> (raw)
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
next reply other threads:[~2002-01-31 8:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-01-31 8:52 Frederic Tronel [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3C5905CF.A09E2519@inrialpes.fr \
--to=frederic.tronel@inrialpes.fr \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox