On 07/23/2013 03:37 PM, i c wrote:
let's consider the following:

let fd = Unix.open ...
let fd = Unix.open ...

At this point one file descriptor cannot be closed. Static analysis will
have trouble catching these bugs, so do humans.
Disallowing variable shadowing prevents this.
The two "fd" occur in different contexts and should have different names.



$ cat shadow_fd.ml
let () =
  let fd = Unix.openfile "foo_1.txt" [] 0o640 in
  let fd = Unix.openfile "foo_2.txt" [] 0o640 in
  Unix.close fd


$ ocamlfind ocamlopt -linkpkg -package unix shadow_fd.ml -o shadow_fd
File "shadow_fd.ml", line 2, characters 6-8:
Warning 26: unused variable fd.


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to