* [Caml-list] classes and labels
@ 2001-03-20 15:02 wester
2001-03-20 22:11 ` Gerd Stolpmann
2001-03-21 0:06 ` Jacques Garrigue
0 siblings, 2 replies; 3+ messages in thread
From: wester @ 2001-03-20 15:02 UTC (permalink / raw)
To: caml-list
Hi,
I have the class definition:
# class myclass ?(n=0) () =
object
val nn = n;
method get_nn = nn
method clone (na: int) = let (mc: myclass) = new myclass ~n:na () in mc;
end;;
that produces the following error message in the toplevel:
Characters 5-153:
The expression "new myclass" has type ?n:int -> unit -> myclass
but is used with type int -> unit -> myclass
Can sombody tell what is wrong with my class definition?
I would be very apprecitative for any help.
With kind regards
Rolf Wester
-------------------------------------
Rolf Wester
wester@ilt.fhg.de
-------------------
To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] classes and labels
2001-03-20 15:02 [Caml-list] classes and labels wester
@ 2001-03-20 22:11 ` Gerd Stolpmann
2001-03-21 0:06 ` Jacques Garrigue
1 sibling, 0 replies; 3+ messages in thread
From: Gerd Stolpmann @ 2001-03-20 22:11 UTC (permalink / raw)
To: wester, caml-list
On Tue, 20 Mar 2001, wester@ilt.fhg.de wrote:
>Hi,
>
>I have the class definition:
>
># class myclass ?(n=0) () =
> object
> val nn = n;
> method get_nn = nn
> method clone (na: int) = let (mc: myclass) = new myclass ~n:na () in mc;
>end;;
>
>that produces the following error message in the toplevel:
>
> Characters 5-153:
>The expression "new myclass" has type ?n:int -> unit -> myclass
>but is used with type int -> unit -> myclass
>
>Can sombody tell what is wrong with my class definition?
Nothing. It is a restriction of O'Caml 3.00. Your class definition works fine
in 3.01. If you cannot upgrade, this is the workaround:
# class myclass ?(n=0) () =
object
val nn = n;
method get_nn = nn
method clone (na: int) =
let (mc: myclass) = new myclass ?n:(Some na) () in mc;
end;;
Gerd
--
----------------------------------------------------------------------------
Gerd Stolpmann Telefon: +49 6151 997705 (privat)
Viktoriastr. 100
64293 Darmstadt EMail: gerd@gerd-stolpmann.de
Germany
----------------------------------------------------------------------------
-------------------
To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] classes and labels
2001-03-20 15:02 [Caml-list] classes and labels wester
2001-03-20 22:11 ` Gerd Stolpmann
@ 2001-03-21 0:06 ` Jacques Garrigue
1 sibling, 0 replies; 3+ messages in thread
From: Jacques Garrigue @ 2001-03-21 0:06 UTC (permalink / raw)
To: wester; +Cc: caml-list
From: wester@ilt.fhg.de
> class myclass ?(n=0) () =
> object
> val nn = n;
> method get_nn = nn
> method clone (na: int) = let (mc: myclass) = new myclass ~n:na () in mc;
> end;;
>
> that produces the following error message in the toplevel:
>
> Characters 5-153:
> The expression "new myclass" has type ?n:int -> unit -> myclass
> but is used with type int -> unit -> myclass
What version of ocaml are you using ?
At least, I couldn't reproduce the problem with 3.01:
Objective Caml version 3.01
# class myclass ?(n=0) () =
object
val nn = n;
method get_nn = nn
method clone (na: int) = let (mc: myclass) = new myclass ~n:na () in mc;
end;;
class myclass :
?n:int ->
unit ->
object val nn : int method clone : int -> myclass method get_nn : int end
And this both with the -labels option on and off.
By the way, you don't need all these annotations in the clone method:
method clone na = new myclass ~n:na ()
Regards,
Jacques Garrigue
-------------------
To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2001-03-22 8:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-20 15:02 [Caml-list] classes and labels wester
2001-03-20 22:11 ` Gerd Stolpmann
2001-03-21 0:06 ` Jacques Garrigue
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox