From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id CD116BC88 for ; Tue, 8 Feb 2005 23:55:46 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j18Mtk47025350 for ; Tue, 8 Feb 2005 23:55:46 +0100 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id XAA09856 for ; Tue, 8 Feb 2005 23:55:45 +0100 (MET) Received: from anthony.ics.uci.edu (anthony.ics.uci.edu [128.195.21.186]) by nez-perce.inria.fr (8.13.0/8.13.0) with SMTP id j18MtijB018065 for ; Tue, 8 Feb 2005 23:55:45 +0100 Received: (qmail 22235 invoked by uid 1000); 8 Feb 2005 22:55:43 -0000 Date: Tue, 8 Feb 2005 14:55:42 -0800 From: Christian Stork To: caml-list@inria.fr Subject: Unquantifiable escaping type in variation of visitor pattern Message-ID: <20050208225542.GA20967@anthony.ics.uci.edu> Mail-Followup-To: caml-list@inria.fr Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Archive: encrypt User-Agent: Mutt/1.5.6+20040907i X-Miltered: at concorde with ID 42094372.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 42094370.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; escaping:01 grammar:01 nodes:01 nodes:01 ocaml:01 escapes:01 model:01 ocaml:01 twist:98 ...:98 baton:98 ...:98 806:98 021:98 node:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: 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