<?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/7fe3f20204f659363005c0e7519c1efd"
  from="Basile Starynkevitch &lt;basile.starynkevitch@i...&gt;"
  author="Basile Starynkevitch"
  date="2003-10-23T12:11:25"
  subject="Re: [Caml-list] Ocaml 3.07+2: no support for optional arguments to classes"
  prev="2003/10/e3a4825e2cfa9c175bbf57ff30c4ac42"
  next="2003/10/6ac7b3927a502e3a4402365b1ea837cc"
  prev-in-thread="2003/10/e3a4825e2cfa9c175bbf57ff30c4ac42"
  next-in-thread="2003/10/6ac7b3927a502e3a4402365b1ea837cc"
  prev-thread="2003/10/b81c85a6b4a6f8d67a06fd08181e888f"
  next-thread="2003/10/31fc9734cb77074b2b1b48ffdc5de321"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] Ocaml 3.07+2: no support for optional arguments to classes">
<msg 
  url="2003/10/e3a4825e2cfa9c175bbf57ff30c4ac42"
  from="Alex Baretta &lt;alex@b...&gt;"
  author="Alex Baretta"
  date="2003-10-23T10:38:08"
  subject="[Caml-list] Ocaml 3.07+2: no support for optional arguments to classes">
<msg 
  url="2003/10/7fe3f20204f659363005c0e7519c1efd"
  from="Basile Starynkevitch &lt;basile.starynkevitch@i...&gt;"
  author="Basile Starynkevitch"
  date="2003-10-23T12:11:25"
  subject="Re: [Caml-list] Ocaml 3.07+2: no support for optional arguments to classes">
<msg 
  url="2003/10/6ac7b3927a502e3a4402365b1ea837cc"
  from="Alex Baretta &lt;alex@b...&gt;"
  author="Alex Baretta"
  date="2003-10-23T15:47:35"
  subject="Re: [Caml-list] Ocaml 3.07+2: no support for optional arguments to classes">
</msg>
</msg>
</msg>
</thread>

<contents>
On Thu, Oct 23, 2003 at 12:37:37PM +0200, Alex Baretta wrote:
&gt; I am unable to get the following code to compile.
&gt; 
&gt; class xcaml_conf : ?string -&gt; ?xcaml_configuration -&gt; 
&gt; Netcgi_types.cgi_activation -&gt;
&gt; object
&gt;   method config : xcaml_configuration
&gt;   method cgi : # Xcaml_cgi.xcaml_cgi_activation
&gt;   method mem : Parse_config.varname -&gt; bool
&gt;   method argument_value : Parse_config.varname -&gt; string
&gt; end
&gt; 

Probably better to ask in:

&gt; Beginner's list: http://groups.yahoo.com/group/ocaml_beginners

Your syntax is wrong: your code is a module interface (ie a signature).
Syntax is similar to declaration of functional types.

The following example compile and works as expected:

(**** file test.mli *****)
class class_with_option : ?name: string -&gt; int -&gt; object 
  method print: unit 
  method descr: string
end;;
(**** end of file test.mli ****)

Compile it with ocamlc -c -g test.mli



(**** file test.ml ****)
class class_with_option ?(name="??") num = object
  val _num : int = num
  method print = Printf.printf "in class_with_option name=%S num=%d\n%!" name _num
  method descr = Printf.sprintf "&lt;class_with_option name=%S num=%d&gt;" name _num
  method private othermeth = _num + 1
end;;

let c1 = new class_with_option ~name: "obj_1" 1;;

let c2 = new class_with_option 2;;

c1#print;;

c2#print;;
(**** end of test.ml ******)

Compile it with ocamlc -c -g test.ml -o _test
and run it with _test.

In a few words, code your interface with:

class xcaml_conf : ?name: string -&gt; ?config: xcaml_configuration -&gt; 
  Netcgi_types.cgi_activation -&gt;
   object
    method config : xcaml_configuration
    method cgi : # Xcaml_cgi.xcaml_cgi_activation
    method mem : Parse_config.varname -&gt; bool
    method argument_value : Parse_config.varname -&gt; string
  end

An additional hint is: avoid reusing names from Pervasives (like int) as
optional labels. Even if it is permitted, I believe it is errorprone.

Regards.
-- 
Basile STARYNKEVITCH -- basile dot starynkevitch at inria dot fr
Project cristal.inria.fr - 
http://cristal.inria.fr/~starynke --- all opinions are only mine 

-------------------
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>

