Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Optional arguments in inherited methods
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-04-28 (16:56)
From: james woodyatt <jhw@w...>
Subject: Re: [Caml-list] Optional arguments in inherited methods
On 28 Apr 2004, at 09:13, John Goerzen wrote:
> I have this defined in a base class:
>     method private getdata sname oname =  <code here>
> In my subclass, I wish to do this:
>     method private getdata ?(raw=false) ?(idepth=10) ?extravars sname 
> oname = <code>
> The compiler does not seem to like this at all, though I am at a loss 
> to
> explain why.  Can someone help me out?

Presumably, given this in the base class:

	method getdataf sname = <code here returns function> wish the compiler to insure that the default values are used for 
each of the optional arguments in the [possibly partial] evaluation of 
the derived class method.

Well— it doesn't.  You have to define the derived class method in two 

	method private getdata_aux ?(raw=false) ?(idepth=10) ?extravars sname 
oname = <code>
	method private getdata sname oname = self#getdata sname oname

> The error I get is:
> The method getdata has type
>   ?raw:'a -> ?idepth:'b -> ?extravars:'c -> 'd -> 'e -> 'f
>   but is expected to have type string -> string -> string
> So even stranger is that it doesn't set a type for anything, even 
> though
> it has enough information to figure out the type for everything.

Yeah, it's already decided you have a problem before it's finished 
inferring the types of everything.  That might be another one of those 
little annoyances... since inferring types when the code is known to be 
in error is probably a hard problem.

j h woodyatt <>
that's my village calling... no doubt, they want their idiot back.

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: