Re: Type-checking bug (or feature?) in O'Caml 1.06

From: Pierre Weis (weis@pauillac.inria.fr)
Date: Wed Nov 19 1997 - 10:39:33 MET


From: Pierre Weis <weis@pauillac.inria.fr>
Message-Id: <199711190939.KAA07393@pauillac.inria.fr>
Subject: Re: Type-checking bug (or feature?) in O'Caml 1.06
In-Reply-To: <mlzpn2rpij.fsf@mario.cs.cornell.edu> from Paul Stodghill at "Nov 18, 97 02:05:56 pm"
To: stodghil@cs.cornell.edu (Paul Stodghill)
Date: Wed, 19 Nov 1997 10:39:33 +0100 (MET)

> The new behavior is even more bizarre than I had first thought.
>
> ---------------------------------------------------------------------------
> % cat foo.mli
> type ('a, 'b) t;;
> val iter: ('a -> 'b -> 'unit) -> ('a, 'b) t -> unit
[...]
> % ocamlc -v -i -c foo.mli
> [...]
> val iter : ('a -> 'b -> 'c) -> ('a, 'b) t -> unit
>
> Why is the generated type different than the declared type?

It is not, since you declared iter with the same type scheme:

> val iter: ('a -> 'b -> 'unit) -> ('a, 'b) t -> unit
                         ^

the ' symbole turns out 'unit to be a type variable. Free variables
<I>names</I> in type schemes are irrelevant (as for functions
abstracted arguments in programs). Thus, in its messages, the compiler
generates new names for type variables as 'a, 'b, 'c, ..., and
the original names written in the source programs are forgotten.
For instance:

# type ('key, 'assoc_val) t = ('key * 'assoc_val) list;;
type ('a, 'b) t = ('a * 'b) list

Thus, the declared type scheme and the generated type scheme are equivalent.

Best regards,

Pierre Weis

INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/



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