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: Jacques Garrigue <garrigue@k...>
Subject: Re: problem with optional arguments
From: "Dr. Wolfgang Gehrke" <wgehrke@dia.uniroma3.it>

> 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

The point is that optional arguments, when you do not give a default
value, are of type [t option] rather than [t], so that [?(a:int)]
produces immediately a type clash (int is not compatible with 'a option).
The simplest solution is to specify a default:
        class test2 ?(a:int=2) () = ...
Otherwise, you have to explicitely handle the Some and None cases for
a.

Regards,

Jacques Garrigue
---------------------------------------------------------------------------
Jacques Garrigue      Kyoto University     garrigue at kurims.kyoto-u.ac.jp
		<A HREF=http://wwwfun.kurims.kyoto-u.ac.jp/~garrigue/>JG</A>