caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: Christophe.Raffalli@univ-savoie.fr
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] about optionnal argument ?
Date: Sat, 28 Dec 2002 00:11:09 +0900	[thread overview]
Message-ID: <20021228001109W.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <3E0C43FE.7030200@univ-savoie.fr>

From: Christophe Raffalli <Christophe.Raffalli@univ-savoie.fr>

> I wonder why optionnal argument are implemented through the option
> type instead  of giving a default value ?
> 
> Obviously the type should carry the default value which should be a closed 
> constant (like None, 0, 0.0, [1;2;3], etc ...) but this would preserve the 
> possibility of using optionnal arguments and unboxed int or float arguments
> and it will save the None/Some test !

There are several reasons to use optionals rather than defaults.
One is semantical: the meaning of defaults is quite clear with
second-class functions, much less with first-class ones.  If we want
to keep an untyped semantics, your idea of putting the default in the
type is not satisfactory. It would also have other implications: if I
have a list of functions taking optional arguments, does it mean that
they should all have the same defaults?
The optional approach appears to be a nicer fit for first-class
functions: it is not by chance that common lisp has the same
approach.  It is also more expressive: the default value may depend on
the other arguments.

>From the implementation point of view, default arguments with
first-class functions would be also cumbersome: either we depend
strongly on types, and allow to write arbitrary values in types (not
only simple ones, functions too!), or we must think of a way to put
the defaults arguments in the closure when needed. Hairy.

All-in-all, deriving default arguments from optionals is much simpler,
and the extra cost generally doesn't matter.
But you have a good point that if a function is very simple
(arithmetic or data copying) and called very often, then using
optionals with it is maybe not such a good idea. The overloading of
glVertex is a bit of an overkill anyway.
I don't know how glVertex is implemented on the C side, but if it is
only copying its data to a queue, then we may want to optimize the
marshalling.  But again it depends how your data was layed out
originally: if it is in a table, the vector form is best as no copy is
needed. If you have to compute it for each call, then the flat unboxed
calls are best.

Regards,

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


  reply	other threads:[~2002-12-27 15:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-27  9:18 [Caml-list] First alpha release of LablGTK2 Jacques Garrigue
2002-12-27 12:13 ` [Caml-list] about optionnal argument ? Christophe Raffalli
2002-12-27 15:11   ` Jacques Garrigue [this message]
2002-12-27 15:18     ` Nickolay Semyonov-Kolchin

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=20021228001109W.garrigue@kurims.kyoto-u.ac.jp \
    --to=garrigue@kurims.kyoto-u.ac.jp \
    --cc=Christophe.Raffalli@univ-savoie.fr \
    --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).