Browse thread
[Caml-list] Newbie: declarations
[
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: | FabienFleutot <fleutotf@e...> |
| Subject: | Re: [Caml-list] Newbie: declarations |
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