Browse thread
[Caml-list] Resource acquisition is initialization
[
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: | Xavier Leroy <xavier.leroy@i...> |
| Subject: | Re: [Caml-list] Resource acquisition is initialization |
> Maybe I don't understand something but IMHO it's not very usable because
> with_file_in type is fixed after the first use. So e.g. input_line and
> input_char operation cannot be mixed. You cannot write something like
>
> let process filename =
> let f = with_file_in filename in
> begin
> print_string (f input_line);
> print_char (f input_char); (* syntax error! *)
> end
Even without the typing problem, this would open and close the file
twice, which isn't what you want. The correct usage is:
let process filename =
with_file_in filename
(fun ic ->
print_string (input_line ic);
print_char (input_char ic))
- Xavier Leroy
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners