Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Remi VANICAT <remi.vanicat@labri.u-bordeaux.fr>
To: caml-list@inria.fr
Subject: Re: problem with optional arguments
Date: 20 Sep 2000 22:15:08 +0200	[thread overview]
Message-ID: <ya366nqq0qb.dlv@serveur2-1.labri.u-bordeaux.fr> (raw)
In-Reply-To: "Dr. Wolfgang Gehrke"'s message of "Wed, 20 Sep 2000 12:38:07 +0200"

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

> Hello,
> 
> could someone advice me how to resolve the following problem:
> 
> The following works fine:
> 
> class test1 ~(a:int) () =
>   object
>     val a = abs a
>     method a = a
>     method strange x = new test1 ~a:x ()
>   end
> 
> let t1 = new test1 ~a:(-10) ()
> 
> 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

it's seem normal, which value have a if the optional argument is not
given ? in fact, ?a avec type 'a option, you should give a default
value. then there is another problem :

class test2 ?(a=0) () =
   object
     val a = abs a
     method a = a
     method strange x = new test2 ~a: x ()
   end

don't work, but i don't see realy why (the message of error is :

The expression "new test2" has type ?a:int -> unit -> test2
but is used with type 'a -> unit -> 'b
)

but 

class test2 ?(a=0) () =
   object
     val a = abs a
     method a = a
     method strange x = new test2 ?a: (Some x) ()
   end

work, and let you see that the argument of an optional argument is
realy of type something option


-- 
Rémi Vanicat
vanicat@labri.u-bordeaux.fr
http://dept-info.labri.u-bordeaux.fr/~vanicat



  reply	other threads:[~2000-09-21  7:37 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 [this message]
2000-09-21 18:59   ` Gerd Stolpmann
2000-09-21  0:08 ` Jacques Garrigue

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=ya366nqq0qb.dlv@serveur2-1.labri.u-bordeaux.fr \
    --to=remi.vanicat@labri.u-bordeaux.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