[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Martin Jambon <martin.jambon@e...> |
| Subject: | Re: [Caml-list] default arguments in classes |
Jacques Le Normand wrote:
> Hello list,
> I'm trying to define a method with a default argument, but I keep
> getting an error. Here's the code:
>
> class foo =
> object (self)
> method bar ?(baz="moo") () =
> (new foo)#bar ~baz ()
> end
>
> and the error:
>
> The expression "new foo" has type foo but is used with type
> < bar : baz:string -> unit -> 'a; .. >
> Types for method bar are incompatible
>
> how do I fix this?
Adding type annotations often helps:
class foo =
object (self)
method bar ?(baz="moo") () : unit =
((new foo) # bar : ?baz:_ -> _) ~baz ()
end
Martin
--
http://mjambon.com/