<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/10/90ca861a25ed8e5d1d82dbb9d0fe2021"
  from="Rafael &apos;Dido&apos; Sevilla &lt;dido@i...&gt;"
  author="Rafael &apos;Dido&apos; Sevilla"
  date="2003-10-14T09:11:11"
  subject="[Caml-list] implementing the visitor pattern in ocaml"
  prev="2003/10/699b12f0ebe78da74ded3e4cba5c6059"
  next="2003/10/7e77f8b374dfe8fb817bb9c327b8a8b7"
  next-in-thread="2003/10/7e77f8b374dfe8fb817bb9c327b8a8b7"
  prev-thread="2003/10/a568149c03c9796eac20731395a98f3a"
  next-thread="2003/10/4e4b1aa34c29e58e6db93315ea915984"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] implementing the visitor pattern in ocaml">
<msg 
  url="2003/10/90ca861a25ed8e5d1d82dbb9d0fe2021"
  from="Rafael &apos;Dido&apos; Sevilla &lt;dido@i...&gt;"
  author="Rafael &apos;Dido&apos; Sevilla"
  date="2003-10-14T09:11:11"
  subject="[Caml-list] implementing the visitor pattern in ocaml">
<msg 
  url="2003/10/7e77f8b374dfe8fb817bb9c327b8a8b7"
  from="Samuel Lacas &lt;Samuel.Lacas@t...&gt;"
  author="Samuel Lacas"
  date="2003-10-14T10:13:29"
  subject="Re: [Caml-list] implementing the visitor pattern in ocaml">
<msg 
  url="2003/10/d2f71a4af6c422779e3e3b63ba42bcbf"
  from="Didier Remy &lt;remy@m...&gt;"
  author="Didier Remy"
  date="2003-10-14T15:14:30"
  subject="Re: [Caml-list] implementing the visitor pattern in ocaml">
</msg>
</msg>
</msg>
</thread>

<contents>
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 -&gt; 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 &lt; accept : abstractvisitor -&gt; 'a; get_x : int;
.. &gt;
but is here used with type foo = &lt; .. &gt;
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

</contents>

</message>

