<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2002/12/86a98a76ddc2f876951492fdc2797528"
  from="Jacques Garrigue &lt;garrigue@k...&gt;"
  author="Jacques Garrigue"
  date="2002-12-27T15:11:32"
  subject="Re: [Caml-list] about optionnal argument ?"
  prev="2002/12/b54a908d1693a8831f27d22f361547d0"
  next="2002/12/d74e20ad375c94b64e2a48fd14c314bb"
  prev-in-thread="2002/12/cfab7d82fab7e0ed9d6dbd759f94419c"
  next-in-thread="2002/12/d74e20ad375c94b64e2a48fd14c314bb"
  prev-thread="2002/12/0a20c8ad6f2bdd101d65c6f54b7dfd02"
  next-thread="2002/12/5d442ee31123f148e1c3d1f0d71e3c7b"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] First alpha release of LablGTK2">
<msg 
  url="2002/12/a57a9f8f19efef0c309a18bc051d81d2"
  from="Jacques Garrigue &lt;garrigue@k...&gt;"
  author="Jacques Garrigue"
  date="2002-12-27T09:18:43"
  subject="[Caml-list] First alpha release of LablGTK2">
<msg 
  url="2002/12/cfab7d82fab7e0ed9d6dbd759f94419c"
  from="Christophe Raffalli &lt;Christophe.Raffalli@u...&gt;"
  author="Christophe Raffalli"
  date="2002-12-27T11:24:12"
  subject="[Caml-list] about optionnal argument ?">
<msg 
  url="2002/12/86a98a76ddc2f876951492fdc2797528"
  from="Jacques Garrigue &lt;garrigue@k...&gt;"
  author="Jacques Garrigue"
  date="2002-12-27T15:11:32"
  subject="Re: [Caml-list] about optionnal argument ?">
<msg 
  url="2002/12/d74e20ad375c94b64e2a48fd14c314bb"
  from="Nickolay Semyonov-Kolchin &lt;snob@s...&gt;"
  author="Nickolay Semyonov-Kolchin"
  date="2002-12-27T17:37:13"
  subject="Re: [Caml-list] about optionnal argument ?">
</msg>
</msg>
</msg>
</msg>
</thread>

<contents>
From: Christophe Raffalli &lt;Christophe.Raffalli@univ-savoie.fr&gt;

&gt; I wonder why optionnal argument are implemented through the option
&gt; type instead  of giving a default value ?
&gt; 
&gt; Obviously the type should carry the default value which should be a closed 
&gt; constant (like None, 0, 0.0, [1;2;3], etc ...) but this would preserve the 
&gt; possibility of using optionnal arguments and unboxed int or float arguments
&gt; 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.

&gt;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

</contents>

</message>

