From: Christian Stork <cstork@ics.uci.edu>
To: caml-list@inria.fr
Subject: Unquantifiable escaping type in variation of visitor pattern
Date: Tue, 8 Feb 2005 14:55:42 -0800 [thread overview]
Message-ID: <20050208225542.GA20967@anthony.ics.uci.edu> (raw)
Hello,
I'm tying to implement a framework for visitors over trees (e.g. ASTs).
These trees are built according to some rules. Rules are much like the
productions of a grammar.
The following minimal example demonstrates my current design problem:
type 'rule node = { rule:'rule; kids:'rule node list }
class someRule =
object (self)
method accept
: 'baton . someRule node -> 'baton visitor -> 'baton -> 'baton
= fun n v b -> v#visitSomeRuleNode n b
end
and ['baton] visitor =
object (self)
method visitSomeRuleNode (n:someRule node) (b:'baton) =
List.fold_left
(fun b' k -> k.rule#accept k (self:>'baton visitor) b')
b n.kids
end
The idea is that nodes are simple records that refer to their specific
rule, have child nodes, and carry some additional data (not shown
above). Rules and visitors are implemented as objects. They are
responsible for implementing the accept & visitSomeRuleNode methods. (In
the minimalistic example there's only one rule but there can/will be
many.)
The above code has one special twist, it allows the visitor's visit...
methods to hand eachother some argument, called the baton. Different
visitors might want to use different types of batons. The above code
tries to support this by parametrizing the accept method and the
visitor class. Sadly, Ocaml complains about then with
...in method accept...
This type scheme cannot quantify 'baton :
it escapes this scope.
I don't really understand this error message. I assume it has to do
with 'baton being a parameter in 'baton visitor and its use in
visitSomeRuleNode. Any clarifications are welcome! :-)
Anyway, is there maybe a different, workable way to model this variation
of the visitor pattern in OCaml?
Thanks for you time,
Chris
--
Chris Stork <> Support eff.org! <> http://www.ics.uci.edu/~cstork/
OpenPGP fingerprint: B08B 602C C806 C492 D069 021E 41F3 8C8D 50F9 CA2F
next reply other threads:[~2005-02-08 22:55 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-02-08 22:55 Christian Stork [this message]
2005-02-09 0:16 ` [Caml-list] " John Prevost
2005-02-22 17:29 ` Christian Stork
2005-02-23 3:08 ` Jacques Garrigue
2005-02-24 12:16 ` Christian Stork
2005-02-24 23:57 ` Jacques Garrigue
2005-02-25 0:30 ` Jacques Garrigue
2005-02-09 1:53 ` Jacques Garrigue
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=20050208225542.GA20967@anthony.ics.uci.edu \
--to=cstork@ics.uci.edu \
--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