Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] classes and labels
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Gerd Stolpmann <gerd@g...>
Subject: Re: [Caml-list] classes and labels
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