Version française
Home     About     Download     Resources     Contact us    
Browse thread
problem with optional arguments
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Remi VANICAT <remi.vanicat@l...>
Subject: Re: problem with optional arguments
"Dr. Wolfgang Gehrke" <wgehrke@dia.uniroma3.it> writes:

> Hello,
> 
> could someone advice me how to resolve the following problem:
> 
> The following works fine:
> 
> class test1 ~(a:int) () =
>   object
>     val a = abs a
>     method a = a
>     method strange x = new test1 ~a:x ()
>   end
> 
> let t1 = new test1 ~a:(-10) ()
> 
> But on the other hand with an optional argument it does not compile,
> neither:
> 
> class test2 ?(a:int) () =
>   object
>     val a = abs a
>     method a = a
>     method strange x = new test2 ~a:x ()
>   end

it's seem normal, which value have a if the optional argument is not
given ? in fact, ?a avec type 'a option, you should give a default
value. then there is another problem :

class test2 ?(a=0) () =
   object
     val a = abs a
     method a = a
     method strange x = new test2 ~a: x ()
   end

don't work, but i don't see realy why (the message of error is :

The expression "new test2" has type ?a:int -> unit -> test2
but is used with type 'a -> unit -> 'b
)

but 

class test2 ?(a=0) () =
   object
     val a = abs a
     method a = a
     method strange x = new test2 ?a: (Some x) ()
   end

work, and let you see that the argument of an optional argument is
realy of type something option


-- 
Rémi Vanicat
vanicat@labri.u-bordeaux.fr
http://dept-info.labri.u-bordeaux.fr/~vanicat