caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: Gabriel Scherer <gabriel.scherer@gmail.com>
Cc: Roberto Di Cosmo <roberto@dicosmo.org>, 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 15:45:51 +0900	[thread overview]
Message-ID: <8F5F6351-7DF3-4BFD-BE79-6B76696A457C@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <CAPFanBGBbYs2p=4SHPyWyWCpBeko_gy4feonq2eU8NP0jWeo5A@mail.gmail.com>

On 2012/03/23, at 14:52, Gabriel Scherer wrote:

>> 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.
> 
> I'd rather use a warning here. There are enough subtleties with (type
> a b . foo) already, I possible I would be glad not to have to explain
> different scoping rules from the rest of the language.

The point here is that the "type a b. ..." syntax is syntactic sugar.
Rather than putting efforts in making it "hygienic", at the cost of
mangling type variable names, isn't it simpler to define precisely
how it expands, and prohibit ambiguous types?
I would argue that this is actually simpler to explain it that way
(if you want to give an exact specification).

I have committed this in trunk and 4.00, and the output now is a syntax
error:

Error: In this scoped type, variable 'a is reserved for the local type a.

It is of course possible to make it a warning (by doing two passes and generating
fresh names), but I don't see the point: you can always choose your names so
that no conflict happens, so why risk the confusion?
A similar case occurs with value fields in classes: not only you cannot access them
from other value fields, but they actually hide external values.

>> 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.
> 
> That would be quite strange. I already find it dubious that (type a b
> . ....) would escape its natural scope, but our nice old type
> variables had not been affected by those changes yet, and I think it's
> better that they keep their natural meaning of local quantification.

Backward compatibility is of course a concern.
On the other hand, polymorphic methods are not used that often,
and problems only occur with code that is ambiguous to read.

For me the main problem is that it hides the fact those type variables
are really locally abstract types. And the idea behind using locally
abstract types was to avoid introducing yet another kind of type
variable.

> Could we get the type-checker to understand that
>    let rec length (type a) (type b) : (a, b) l -> _ = function ...
> or let rec length (type a) (type b) (li : (a, b) l) = ...
> is polymorphic enough to be a case of polymorphic recursion? This way
> we could get rid of the (type a b . ....) syntax altogether have
> clearer scoping rules.

This is certainly doable, but in my opinion it would not replace the
"type a b. ..." syntax, which is more readable.

> (On my wishlist:   ... (type a) (type b) ... could be written ...
> (type a b) ...)

Easy to do.
Actually I'm not sure why it wasn't defined that way to start with.
Not enough System F-ish?

Jacques Garrigue

  reply	other threads:[~2012-03-23  6:46 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
2012-03-23  5:52   ` Gabriel Scherer
2012-03-23  6:45     ` Jacques Garrigue [this message]
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=8F5F6351-7DF3-4BFD-BE79-6B76696A457C@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=gabriel.scherer@gmail.com \
    --cc=roberto@dicosmo.org \
    /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).