* Recursive parametrized classes bug?
@ 2008-09-18 8:31 Сергей Плаксин
2008-09-18 10:12 ` [Caml-list] " Jacques Garrigue
0 siblings, 1 reply; 2+ messages in thread
From: Сергей Плаксин @ 2008-09-18 8:31 UTC (permalink / raw)
To: Caml List
>>> 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
---------------------
Whithou recursion it compiled successfully.
class type ['a] a =
object
method v: 'a
end
class type b =
object
inherit [int] a
end
class type c =
object
inherit [float] a
end
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] Recursive parametrized classes bug?
2008-09-18 8:31 Recursive parametrized classes bug? Сергей Плаксин
@ 2008-09-18 10:12 ` Jacques Garrigue
0 siblings, 0 replies; 2+ messages in thread
From: Jacques Garrigue @ 2008-09-18 10:12 UTC (permalink / raw)
To: serp; +Cc: caml-list
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-09-18 10:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-18 8:31 Recursive parametrized classes bug? Сергей Плаксин
2008-09-18 10:12 ` [Caml-list] " Jacques Garrigue
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox