Version française
Home     About     Download     Resources     Contact us    
Browse thread
Deconstructing optional arguments
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Olivier Andrieu <oandrieu@g...>
Subject: Re: [Caml-list] Deconstructing optional arguments
On Fri, Apr 11, 2008 at 11:24 AM, Jon Harrop <jon@ffconsultancy.com> wrote:
>
>  Is it possible to deconstruct an optional argument as you can with a labeled
>  argument:
>
>   let f ~p:(x,y) () = x - y
>
>  with something like:
>
>   let f ?(p=0,0):(x,y) () = x - y

sure, cf. the grammar in the refman
http://caml.inria.fr/pub/docs/manual-ocaml/expr.html

parameter	::=
        ...
 	¨O	 ? label-name : (  pattern  [: typexpr]  [= expr] )


let f ?p:(x,y=0,0) () = x - y

-- 
  Olivier