Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Default values for structures (feature request)
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques GARRIGUE <garrigue@k...>
Subject: Re: [Caml-list] Default values for structures (feature request)
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

-------------------
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