Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: 2004-06-02 (12:57)
From: Jacques GARRIGUE <garrigue@k...>
Subject: Re: [Caml-list] Default values for structures (feature request)
From: Richard Jones <>

> 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 Archives:
Bug reports: FAQ:
Beginner's list: