The smallest area for opening namespaces is in the module.
The workaround is to place the function and its open namespaces in an automatically open submodule, so that the commands opendo not pollute the parent modules, and the submodule is transparent to users:
[<AutoOpen>]
module Utils =
open System.IO
let writeToFile filename (text: string) =
let stream = new FileStream(filename, FileMode.Create)
let writer = new StreamWriter(stream)
writer.WriteLine(text)
source
share