* Deconstructing optional arguments
@ 2008-04-11 9:24 Jon Harrop
2008-04-11 10:06 ` [Caml-list] " Alain Frisch
2008-04-11 10:36 ` Olivier Andrieu
0 siblings, 2 replies; 3+ messages in thread
From: Jon Harrop @ 2008-04-11 9:24 UTC (permalink / raw)
To: caml-list
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
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/products/?e
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] Deconstructing optional arguments
2008-04-11 9:24 Deconstructing optional arguments Jon Harrop
@ 2008-04-11 10:06 ` Alain Frisch
2008-04-11 10:36 ` Olivier Andrieu
1 sibling, 0 replies; 3+ messages in thread
From: Alain Frisch @ 2008-04-11 10:06 UTC (permalink / raw)
To: Jon Harrop; +Cc: caml-list
Jon Harrop 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
Yes, of course. The default value is attached to the pattern, not to the
label:
let f ?p:((x,y)=(0,0)) () = x - y;;
-- Alain
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] Deconstructing optional arguments
2008-04-11 9:24 Deconstructing optional arguments Jon Harrop
2008-04-11 10:06 ` [Caml-list] " Alain Frisch
@ 2008-04-11 10:36 ` Olivier Andrieu
1 sibling, 0 replies; 3+ messages in thread
From: Olivier Andrieu @ 2008-04-11 10:36 UTC (permalink / raw)
To: Jon Harrop; +Cc: caml-list
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=GB2312, Size: 488 bytes --]
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-04-11 10:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-11 9:24 Deconstructing optional arguments Jon Harrop
2008-04-11 10:06 ` [Caml-list] " Alain Frisch
2008-04-11 10:36 ` Olivier Andrieu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox