Re: Weird behavior with mutually recursive type definitions

From: Hendrik Tews (tews@tcs.inf.tu-dresden.de)
Date: Thu Aug 12 1999 - 15:17:43 MET DST


Date: Thu, 12 Aug 1999 15:17:43 +0200
Message-Id: <199908121317.PAA27233@ithif20.inf.tu-dresden.de>
From: Hendrik Tews <tews@tcs.inf.tu-dresden.de>
To: Francois Pottier <Francois.Pottier@inria.fr>
Subject: Re: Weird behavior with mutually recursive type definitions
In-Reply-To: <19990804155239.50895@pauillac.inria.fr>

Francois Pottier writes:

   Date: Wed, 4 Aug 1999 15:52:39 +0200
   Subject: Weird behavior with mutually recursive type definitions
   
   [...]

     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?
   
A few month ago we run into the same problem. From a private
conversation with Jacques Garrigue I understood, that the above
behavior is actually a feature of the typechecker, because there
is no better solution known at the moment. :-(

We solved the problem by eliminating type abbreviations (by
replacing it with its expansion) until these constraints
vanished. (You can use option ocamlc -i on your code to see which
constraints are generated.) The elimination of the abbreviations
leads to ugly and unreadable code, but it works at least.

Hope this helps,

Hendrik



This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:24 MET