我的第一个使用 F# 的程序。
我有一个像这样的文件:
namespace LanguageMapper.Data
#if INTERACTIVE
#r "System.Data"
#r "System.Data.Linq"
#r "FSharp.Data.TypeProviders"
#endif
open System.Data
open System.Data.Linq
open Microsoft.FSharp.Data.TypeProviders
module Data =
// You can use Server Explorer to build your ConnectionString.
type SqlConnection = Microsoft.FSharp.Data.TypeProviders.SqlDataConnection<ConnectionString = @"connstring">
let db = SqlConnection.GetDataContext()
然后我有另一个像这样的文件
namespace LanguageMapper.Program
open Data
module Program =
[<EntryPoint>]
let main argv =
let getLocale x =
match x with
| [|"live"|] -> "live"
| [|"dev"|] -> "dev"
| _ -> "local"
在开放数据
之上,我在VS中看到一个红色的波浪线告诉我:
"Error 1 This declaration opens the namespace or module 'Microsoft.FSharp.Data' through a partially qualified path. Adjust this code to use the full path of the namespace. This change will make your code more robust as new constructs are added to the F# and CLI libraries."
我做错了什么?我只想从一个文件引用另一个文件。
最佳答案
您需要使用其完全限定名称(包括其命名空间)打开模块。因此,在LanguageMapper.Program中,您需要打开LanguageMapper.Data.Data(只有最后一位是模块名称)。
编译器提示您的 open
定义,因为它只指定打开名为 Data 的命名空间或模块 - 并且它在 Microsoft.FSharp.Data 中找到一个,可能是因为有一些“自动”针对 Microsoft.FSharp 命名空间打开。
关于F# 模块/命名空间错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13333527/