caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques GARRIGUE <garrigue@kurims.kyoto-u.ac.jp>
To: henri.dubois-ferriere@epfl.ch
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Optional arguments in inherited methods
Date: Thu, 29 Apr 2004 17:48:24 +0900 (JST)	[thread overview]
Message-ID: <20040429.174824.68545560.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <Pine.LNX.4.44.0404291010340.4861-100000@lcavpc19.epfl.ch>

From: Henri DF <henri.dubois-ferriere@epfl.ch>

> > Unfortunate, but in the case of optional arguments the problem is
> > not with typing but with how they are implemented: an optional
> > argument of type [t] is actually a non-optional argument of type [t
> > option]. They disappear automagically on application, but this means
> > that None's are automatically inserted. So applying a function which has
> > optional arguments is completely different from a function without
> > them (even if the function call looks the same in your source code).
> 
> what about optional arguments which have a default value? i would assume 
> these are not implemented using options, so would that change anything 
> here?

They are also implemented with options.

  let f ?(x=0) y = x + y

is just a shorthand for

  let f ?x y = let x = match x with Some x -> x | None -> 0 in x + y

(I believe this is explained in the manual)

Why is it this way? Just because the ocaml type system is such that we
don't want to have values inside types, which is the approach you can
see in C++ for instance.

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:[~2004-04-29  8:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-28 16:13 John Goerzen
2004-04-28 16:56 ` james woodyatt
2004-04-28 19:43   ` John Goerzen
2004-04-28 22:48     ` Jacques GARRIGUE
2004-04-29  8:11       ` Henri DF
2004-04-29  8:48         ` Jacques GARRIGUE [this message]

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=20040429.174824.68545560.garrigue@kurims.kyoto-u.ac.jp \
    --to=garrigue@kurims.kyoto-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=henri.dubois-ferriere@epfl.ch \
    /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).