caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Future of labels, and ideas for library labelling
Date: Tue, 10 Apr 2001 12:37:56 +0900	[thread overview]
Message-ID: <20010410123756H.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <4.3.2.7.2.20010409124220.00d4a810@shell16.ba.best.com>

[ Disclaimer: you can safely skip this message if you are not
  interested in labels. It is about modalities of use for people who
  want them. ]

To summarize recent posts by various people, there are two approaches
for a universal mode:

* Take the label mode as a basis, and split libraries where needed to
  avoid troubling non-labellers.
  Labels, when present, are no longer optional.

* Extend classic mode with commutation, and keep labels in libraries.
  Labels are kept optional.

Now let me explain what is the trouble with the second option.
To put it simply: you cannot have commutation, first class
functions, type inference, and allow discarding of labels in
unification.
People presented other languages more flexible with labels, but all
these languages had neither type inference nor first class functions.

Why is it so: type inference is based on unification. If you allow
discarding labels during unification, then the notion of what is a
labelled argument becomes fundamentally ambiguous.
In the most simplistic way (what is currently done in classic mode),
the type of a function variable will be non-deterministically taken
from the possible types inferred for this function. Imagine the
context gives both "f : a:int -> b:int -> int" and "f : b:int -> a:int
-> int". For labels to be really optional, you have to accept unifying
these two types, taking for the type of f one of these two.
This is not (too) ambiguous in current classic mode, since anyway
positional order is fixed, but if you allow commutation, then this is
not only the type which is non-deterministic, but also the result of
your function!

The situation might be improved a bit by using subtyping in place of
unification (which is known as very hard to infer!), but even then it
would still mean that the semantics use overloading, and we cannot
have a clean untyped semantics as is currently the case. Consider (f :
a:int -> a:int -> int). If we forget labels selectively, we can both
obtain (f : a:int -> int -> int) and (f : int -> a:int -> int),
meaning that the semantics of (f 1 ~a:2) depends on a notion of what
is the current type of f. Also, subtyping changes direction on left
sides of arrows, so this wouldn't be enough to make labels fully
optional.


So, is there no way out?
Not completely, if we accept to start from strict unification:
function types can be unified only if they bear identical labels.
This is the first option: starting from label mode.
But then, we can be more lenient:
  If only non-labelled arguments are given, and if their number
  matches the arity of the function, then the type checker
  automatically adds missing labels.
This is more or less what Chris Hecker is asking for.

What is nice about it: the semantics need not be changed, the only
thing the type checker does is adding labels in completely unambiguous
cases, where there is only one way to add them, and not adding them
would make typing fail. This makes efficient use of the fact order of
arguments in function types is fixed in ocaml (contrary to olabl).

This departs slightly from the pure untyped semantics for the source
program (semantics applies on a completed program), so that there
should be a way to turn on a warning, to make sure one's program is
complete, and pure semantics apply directly to the source. This
corresponds to the idea of having strict labels has a submode of
default mode.

Are there people who would _not_ be satisfied by such an approach?

A point of detail: this would _not_ solve the fold problem.  For two
reasons. One is that unification is kept strict, so the function you
pass to fold should have the right labels. And more specifically, you
wouldn't even be able to omit labels in the call of fold itself:
since fold has its return argument of polymorphic type, its arity is
not known, and we cannot tell whether an application is complete or
not. (One could accept this case on the ground that the ambiguity is
really minor, but the ambiguity exists.)
Anyway, I really think this discussion around fold and higher-order
functions is pointless: I'd rather let people use the labeled or the
non-labeled form according to their taste, than deciding what is the
right one for everybody. Frank Atanassow made a very interesting
contribution on this subject, on how the same person may both
appreciate programming by combinators (without labels), and also a
more imperative style (with commuting labels).

Cheers,

Jacques Garrigue
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


  reply	other threads:[~2001-04-10  3:38 UTC|newest]

Thread overview: 76+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-31  3:40 [Caml-list] Future of labels Yaron M. Minsky
2001-04-02  3:39 ` [Caml-list] Future of labels, and ideas for library labelling Jacques Garrigue
2001-04-02  7:58   ` Judicael Courant
2001-04-02  8:50     ` Markus Mottl
2001-04-02 10:33     ` kahl
2001-04-03  0:35       ` Jacques Garrigue
2001-04-03  1:36         ` Kipton M Barros
2001-04-03  1:52         ` Patrick M Doane
2001-04-03  3:53           ` Jacques Garrigue
2001-04-03  5:10             ` Patrick M Doane
2001-04-03  9:30               ` Jacques Garrigue
2001-04-03  8:52             ` Xavier Leroy
2001-04-03  9:34               ` Judicael Courant
2001-04-03  9:54               ` Jacques Garrigue
2001-04-03 12:59                 ` Jean-Christophe Filliatre
2001-04-03 13:11                   ` [Caml-list] ocaml, java, rmi and jini Martin Berger
2001-04-03 19:23                     ` Chris Hecker
2001-04-03 20:50                       ` Gerd Stolpmann
2001-04-06  9:40                         ` Sven LUTHER
2001-04-06 20:57                           ` Gerd Stolpmann
2001-04-03 21:06                       ` martinb
2001-04-06 15:03                     ` Xavier Leroy
2001-04-03 14:06                   ` [Caml-list] Future of labels, and ideas for library labelling Jacques Garrigue
2001-04-03 14:12                     ` Daniel de Rauglaudre
2001-04-03 14:42                       ` Claude Marche
2001-04-04 19:18                     ` Gerd Stolpmann
2001-04-03  9:55               ` Ohad Rodeh
2001-04-03 18:06                 ` [Caml-list] Example of Ocaml-syntax problem with ; Mattias Waldau
2001-04-04 15:15                 ` [Caml-list] Suspending threads Ohad Rodeh
2001-04-04 17:28                   ` Vitaly Lugovsky
2001-04-06 13:21                   ` Xavier Leroy
2001-04-03 12:02               ` [Caml-list] Future of labels, and ideas for library labelling Dave Mason
2001-04-03 13:43               ` Francois-Rene Rideau
2001-04-03 14:23                 ` Daniel de Rauglaudre
2001-04-03 13:43               ` Frank Atanassow
2001-04-03 13:58               ` Joshua D. Guttman
2001-04-03 16:52               ` Eric C. Cooper
2001-04-09  9:05                 ` John Max Skaller
2001-04-09  7:29             ` John Max Skaller
2001-04-03  8:07         ` Judicael Courant
2001-04-03  6:55     ` Chris Hecker
2001-04-03 18:13       ` [Caml-list] Generics? Brian Rogoff
2001-04-03 20:12         ` Chris Hecker
2001-04-10 16:48           ` John Max Skaller
2001-04-09  8:11       ` [Caml-list] Future of labels, and ideas for library labelling John Max Skaller
2001-04-09  9:21         ` Jacques Garrigue
2001-04-09 15:06           ` Fergus Henderson
2001-04-10 18:49           ` John Max Skaller
2001-04-09 19:54         ` Chris Hecker
2001-04-10  3:37           ` Jacques Garrigue [this message]
2001-04-10  7:42             ` Judicael Courant
2001-04-10  8:25               ` Jacques Garrigue
2001-04-10  8:46               ` Claude Marche
2001-04-10 10:09                 ` Jacques Garrigue
2001-04-10 14:42                   ` Lionnel Maugis
2001-04-10  9:06             ` François-René Rideau
2001-04-11 15:34               ` Jacques Garrigue
2001-04-11 17:48                 ` Dave Mason
2001-04-12 12:39                 ` [Caml-list] How do I define prog1? Mattias Waldau
2001-04-12 14:22                   ` Vitaly Lugovsky
2001-04-12 17:53                     ` William Chesters
2001-04-12 15:15                   ` Sven LUTHER
2001-04-12 16:14                     ` Mattias Waldau
2001-04-12 15:21                   ` Maxence Guesdon
2001-04-12 15:47                   ` Stefan Monnier
2001-04-17 20:04                     ` Chris Hecker
2001-04-10 22:43             ` [Caml-list] Future of labels, and ideas for library labelling Brian Rogoff
2001-04-11  8:29               ` Jacques Garrigue
2001-04-11  9:44                 ` Anton Moscal
2001-04-11 13:16                 ` Didier Remy
2001-04-11 15:11                   ` Jacques Garrigue
2001-04-03  7:27 Arturo Borquez
2001-04-03 16:39 John R Harrison
2001-04-04 16:37 Dave Berry
2001-04-11 10:48 Francois-Rene Rideau
2001-04-17 11:53 Poigné

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=20010410123756H.garrigue@kurims.kyoto-u.ac.jp \
    --to=garrigue@kurims.kyoto-u.ac.jp \
    --cc=caml-list@inria.fr \
    /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).