From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA02030; Tue, 14 Oct 2003 11:11:11 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id LAA28693 for ; Tue, 14 Oct 2003 11:11:09 +0200 (MET DST) Received: from intmail.imperium.ph ([202.175.240.154]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h9E9B7104046 for ; Tue, 14 Oct 2003 11:11:08 +0200 (MET DST) Received: from morgoth.imperium.ph (unknown [192.168.1.35]) by intmail.imperium.ph (Postfix) with SMTP id A9B8546A73 for ; Tue, 14 Oct 2003 17:11:05 +0800 (PHT) Received: by morgoth.imperium.ph (sSMTP sendmail emulation); Tue, 14 Oct 2003 17:11:12 +0800 Date: Tue, 14 Oct 2003 17:11:12 +0800 From: "Rafael 'Dido' Sevilla" To: caml-list@inria.fr Subject: [Caml-list] implementing the visitor pattern in ocaml Message-ID: <20031014091112.GB26517@imperium.ph> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Operating-System: Linux morgoth 2.4.20-gentoo-r5 User-Agent: Mutt/1.5.4i X-Loop: caml-list@inria.fr X-Spam: no; 0.00; rafael:01 'dido':01 dido:01 ocaml's:01 foo:01 foo:01 val:01 ocaml:01 ocaml:01 inherit:01 int:01 int:01 unit:03 string:03 string:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk I've been experimenting with OCaml's object-oriented features, and have tried to implement the visitor pattern in OCaml. Here's one attempt: class virtual abstractvisitor = object method virtual visit_foo : foo -> unit end and foo (x_init : int) = object (self) val x = x_init method get_x = x method accept (v : abstractvisitor) = v#visit_foo(self) end and visitor = object inherit abstractvisitor method visit_foo f = print_string ("x = " ^ (string_of_int f#get_x)) end ;; but I get this: This expression has type < accept : abstractvisitor -> 'a; get_x : int; .. > but is here used with type foo = < .. > Self type cannot escape its class What does this mean? What's the right way to implement the visitor design pattern in OCaml? ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners