From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA15533; Mon, 17 Nov 2003 17:24:50 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA15332 for ; Mon, 17 Nov 2003 17:24:49 +0100 (MET) Received: from herd.plethora.net (herd.plethora.net [205.166.146.1]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id hAHGOl125140 for ; Mon, 17 Nov 2003 17:24:48 +0100 (MET) Received: from bhurt.plethora.net (bhurt.plethora.net [205.166.146.49]) by herd.plethora.net (8.11.6/8.10.1) with ESMTP id hAHGObC04578; Mon, 17 Nov 2003 10:24:42 -0600 (CST) Date: Mon, 17 Nov 2003 11:24:01 -0600 (CST) From: Brian Hurt X-X-Sender: bhurt@localhost.localdomain To: Selentek 24331-03 cc: caml-list@inria.fr Subject: Re: [Caml-list] optional arguments In-Reply-To: <20031117085249.GA11793@inv_machine> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 val:01 val:01 int:01 int:01 nov:01 match:02 match:02 unit:03 unit:03 wrote:03 argument:03 arguments:03 redirect:95 let:04 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Mon, 17 Nov 2003, Selentek 24331-03 wrote: > Hello, > > Is there any way to "send optional argument with None value". > for example: > > let a = None;; > val a : 'a option = None If you delete the above two lines... > > let f ?v () = > match v with > | Some i -> i + 1 > | None -> 0 > This code just does what you want it to. It has the type: val f : ?v:int -> unit -> int = And is called like: f ();; (* returns 0 *) f ~v:1 () ;; (* returns 2 *) Another possibility is to do: let f ?(v = None) () = match v with None -> 0 | Some i -> i + 1 ;; This has the type: val f : ?v:int option -> unit -> int = And is called like: f ();; (* returns 0 *) f ~v:None ();; (* returns 0 *) f ~v:(Some 1) ();; (* returns 2 *) Form #2 is probably want you want to do if you just want to pass in an option. > > Sorry for my english. > Your english is as good as mine :-}. -- "Usenet is like a herd of performing elephants with diarrhea -- massive, difficult to redirect, awe-inspiring, entertaining, and a source of mind-boggling amounts of excrement when you least expect it." - Gene Spafford Brian ------------------- 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