caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: Sergeiu@optrak.co.uk
Cc: caml-list@inria.fr
Subject: Re: Optional arguments
Date: Fri, 09 Feb 2001 10:19:57 +0900	[thread overview]
Message-ID: <20010209101957N.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <30273167BD5AD111A5AD00A0C992201725868D@mercury.optrak.co.uk>

From: Serguei Ouklonski <Sergeiu@optrak.co.uk>

> Example1:
> 
> let fn1 a:string (?b = "") = (String.length a) + (String.length b)
> 
> let x = fn1 "test"
> 
>   result is function
> 
> Example2:
> 
> let fn1 (?a = "") b:string = (String.length a) + (String.length b)
> 
> let x = fn1 "test"
> 
>   result is 4 (number)
> 
> It seems that in both cases result should be 4.
> 
> Have I missed something from OCaml docs?

Optional arguments are discarded when you apply a functions to a
non-labelled argument _appearing after them_ in the function's type.
So in your example, since a is taken before b, b will not be
discarded.
Since there is no way to discard b in this, the compiler warns you:
      # let fn1 a ?(b = "") = String.length a + String.length b;;
      Warning: This optional argument cannot be erased
      val fn1 : string -> ?b:string -> int = <fun>

Regards,

Jacques Garrigue
---------------------------------------------------------------------------
Jacques Garrigue      Kyoto University     garrigue at kurims.kyoto-u.ac.jp
		<A HREF=http://wwwfun.kurims.kyoto-u.ac.jp/~garrigue/>JG</A>



  reply	other threads:[~2001-02-09  9:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-02-08 12:50 Serguei Ouklonski
2001-02-09  1:19 ` Jacques Garrigue [this message]
2008-11-09 19:17 malc

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=20010209101957N.garrigue@kurims.kyoto-u.ac.jp \
    --to=garrigue@kurims.kyoto-u.ac.jp \
    --cc=Sergeiu@optrak.co.uk \
    --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).