caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: Syntax for label, NEW PROPOSAL
@ 2000-03-17 21:33 Damien Doligez
  2000-03-18 21:07 ` Frank Atanassow
  2000-03-18 22:40 ` John Prevost
  0 siblings, 2 replies; 33+ messages in thread
From: Damien Doligez @ 2000-03-17 21:33 UTC (permalink / raw)
  To: caml-list

First of all, I don't think I'm going to use label mode anytime soon,
but the same is true of objects, I haven't looked at variants yet, and
I consider higher-order functors an exotic feature that I'll probably
never need (and I do use double-semicolons).

But that's no reason to go to war against labels.  It's just I'm in
love with the small simple functional language that is at the heart of
O'Caml. As long as I can use it, I'm happy.

Now a few random comments on the discussion.


>From: Don Syme <dsyme@microsoft.com>
>  - No labels inside the arguments of higher order functions.  This 
>    will really confuse new users who try not to use labels!
>    e.g.. no "acc" in the first argument of
>       val fold_right: fun:('b -> acc:'a -> 'a) -> 'b array -> acc:'a -> 'a

But that argument doesn't really work because new users who try not
to use labels will not use label mode.


>o The "just documentation" response doesn't really hold water,
>because if the labels were just documentation, then they would
>different.  For example, "fun", being a keyword, is highly confusing
>and not terribly descriptive - any sensible prototype would probably
>just use "f".

I agree, and I would even go further.  I think the current labeling of
the standard library is way too verbose.  "fun" should not be "func"
or even "fn", but simply "f".  That's the usual name for a generic
function.  Likewise, we should replace char:char with c:char and so
on (maybe even the predicate function in List.for_all should be
labeled f).

Also, in the List module, I found this:

    val nth : 'a list -> pos:int -> 'a

This is really bad design, unless the goal is to confuse the reader
(two different names for the same number).  It should be either

    val nth : 'a list -> n:int -> 'a

or

    val posth : 'a list -> pos:int -> 'a
.

I think we need to develop a systematic set of abbreviations (and a
document to explain it) that will allow us to limit almost all labels
to be at most one character in length.  It would (at least partially)
solve the problem of expression cluttering that we have with the long
labels currently in the library.  As a side-effect, it would also
solve the problem of keywords as labels: there isn't any keyword of
length 1.


>From: Dave Mason <dmason@sarg.Ryerson.CA>
>1) please do not call it ``modern'' mode.  Call it ``label'' mode.

This is an excellent suggestion, and I have implemented it (as of
version 2.99+12) : I replaced the command-line option "-modern" with
"-label".  I kept "-modern" as an alias to "-label" for the time
being, but I certainly hope we'll retire it before we release 3.00.

-- Damien



^ permalink raw reply	[flat|nested] 33+ messages in thread
* RE: Syntax for label, NEW PROPOSAL
@ 2000-03-17 17:03 Don Syme
  2000-03-17 19:24 ` John Prevost
  0 siblings, 1 reply; 33+ messages in thread
From: Don Syme @ 2000-03-17 17:03 UTC (permalink / raw)
  To: 'Jacques Garrigue', 'caml-list@inria.fr'


I really don't see people clamouring for lots of labels in the standard
library (besides the inventors of the language feature, who don't really
count, for lots of obvious reasons - over exposure to the feature, over
familiarity with the label names, a natural bent to program in a particular
way that led them to the feature in the first place, self-selection as
people who think the feature is the best thing ever).

I reiterate my bottom line: only add labels to a particular function if you
can strongly argue that they will actually decrease the number of mistakes
made by typical users that are not already caught by the typechecker.  Don't
argue about "labels being good practice" - programmers don't care about what
someone else sees as good practice (we'd all be using Ada if they did) -
they care about getting 90% of their code right first time, which is what
the Caml type checker already ensures.

That is, you need to argue when and where labels are _good_, and not just
why they are _harmless_.  (And in the world of language design, no extra
language feature is truly harmless).  IMHO, one of the only functions in the
standard library that comes close to needing labels is "blit", and I've
already argued why it's marginal that they are even of much help there.

Four more points:

o The fact that you've had to resort to "modes" at all indicates something
is wrong.  The point about O'Caml is that you shouldn't have to understand
_anything_ about labels, objects, modules or syntax modes to use the system
as a new user.  You shouldn't have to see any labels, nor have to ask "what
are these two modes all about", nor have to try to understand why some of
the arguments have labels and some don't.

o The "just documentation" response doesn't really hold water, because if
the labels were just documentation, then they would different.  For example,
"fun", being a keyword, is highly confusing and not terribly descriptive -
any sensible prototype would probably just use "f".  And C prototypes look
_horrible_ when you have both higher order arguments and argument names.

o A quick poll of 2 of my Standard ML friends down the corridor about what
they think of labels going in the standard library, and they all said
"gross".

o To ensure "living happily together", my feeling is you should leave the
standard library alone (though I could live with 2 or 3 functions having
labels), but go wild with labels and variants in the places were no one
doubts they will be useful.

Cheers!
Don


-----Original Message-----
From: Jacques Garrigue [mailto:garrigue@kurims.kyoto-u.ac.jp]
Sent: 17 March 2000 15:23
To: caml-redistribution@pauillac.inria.fr
Subject: RE: Syntax for label, NEW PROPOSAL


Having seen a number of recent messages against having labels in the
standard library, I have the feeling that there is a lot of confusion
here, and I would like to make a few points clear.

* In default (classic) mode, writing labels is (and will stay) not
  required. For those users that do not like labels, or do not want to
  bother with them, or just are starting to learn ML, labels in the
  standard library are just some form of documentation, like argument
  names in C prototypes.
  Honestly, I have never heard anybody protesting against having
  argument names in C prototypes.

* While not requiring labels, classic mode provides some support for
  them, meaning that casual users can put some labels in their
  programs if they want. This also means that any library written in
  modern mode (where labels matter) will be available with the same
  comfort in both classic and modern mode, and, more interestingly,
  according to the _user_'s taste rather than to the implementor's.

* What we are discussing about is modern mode. This is not pedantic
  mode, this is just another typing discipline. This basically doesn't
  concern people who are not very fond of labels, and will be perfectly
  happy with classic mode.

* Pierre expressed his concern that modern mode would make more
  difficult some nice programming style. I perfectly agree with him,
  but I think this specific problem can be solved without removing
  labels from the library.

Looking at the messages, there are clearly people who prefer (heavily)
labelled style, and others who prefer fewer or no labels. But they all
agree that Caml is and should stay a great _functional_ language.
Let's all live happily together: modern and classic mode are there for
that!

Jacques



^ permalink raw reply	[flat|nested] 33+ messages in thread
* RE: Syntax for label, NEW PROPOSAL
@ 2000-03-15 20:40 Don Syme
  2000-03-17  9:48 ` Jacques Garrigue
  0 siblings, 1 reply; 33+ messages in thread
From: Don Syme @ 2000-03-15 20:40 UTC (permalink / raw)
  To: 'Pierre Weis'; +Cc: caml-list


I agree very much with Pierre's comments.  Labels _do_ get in the way, and
probably shouldn't be used in the standard library in 3.00.

It seems pretty clear to me that a typical programmer only keeps an active
vocabulary of roughly 100-200 identifiers. (I mean identifiers from
libraries they are using but have not written themselves - I think you could
do experiments to confirm the figures, but whatever the range we all know
from experience that it is limited). If you accept that, then think about
the impact that labels have on this budget.  A quick grep reveals around 40
different labels.  It's clearly _much_ better to spend the budget on top
level identifiers rather than labels, because otherwise programmers, even
good ones, just become less effective.  The very presence of labels in the
standard library means that new users will look at them, learn them, try to
use them, and the size of their working set of library functions will
decrease as a result.

For example, using the "blit" function from the new version of the array
library module requires knowing not _one_ identifier but _six_.  An existing
user could still use the unlabelled version, but most new users will use
labels, thinking that this is leading to better code and better programming
(incorrectly, I believe, or at best a marginal improvement).  It's like C++
operator overloading - it looks oh so appealing, and a lot of fun for the
language designer to put in, but it nearly always ends up a waste of time to
use.

That's not to say labels are inappropriate everywhere, but it does explain
why they shouldn't be used on functions which users already use accurately,
or where errors in use are already caught by the type checker.  This is the
fundamental test: do labels help programmers use functions with fewer errors
at _runtime_, and is the advantage sufficient to make up for the extra
"weight" of even having the labels around at all?  Remember Caml won out as
the best ML implementation by being Caml-Light, not
Caml-you-must-be-aware-of-the-intricacies-of-my-features-to-learn-to-use-me
;-)

Thus, I'd argue for even stronger rules than Pierre:
  - Labels are only appropriate where a significant number of users 
    routinely make mistakes when using a function, and it is 
    clear that adding labels would solve the problem.
  - This means no labels on functions with 1 or 2 arguments.
  - This means no labels on functions with 3 arguments unless the 
    types are directly ambiguous (and probably not even then).
  - This means no labels on functions where a natural order exists for the
    arguments.
  - This also means no labels on polymorphic functions such as Hash.add (I
think
    it would be very rare that the typechecker wouldn't spot a misuse of
that
    function)
  - No labels inside the arguments of higher order functions.  This 
    will really confuse new users who try not to use labels!
    e.g.. no "acc" in the first argument of
         val fold_right: fun:('b -> acc:'a -> 'a) -> 'b array -> acc:'a ->
'a

And it's not always clear that labels are such a great help - even in the
case
of Array.blit, users may not use the labelled function 
much more accurately, given the time it takes to look up the label names,
correct the errors in misspelling the labels, and given that there is a
natural 
default rule in functional programming that a source operand 
come before a destination.  Even worse, because the programmer has
to remember the damn label names, there may be another 3 or 4 
library functions that they've never learnt to use at all.

Here's a story: In 1990, a new version of the HOL theorem prover (hol90) was
released.  The re-implementation was quite good, but the implementer made a
major mistake - he used labelled versions (actually SML records) of many,
many functions where nothing was gained by doing so.  This was a complete
waste of time, and was a major factor that lead to the splitting of the HOL
effort between "hol-light" and "HOL98", a split that took years to correct.
As Pierre describes, the object system was carefully designed not to put
people off, and if the standard libraries had been objectified then most
existing users would not have moved to OCaml.

Again, that's not to say I don't like labels - they are clearly useful when
functions take many arguments that have no natural order, and will be a god
send for some APIs.  However using them prolifically in the standard library
in this version is simply a bad idea.  Remember, you can always add them to
the standard library later, but you can't take them away!

Cheers,
Don  


-----Original Message-----
From: Pierre Weis [mailto:Pierre.Weis@inria.fr]
Sent: 15 March 2000 14:10
To: caml-redistribution@pauillac.inria.fr
Cc: caml-list@inria.fr
Subject: Re: Syntax for label, NEW PROPOSAL


[Sorry, no french version for this long message]

Abstract:

A long answer to Jacques's proposal. I do not discuss syntax but
semantic issues of the label extension. My conclusion is to be very
careful in adding labels into the standard libraries, and also state
as a extremely desirable design guideline to keep the usage of higher
order functions as simple as possible.

> *** Proposal
> 
> Objective Caml 3.00 is not yet released, and I believe we can still
> have modifications on this point.

Yes, you're perfectly right, we can still modify several points.
However, I think there are many other points that are more important
than the choice of ``%'' instead of ``:'', which is only cosmetic
after all.

Thus, I would prefer to discuss deeper and more semantic problems:

-- Problem1: labels can be reserved keywords. This is questionable
and it has been strongly criticised by some Caml users, especially when
reading in the code the awful sequence fun:begin fun ...

-- Problem2: labels that spread all over the standard libraries, even
when they do not add any good. I would cite:

   * the labels completely redundant with the types
     (E.g. char:char in the type of String.contains or String.index)

   * undesired labels: in many cases I don't want to have labels just
     because I don't want to remember their names. (E.g., I very often
     mispell the label acc since I've always used accu to name an
     accumulator; furthermore, when I do not mispell this label, I feel
     acc:accu extremely verbose). Also because labels are verbose at
     application.

   * labels that prevent you to use comfortably your traditional functions.
     This is particularly evident for the List.map or List.fold_right
     higher-order functionals.

This last point is a real problem. Compare the usual way of using
functionals to define the sum of the elements of a list:

$ ocaml
        Objective Caml version 2.99+10

# let sum l = List.fold_right ( + ) l 0;;
val sum : int list -> int = <fun>

Clearly application is denoted in ML with only one character: a space.

Now, consider using the so-called ``Modern'' versions of these
functionals, obtained with the -modern option of the compiler:

$ ocamlpedantic
        Objective Caml version 2.99+10

# let sum l = List.fold_right ( + ) l 0;;
                              ^^^^^
This expression has type int -> int -> int but is here used with type 'a
list

Clearly, there is something wrong now! We may remark that the error
message is not that clear, but this is a minor point, since error
messages are never clear enough anyway!

The real problem is that fixing the code makes no good at all to its
readability (at least that's what I would say):

# let sum l = List.fold_right fun:begin fun x acc:y -> x + y end acc:0;;
val sum : 'a -> int list -> int = <fun>

It seems that, in the ``modern'' mode, application of higher order
functions is now denoted by a new kind of parens opening by
``fun:begin fun'' and ending by ``end''. This is extremely explicit
but also a bit heavy (in my mind).

For all these reasons, I would suggest to carefully use labels into
the standard libraries: 

-- remove labels from higher-order functional
-- remove redundant labels: when no ambiguity can occur you need not
   to add a label.
-- use labels when typechecking ambiguity is evident (for instance
when there are two or more parameters with the same type).

Labels must enforce readability of code or help documenting the
libraries, it should not be an extra burden to the programmer and a
way of offuscating code.

Evidently, as any other extension, labels must not offuscate the
overall picture, that is they must not clobber the semantics, nor add
extra exceptional cases to the few general rules we have for the
syntax and semantics of Caml.

In this respect, optional labelled arguments might also be discussed,
particularly for the following facts:

-- syntactically identical patterns and expressions now may have
incompatible types:
   # let f ?style:x _ = x;;
   val f : ?style:'a -> 'b -> 'a option = <fun>

   As a pattern on the left-hand side x has type 'a, while as an
   expression on the right hand side it has type 'a option

-- some expressions can be only written as arguments in an application
   context:
   # let f ?style:x g = ?style:x;;
                        ^
   Syntax error
   # let f ?style:x g = g ?style:x;;
   val f : ?style:'a -> (?style:'a -> 'b) -> 'b = <fun>

-- the simple addition of a default value to an optional argument may
   trigger a typechecking error:

   # let f ?(style:x) g = g ?style:x;;
   val f : ?style:'a -> (?style:'a -> 'b) -> 'b = <fun>

   # let f ?(style:x = 1) g = g ?style:x;;
   This expression has type int but is here used with type 'a option

Do not forget the design decision that has always been used before in
the development of Caml: interesting but not universal extensions to
the language must carefully be kept orthogonal to the core language
and its libraries. This has been successfully achieved for the
important addition of modules (that do not prevent the users from
using the old interface-implementation view of modules) as well as for
the objects system addition that has been also maintained orthogonal
to the rest of the language (in particular the standard library has
never been ``objectified''). I don't know of any reason why labels
cannot follow the same safe guidelines.

> Here is an alternative proposal, to use `%' in place of `:'. Labels
> are kept as a lexical entity. This still breaks some programs, since
> `%' was registered as infix, but this is not so bad.

> Con:
> * I still think that `:' looks better, particularly inside types.
> * On my keyboard I can type in `:' without pressing shift :-)
> * We will need some tool to convert existing code.

I think that % should be the infix integer modulo symbol.

> Do you think it would be better?

No.

> Are there people around who would rather keep `:' ?

Yes. However this is syntax and we have to consider semantics in the
first place.

There are also people around that would like to keep Caml a true
functional language, where usage of higer order functions is easy and
natural.  We have to be careful not to lose what is the actual
strength of the language.

-- 
Pierre Weis

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



^ permalink raw reply	[flat|nested] 33+ messages in thread
* Re: Syntax for label
@ 2000-03-14 16:53 Don Syme
  2000-03-15  3:15 ` Syntax for label, NEW PROPOSAL Jacques Garrigue
  0 siblings, 1 reply; 33+ messages in thread
From: Don Syme @ 2000-03-14 16:53 UTC (permalink / raw)
  To: 'caml-list@inria.fr'

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1358 bytes --]



And why not "as", i.e. "t as x", as I explained once in a previous post.
I never did get an explanation as to why this wasn't an better solution.  It
reuses a rarely-used keyword in a perfectly backward-compatible way.  
I think it's simply a typical case of a new (and not necessarily terribly 
crucial) language feature muscling in on the limited "ultra-convenient" 
concrete syntax that's available!   No offence intended ;-)

Cheers,
Don


-----Original Message-----
From: Christophe Raffalli [mailto:Christophe.Raffalli@univ-savoie.fr]
Sent: 10 March 2000 18:45
To: caml-redistribution@pauillac.inria.fr
Subject: Syntax for label



It is clear that labels are a good thing ...

But why did you use the same character ":" for types and labels !

whit not (for instance) x:t to say that x as type t
and                     l#x to say that x as label l

the syntax l#x:t is much better than l:x : t !!

I know that # is allready used for methods ... but some characters are
still usable:

~
£ it looks like the l of labels (but its ascii code is greater than 128,
but is this really a problem ? probably ?)

-- 
Christophe Raffalli
Université de Savoie
Batiment Le Chablais, bureau 21
73376 Le Bourget-du-Lac Cedex

tél: (33) 4 79 75 81 03
fax: (33) 4 79 75 87 42
mail: Christophe.Raffalli@univ-savoie.fr
www: http://www.lama.univ-savoie.fr/~RAFFALLI



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

end of thread, other threads:[~2000-03-24 15:19 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-03-17 21:33 Syntax for label, NEW PROPOSAL Damien Doligez
2000-03-18 21:07 ` Frank Atanassow
2000-03-18 22:40 ` John Prevost
  -- strict thread matches above, loose matches on Subject: below --
2000-03-17 17:03 Don Syme
2000-03-17 19:24 ` John Prevost
2000-03-15 20:40 Don Syme
2000-03-17  9:48 ` Jacques Garrigue
2000-03-17 17:34   ` Dave Mason
2000-03-18  0:26     ` Jacques Garrigue
2000-03-23 13:07       ` Sven LUTHER
2000-03-14 16:53 Syntax for label Don Syme
2000-03-15  3:15 ` Syntax for label, NEW PROPOSAL Jacques Garrigue
2000-03-15  6:58   ` Christophe Raffalli
2000-03-15 21:54     ` Julian Assange
2000-03-15 11:56   ` Wolfram Kahl
2000-03-15 13:58   ` Pierre Weis
2000-03-15 15:26     ` Sven LUTHER
2000-03-17  7:44       ` Pierre Weis
2000-03-15 17:04     ` John Prevost
2000-03-17 10:11       ` Jacques Garrigue
2000-03-15 17:06     ` Markus Mottl
2000-03-15 19:11     ` Remi VANICAT
2000-03-17  8:30       ` Pierre Weis
2000-03-17 14:05         ` Jacques Garrigue
2000-03-17 16:08           ` Pierre Weis
2000-03-15 21:30     ` John Max Skaller
2000-03-16  2:55     ` Jacques Garrigue
2000-03-17 15:13       ` Pierre Weis
2000-03-17 17:33         ` Wolfram Kahl
2000-03-18 11:59         ` Jacques Garrigue
2000-03-21 16:51       ` Pascal Brisset
2000-03-23 11:14         ` Nicolas barnier
2000-03-16  8:50     ` Pascal Brisset
2000-03-17 11:15       ` Sven LUTHER

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).