[
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: | Jean-Christophe Filliatre <filliatr@c...> |
| Subject: | Re: The Unix module & records |
> 1: let main () =
> 2: let file_info : Unix.stats = Unix.stat Sys.argv.(1) in
> 3: let fd = Unix.openfile Sys.argv.(1) [ Unix.O_RDONLY ] perm in
> 4: let buffer = ref "" in
> 5: let bytes_read = Unix.read (fd) (buffer) (file_info.st_size) in
> <snipped>
>
> But it fails with the error "Unbound record field label st_size" on line 5.
> I can't explain why this is happening; looking at the Unix.ml file, I see
> the st_size field in the Unix.stats record. Any suggestions would be
> appreciated.
Since you didn't open the Unix module with "open Unix" you have to
qualify any identifier from that module with "Unix." (as you did for
stat, read, ... by the way), including the field name st_size.
So you should have written "file_info.Unix.st_size".
As you are probably going to say, it becomes quite heavy. Thus, since
you use many identifiers from the Unix module, you should rather open
it, like this :
======================================================================
open Unix
let main () =
let file_info = stat Sys.argv.(1) in
let fd = openfile Sys.argv.(1) [ O_RDONLY ] perm in
let buffer = ref "" in
let bytes_read = read fd buffer file_info.st_size in
<snipped>
======================================================================
--
Jean-Christophe Filliatre
Computer Science Laboratory Phone (650) 859-5173
SRI International FAX (650) 859-2844
333 Ravenswood Ave. email filliatr@csl.sri.com
Menlo Park, CA 94025, USA web http://www.csl.sri.com/~filliatr