caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Ocaml 3.07+2: no support for optional arguments to classes
@ 2003-10-23 10:37 Alex Baretta
  2003-10-23 12:11 ` Basile Starynkevitch
  0 siblings, 1 reply; 3+ messages in thread
From: Alex Baretta @ 2003-10-23 10:37 UTC (permalink / raw)
  To: Ocaml

I am unable to get the following code to compile.

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

Apparently neither the ocamlc parser nor camlp4o accept optional 
arguments to classes. Is this in any way desirable or is this just an 
ommission which could be fixed in the next release?

Alex

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] Ocaml 3.07+2: no support for optional arguments to classes
  2003-10-23 10:37 [Caml-list] Ocaml 3.07+2: no support for optional arguments to classes Alex Baretta
@ 2003-10-23 12:11 ` Basile Starynkevitch
  2003-10-23 15:47   ` Alex Baretta
  0 siblings, 1 reply; 3+ messages in thread
From: Basile Starynkevitch @ 2003-10-23 12:11 UTC (permalink / raw)
  To: Alex Baretta; +Cc: caml-list

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

Probably better to ask in:

> 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 -> int -> 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 "<class_with_option name=%S num=%d>" 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 -> ?config: xcaml_configuration -> 
  Netcgi_types.cgi_activation ->
   object
    method config : xcaml_configuration
    method cgi : # Xcaml_cgi.xcaml_cgi_activation
    method mem : Parse_config.varname -> bool
    method argument_value : Parse_config.varname -> 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] Ocaml 3.07+2: no support for optional arguments to classes
  2003-10-23 12:11 ` Basile Starynkevitch
@ 2003-10-23 15:47   ` Alex Baretta
  0 siblings, 0 replies; 3+ messages in thread
From: Alex Baretta @ 2003-10-23 15:47 UTC (permalink / raw)
  To: Ocaml

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

> class xcaml_conf : ?name: string -> ?config: xcaml_configuration -> 
>   Netcgi_types.cgi_activation ->
>    object
>     method config : xcaml_configuration
>     method cgi : # Xcaml_cgi.xcaml_cgi_activation
>     method mem : Parse_config.varname -> bool
>     method argument_value : Parse_config.varname -> 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.

Duh... I feel so stupid. I'm sorry for having bugged the list.

Alex

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-10-23 15:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-23 10:37 [Caml-list] Ocaml 3.07+2: no support for optional arguments to classes Alex Baretta
2003-10-23 12:11 ` Basile Starynkevitch
2003-10-23 15:47   ` Alex Baretta

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).