Version franaise
Home About Download Resources Contact us
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: -- (:)
From: Jacques Garrigue <garrigue@m...>
Subject: Re: [Caml-list] Recursive parametrized classes bug?
From: Сергей Плаксин <serp@stork.ru>

> >>> cat test.ml
> class type ['a] a  =
>   object
>     method v: 'a
>   end
> and b =
>   object
>     inherit [int] a
>   end
> and c =
>   object
>     inherit [float] a
>   end
> =======
> File "test.ml", 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