Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: wgehrke@dia.uniroma3.it
Cc: caml-list@inria.fr
Subject: Re: problem with optional arguments
Date: Thu, 21 Sep 2000 09:08:25 +0900	[thread overview]
Message-ID: <20000921090825E.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: Your message of "Wed, 20 Sep 2000 12:38:07 +0200" <39C8938F.8DFC8039@dia.uniroma3.it>

From: "Dr. Wolfgang Gehrke" <wgehrke@dia.uniroma3.it>

> But on the other hand with an optional argument it does not compile,
> neither:
> 
> class test2 ?(a:int) () =
>   object
>     val a = abs a
>     method a = a
>     method strange x = new test2 ~a:x ()
>   end

The point is that optional arguments, when you do not give a default
value, are of type [t option] rather than [t], so that [?(a:int)]
produces immediately a type clash (int is not compatible with 'a option).
The simplest solution is to specify a default:
        class test2 ?(a:int=2) () = ...
Otherwise, you have to explicitely handle the Some and None cases for
a.

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>



      parent reply	other threads:[~2000-09-21  7:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-09-20 10:38 Dr. Wolfgang Gehrke
2000-09-20 20:15 ` Remi VANICAT
2000-09-21 18:59   ` Gerd Stolpmann
2000-09-21  0:08 ` 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=20000921090825E.garrigue@kurims.kyoto-u.ac.jp \
    --to=garrigue@kurims.kyoto-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=wgehrke@dia.uniroma3.it \
    /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