Browse thread
[Caml-list] Default values for structures (feature request)
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Sven Luther <sven.luther@w...> |
| Subject: | Re: [Caml-list] Default values for structures (feature request) |
On Wed, Jun 02, 2004 at 09:56:55PM +0900, Jacques GARRIGUE wrote:
> From: Richard Jones <rich@annexia.org>
>
> > Could have a syntax for default values for structures? Something
> > like:
> >
> > type t = { field1 : int = 0;
> > field2 : string; (* no default *)
> > }
>
> The difficulty should be apparent in your example: this supposes
> writing values in interfaces, which would be a major (huge) change in
> language design...
>
> Note that labeled arguments let you do that.
>
> let new_t ?(field1 = 0) ~field2 () = {field1=field1; field2=field2}
>
> > The reason for having default fields is so that I can export struct-
> > ures from my module interface, but be able to add fields with default
> > values later without breaking dependent code. (But in some circum-
> > stances I would deliberately add fields without default values in
> > order to break code).
>
> This is the point with optional/labeled arguments.
> Jacques Garrigue
Well, what about adding a syntaxic wrapper over those to let you
automatically do it using a syntax similar to what Richard Jones
proposed ?
Friendly,
Sven luther
-------------------
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