caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Frank Atanassow <franka@cs.uu.nl>
To: Sven LUTHER <luther@dpt-info.u-strasbg.fr>
Cc: Fr?d?ric van der Plancke <fvdp@decis.be>, caml <caml-list@inria.fr>
Subject: Re: [Caml-list] Newbie: declarations
Date: Tue, 19 Jun 2001 14:25:54 +0200	[thread overview]
Message-ID: <20010619142554.A7583@cs.uu.nl> (raw)
In-Reply-To: <20010619122206.A24467@lambda.u-strasbg.fr>; from luther@dpt-info.u-strasbg.fr on Tue, Jun 19, 2001 at 12:22:06PM +0200

Sven LUTHER wrote (on 19-06-01 12:22 +0200):
> What about having a way to initialise struct types :
> 
> something like :
> 
> type datarec = {
>          mutable name : string = "?";
>          mutable color : string = "?";
>          mutable value : int = 0;
> }
> [...]
> But is it really usefull, i guess you could simply wrap the datatype in a
> constructor, and not worry about such things :

Yes, and it also doesn't make sense for the common case where fields are
polymorphic.

> type datarec = {
>          mutable name : string;
>          mutable color : string;
>          mutable value : int;
> }
> 
> let new_datarec n c v = {
>   name = match n with None -> "?" | Some n -> n;
>   color = match c with None -> "?" | Some c -> c;
>   value = match v with None -> 0 | Some v -> v;
> }
> 
> Then you could simply do :
> 
> let x = new_datarec None None (Some 113)
> let y = new_datarec (Some "y") ("00FF00 FF00FF") None

There is a simpler way:

  let new_datarec = { name = "?"; color = "?"; value = 0 }
  let x = { new_datarec with value = 113 }
  let y = { new datarec with color = "00FF00 FF00FF"; name = "y" }

-- 
Frank Atanassow, Information & Computing Sciences, Utrecht University
Padualaan 14, PO Box 80.089, 3508 TB Utrecht, Netherlands
Tel +31 (030) 253-3261 Fax +31 (030) 251-379
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


      reply	other threads:[~2001-06-19 12:25 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-06-17  0:09 leary
2001-06-17 10:08 ` Vitaly Lugovsky
2001-06-18  2:19   ` leary
2001-06-18 15:18     ` Remi VANICAT
2001-06-18 20:19       ` [Caml-list] Good introduction for the working programmer in Objective CAML Mattias Waldau
2001-06-18 20:35         ` Miles Egan
2001-06-18 20:49         ` leary
2001-06-17 15:33 ` [Caml-list] Newbie: declarations David Fox
2001-06-18 14:52   ` FabienFleutot
2001-06-19  8:11 ` Frédéric van der Plancke
2001-06-19 10:22   ` Sven LUTHER
2001-06-19 12:25     ` Frank Atanassow [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20010619142554.A7583@cs.uu.nl \
    --to=franka@cs.uu.nl \
    --cc=caml-list@inria.fr \
    --cc=fvdp@decis.be \
    --cc=luther@dpt-info.u-strasbg.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).