Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: 2000-09-21 (07:38)
From: Jacques Garrigue <garrigue@k...>
Subject: Re: problem with optional arguments
From: "Dr. Wolfgang Gehrke" <>

> 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


Jacques Garrigue
Jacques Garrigue      Kyoto University     garrigue at
		<A HREF=>JG</A>