From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: checker@d6.com
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] labels and optional arguments in 3.06
Date: Thu, 14 Nov 2002 17:23:07 +0900 [thread overview]
Message-ID: <20021114172307R.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <4.3.2.7.2.20021113204718.031fa750@localhost>
From: Chris Hecker <checker@d6.com>
> >Indeed, that would leave no ambiguity. So it might be ok to allow
> >mixing labelled optional arguments in an otherwise unlabelled
> >application, if there is no ambiguity on labels. But is it really
> >worth a strange definition, when the workaround is just to add
> >parentheses?
>
> I appreciate your point here about compiler complexity, but I'd say the
> answer is yes. The parentheses just add to the syntactic mess, they don't
> help with it and make things clearer (which is the original point of
> labels). It's preferable to just not use the labels than to bizarrely
> parenthesize functions, I think. Imagine reading some code and looking at
> a function call with parentheses like that, knowing that currying makes it
> so there's no need for them if there were no labels. You'd have to stop
> and think about what was going on. So, I'd say that's a readability
> lose. It'd be better to just punt the labels and optional arguments
> altogether, because at least then the code is "normal".
This is indeed the simplest answer: if you don't intend to put labels
in your code, you can do without them on non-optional arguments.
But you don't have to punt optional arguments altogether. This problem
only appears when you have labelled arguments AND optional arguments
AND you don't want to label the labelled arguments in your function
application.
And if your concern is really readability, I maintain: more verbose
(in reasonable limits) is more readable, and writing those labels
in applications cannot be an inconvenient when reading your code.
Languages like smalltalk have only compulsory labels.
> How hard would it be to implement this rule?
The trouble is that the rule is not unique.
A possible one (and easy to implement) would be an iterative
definition:
* if the first parameter of the function is labelled, and this label is
provided in the application, then match their types, and start again
with the rest of the type
* if the first parameter of the function is unlabelled, and there is an
unlabelled argument in the application, then match their types, and
start again
* if the first parameter of the function is optional, and there is no
argument by that label, and there are some unlabelled arguments in
the application, then that parameter is erased; discard it and start
again
* otherwise, if all remaining arguments in the application are
unlabelled, and there are as many arguments as non-optional
parameters, switch to unlabelled application (optional parameters
are erased, non-optional ones taken in order)
* otherwise, switch to labelled application (some parameters may be
ommited)
Not only this is a long definition, but it is not symmetric.
It would allow ommiting labels in
val f : ?a:int -> b:int -> int
but not in
val g : a:int -> ?b:int -> unit -> int
A fully symmetric definition is much harder to obtain, and to
implement.
Jacques Garrigue
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
next prev parent reply other threads:[~2002-11-14 8:23 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-11-13 23:33 Chris Hecker
2002-11-14 1:05 ` Jacques Garrigue
2002-11-14 2:45 ` Chris Hecker
2002-11-14 3:34 ` Jacques Garrigue
2002-11-14 4:57 ` Chris Hecker
2002-11-14 8:23 ` Jacques Garrigue [this message]
2002-11-14 18:31 ` Chris Hecker
2002-11-15 1:09 ` Jacques Garrigue
2002-11-15 2:21 ` Chris Hecker
2002-11-14 7:40 ` Alessandro Baretta
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=20021114172307R.garrigue@kurims.kyoto-u.ac.jp \
--to=garrigue@kurims.kyoto-u.ac.jp \
--cc=caml-list@inria.fr \
--cc=checker@d6.com \
/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).