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
[Caml-list] Type inference + optional parameters
[ 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: [Caml-list] Type inference + optional parameters
> On Wed, 3 Sep 2003, Jacques Garrigue wrote:
> > From: Christoph Bauer <>
> >
> > > ocamls type inference uses information of optionl arguments. This
> > > results in a strange behaviour.
> >
> > Brian Rogoff already answered this one. Do you seriously expect a
> > type-safe compiler to simply ignore the type of the default value :-)
> I guess the original question is not that naive. It would be possible to
> have a type system with an extension like your multimatch, to make the
> type of the result of a function depend on the presence/absence of
> optional argument.
> With a crazy syntax to express conditional unification constraints, you
> could write for instance:
> do_with_opt_conv: ?conv:('a -> 'b  orelse 'b = 'a) -> 'a -> 'b
> meaning that in the absence of the optional argument, the result type
> must be unified with the argument type (there are more constraints
> when the optional argument is not provided).
> Does it make sense ?

It makes sense, and is just a direct consequence of the Default module
I was describing in my mail. I've already considered it 4 years ago,
after a comment for Wolfram Kahl.
However, if you let this behaviour be active with all default
parameters, you end up with overly general types; usually you expect
the concrete argument to be of the same type as the default.
Moreover, there may be hidden pitfalls: type incompatibilities you
only detect later, when several optional parameters are omitted

All in all, I think that this feature is just on the borderline of
practical typing: possible, but the typing is too complex for casual
use, and may result in confusing type errors.
In some cases being explicit simplifies lots of things...

Jacques Garrigue

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: