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] Optional arguments in inherited methods
[ 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] Optional arguments in inherited methods
From: John Goerzen <>

> Argh.  Does OCaml's object system really not support adding additional
> optional variables to subclass methods?

No, it doesn't support that.
Methods in subclasses must have exactly the same type as in the
superclass (the types are unified during checking).
So you are not even allowed to use a subtype of the original method
type (which would be perfectly sound in theory)

> That would be rather annoying if true.

Unfortunate, but in the case of optional arguments the problem is
not with typing but with how they are implemented: an optional
argument of type [t] is actually a non-optional argument of type [t
option]. They disappear automagically on application, but this means
that None's are automatically inserted. So applying a function which has
optional arguments is completely different from a function without
them (even if the function call looks the same in your source code).

Jacques Garrigue

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