by wmt · 11y ago · 0 comments
Either with a using/try with resources/with construct, or by using closures.
// Pseudo language with FP capabilities
let withFile filename action =
let fd = open filename
action fd
close fd
withFile "config.sys" (fun fd -> write (readlines fd))
Real production code would also take care about proper closing the file in case of errors.