2012-04-25 43 views

回答

5

打開命名空間的最小範圍在模塊中。

一種解決方法是把一個函數及其開口命名空間成自動打開子模塊,以便open命令不污染主模塊和子模塊是對用戶透明:

[<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)