Opening a namespace in F # .net for a specific block of code

I understand that this is not possible in C #; the most important thing is to form an alias at the top of the code file. Is there any way to do this in F #?

See this question for the C # counterpart of my question:

My guess is: "No, use an alias." but nothing was solved, nothing happened.

+3
source share
1 answer

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    
    // Now you do not have to include the full paths.
    let writeToFile filename (text: string) =  
      let stream = new FileStream(filename, FileMode.Create)
      let writer = new StreamWriter(stream)
      writer.WriteLine(text)
+5
source

All Articles