Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: "Rafael 'Dido' Sevilla" <dido@imperium.ph>
To: caml-list@inria.fr
Subject: [Caml-list] implementing the visitor pattern in ocaml
Date: Tue, 14 Oct 2003 17:11:12 +0800	[thread overview]
Message-ID: <20031014091112.GB26517@imperium.ph> (raw)

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


             reply	other threads:[~2003-10-14  9:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-14  9:11 Rafael 'Dido' Sevilla [this message]
2003-10-14 10:13 ` Samuel Lacas
2003-10-14 15:18   ` Didier Remy

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=20031014091112.GB26517@imperium.ph \
    --to=dido@imperium.ph \
    --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