[Haskell-cafe] Proposal: Non-recursive let

Siraaj Khandkar siraaj at khandkar.net
Fri Jul 26 18:15:19 CEST 2013


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.





More information about the Haskell-Cafe mailing list