Version franaise
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
Recursive parametrized classes bug?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-09-18 (10:12)
From: Jacques Garrigue <garrigue@m...>
Subject: Re: [Caml-list] Recursive parametrized classes bug?
From: Сергей Плаксин <>

> >>> cat
> class type ['a] a  =
>   object
>     method v: 'a
>   end
> and b =
>   object
>     inherit [int] a
>   end
> and c =
>   object
>     inherit [float] a
>   end
> =======
> File "", line 15, characters 13-18:
> The type parameter float does not meet its constraint: it should be int

The reason is simple enough: for classes and class types, the
parameter are only generalized once the definition is finished.
As a result, using a parameterized class type inside a recursive
definition introduces constraints on parameters.

The classical workaround is to break the recursion (when needed) by
adding more parameters. Another trick is to use recursive modules, but
this is actually more verbose, and rather fragile as constraints on
recursive modules can be subtle.

Jacques Garrigue