caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Funny name for a type variable in the output: should this be filed on the BTS?
@ 2012-03-22  9:51 Roberto Di Cosmo
  2012-03-22 12:05 ` Julien Signoles
  2012-03-22 22:12 ` Jacques Garrigue
  0 siblings, 2 replies; 11+ messages in thread
From: Roberto Di Cosmo @ 2012-03-22  9:51 UTC (permalink / raw)
  To: caml-list

I was playing around some more with GADTs, preparing my next course
on functional programming, and came across an example on
which the type checker outputs a type containing a funny name
for a type variable. 

I do not know if this qualifies as a bug, so before filing it, I'd
love some feedback.

Here we are: I am writing an example to show how one can code
a well typed length function for empty/nonempty list; we start
with the type definition

 type empty
 type nonempty

 type ('a, 'b) l =
     Nil : (empty, 'b) l
   | Cons : 'b * ('a, 'b) l -> (nonempty, 'b) l;;

then we move on to the length function

 let rec length : type a b. (a,b) l -> 'a = function 
   | Nil -> 0 
   | (Cons (_,r)) -> 1+ (length r);;

Hey, you say, the natural type to declare for length should be

   type a b. (a,b) l -> int

but as you see, for some mysterious reason I ended
up writing something silly (dont ask why, I am just
very well known to step on strange bugs as easily
as I breath)

   type a b. (a,b) l -> 'a

The type checker is happy anyway: 'a will be instantiated
to int, and the declaration of length is accepted... but now
look at the output type

   val length : ('a1, 'b) l -> int = <fun>

Why do we get 'a1, and not 'a, in the type?

Well, probably, since 'a is instantiated to int during
type checking, it may be the case that 'a, as type name, is
still marked as taken during the type output, so we get ('a1,'b)

The type is perfectly sound... it is just 'surprising' for
a regular user... do you think this should be considered a bug?

--Roberto
 
------------------------------------------------------------------
Professeur               En delegation a l'INRIA
PPS                      E-mail: roberto@dicosmo.org
Universite Paris Diderot WWW  : http://www.dicosmo.org
Case 7014                Tel  : ++33-(0)1-57 27 92 20
5, Rue Thomas Mann       
F-75205 Paris Cedex 13   Identica: http://identi.ca/rdicosmo
FRANCE.                  Twitter: http://twitter.com/rdicosmo
------------------------------------------------------------------
Attachments:
MIME accepted, Word deprecated
      http://www.gnu.org/philosophy/no-word-attachments.html
------------------------------------------------------------------
Office location:
 
Bureau 6C08 (6th floor)
175, rue du Chevaleret, XIII
Metro Chevaleret, ligne 6
------------------------------------------------------------------                                                 


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

end of thread, other threads:[~2012-03-24  0:24 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-22  9:51 [Caml-list] Funny name for a type variable in the output: should this be filed on the BTS? Roberto Di Cosmo
2012-03-22 12:05 ` Julien Signoles
2012-03-22 13:39   ` Jonathan Protzenko
2012-03-22 14:40     ` Didier Remy
2012-03-22 22:12 ` Jacques Garrigue
2012-03-22 23:35   ` Roberto Di Cosmo
2012-03-23  5:52   ` Gabriel Scherer
2012-03-23  6:45     ` Jacques Garrigue
2012-03-23  8:13       ` Roberto Di Cosmo
2012-03-23 10:25       ` Gabriel Scherer
2012-03-24  0:24         ` Jacques Garrigue

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).