Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* Weird behavior with mutually recursive type definitions
@ 1999-08-04 13:52 Francois Pottier
  1999-08-12 13:17 ` Hendrik Tews
  1999-08-13  1:42 ` Jacques GARRIGUE
  0 siblings, 2 replies; 9+ messages in thread
From: Francois Pottier @ 1999-08-04 13:52 UTC (permalink / raw)
  To: caml-list


Hello,

I am puzzled by O'Caml 2.02's bizarre behavior regarding mutually recursive
type declarations. 

Let's start by defining a dummy, unary type constructor.

  type 'a dummy = Dummy

(The right-hand side of this definition isn't relevant here; the problem
also shows up when 'a dummy is an abstract type constructor, provided by
a functor argument.)

Then, consider the following type definitions:

  type 'a t = 'a dummy
  type specialized = int t

The first type declaration simply renames ``dummy'' into ``t'', and the second
one creates a specialized instance of it. O'Caml correctly analyzes these
declarations.

Now, here's the problem. Let's change just one word, and make the type
declarations mutually recursive, even though they needn't be:

  type 'a t = 'a dummy
   and specialized = int t

O'Caml still accepts the code, but this time, it constrains 'a to be equal to
int, as if the type constructor t could not be used polymorphically within its
own declaration:

  type 'a t = 'a dummy constraint 'a = int
                       ^^^^^^^^^^^^^^^^^^^
  type specialized = int t

Why is this? Can someone explain, or is it a typechecker bug?

Thanks,

-- 
François Pottier
Francois.Pottier@inria.fr
http://pauillac.inria.fr/~fpottier/




^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~1999-08-30 13:36 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-08-04 13:52 Weird behavior with mutually recursive type definitions Francois Pottier
1999-08-12 13:17 ` Hendrik Tews
1999-08-13  1:42 ` Jacques GARRIGUE
1999-08-16  6:31   ` Francois Pottier
1999-08-16  7:08     ` Jacques GARRIGUE
1999-08-16  7:51       ` More confusion " Francois Pottier
1999-08-16  7:57         ` Jacques GARRIGUE
1999-08-27 11:32     ` Weird behavior " Jerome Vouillon
1999-08-27 10:12   ` Jerome Vouillon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox