caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Roberto Di Cosmo <roberto@dicosmo.org>
To: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Funny name for a type variable in the output: should this be filed on the BTS?
Date: Fri, 23 Mar 2012 00:35:56 +0100	[thread overview]
Message-ID: <20120322233556.GA23754@voyager> (raw)
In-Reply-To: <AA1FC020-B493-4E08-B3C4-96EA80F747EC@math.nagoya-u.ac.jp>

Dear Jacques,
     thanks for having looked into this issue and explaining its origin:
if I understand well, this comes from a combination of two mechanisms
 
 (1) the desugaring of type a b. (a,b) l -> 'a into 'a1 'b. ('a1,'b) l -> 'a 
     that introduces the 'a1
  
 (2) the fact that the output type strives to respect the type variable
     names used in the user code : this brings the 'a1 over to the
     output type

I think (2) is a useful feature: it may be hepful to see immediately
where a type variable comes from.

I would probably, as you did, point my finger at (1): the trouble seems
to come from the fact that we can intermix unquoted type variables and
quoted type variables in the same type.

One may have very legitimate reasons to want an 'a in the type 

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

but of course we do not expect a and 'a to be the same variable...

--Roberto



On Fri, Mar 23, 2012 at 07:12:52AM +0900, Jacques Garrigue wrote:
> On 2012/03/22, at 18:51, Roberto Di Cosmo wrote:
<snip>
> > type empty
> > type nonempty
> > 
> > type ('a, 'b) l =
> >     Nil : (empty, 'b) l
> >   | Cons : 'b * ('a, 'b) l -> (nonempty, 'b) l;;
> > 
<snip>
> > let rec length : type a b. (a,b) l -> 'a = function 
> >   | Nil -> 0 
> >   | (Cons (_,r)) -> 1+ (length r);;
> > 
<snip>
> > look at the output type
> > 
> >   val length : ('a1, 'b) l -> int = <fun>
> > 
<snip>
> > The type is perfectly sound... it is just 'surprising' for
> > a regular user... do you think this should be considered a bug?
> 
> Well, since there is no specification whatsoever about type variable names
> in the output, this is hard to call it a bug.
> On the other hand, you were surprised, so something is probably wrong.
> 
> After thinking a bit more about it, actually the problem is not in the printer,
> as everybody assumed, but in the parser.
> Namely, 
> 
> 	... : type a b. (a,b) l -> 'a = ...
> 
> is just syntactic sugar for
> 
> 	... : 'a1 'b. ('a1,'b) l -> 'a = fun (type a) (type b) -> (... : (a,b) l -> 'a)
> 
> Now you see where 'a1 appears: since there is already an 'a in the type,
> we cannot use 'a for the fresh abstract type a.
> 
> However, as you already mentioned, the original type itself was erroneous.
> So a better solution would be to get an error at that point.
> Namely, if the type annotation contains a type variable with the same name
> as one of the quantified types.
> Does it sound reasonable.
> 
> At times I wonder whether the "type a b. ...." syntax is the right approach.
> Another approach would be to change the meaning of
>   ... : 'a 'b. ('a,'b) l -> 'a = ...
> to have 'a and 'b defined in the right hand side.
> The trouble is that we still need the locally abstract types internally, so this
> could be confusing.
> Also this could break some existing programs using polymorphic methods.
> 
> 	Jacques Garrigue

-- 
--Roberto Di Cosmo
 
------------------------------------------------------------------
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
------------------------------------------------------------------                                                 

  reply	other threads:[~2012-03-22 23:32 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-22  9:51 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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120322233556.GA23754@voyager \
    --to=roberto@dicosmo.org \
    --cc=caml-list@inria.fr \
    --cc=garrigue@math.nagoya-u.ac.jp \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).