caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "FabienFleutot" <fleutotf@esiee.fr>
To: <leary@nwlink.com>, "David Fox" <dsf@foxthompson.net>
Cc: "caml" <caml-list@inria.fr>
Subject: Re: [Caml-list] Newbie: declarations
Date: Mon, 18 Jun 2001 16:52:06 +0200	[thread overview]
Message-ID: <006d01c0f806$3eea0430$6ec809c0@fabien> (raw)
In-Reply-To: <lun177m88f.fsf@dsf.net>

From: "David Fox" <dsf@foxthompson.net>
> leary@nwlink.com writes:
>
> > Is there a way to declare a variable and not initialize it, like C?
> >
> > int i;
> > i = 0;
> >
> > More to the point, is there a way to declare a record variable without
> > listing/initializing all the fields?  If yes, what are the default
values?
>
[...]
> My first pass solution is to create a reference
> to a dummy object:
>
> let dummy = {field1=0; field2=0...}
> let current = ref dummy

A better solution would be to use options. If it is possible for some of
your vars to be uninitialized, this unitialized state should be able to be
easily filtered:

let current = ref None;
...
current := Some(generate_struct foo bar);
...
match current with
| None -> failwith "This shouldn't be uninitializable at this stage."
| Some current ->
   ...

It's way cleaner than if(!current==dummy) tests.
-------------------
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  7: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 [this message]
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

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='006d01c0f806$3eea0430$6ec809c0@fabien' \
    --to=fleutotf@esiee.fr \
    --cc=caml-list@inria.fr \
    --cc=dsf@foxthompson.net \
    --cc=leary@nwlink.com \
    /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).