简体   繁体   English

F#模块/命名空间错误

[英]F# Module/Namespace Error

My first program with F#. 我的第一个程序是F#。

I have one file like so: 我有一个像这样的文件:

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

Then i have another file like so 然后我有另一个像这样的文件

namespace LanguageMapper.Program

open Data

module Program = 

[<EntryPoint>]
let main argv = 


    let getLocale x = 
        match x with
        | [|"live"|] -> "live"
        | [|"dev"|] -> "dev"
        | _ -> "local"

Over top of the open Data i get a red squiggly in VS telling me: open Data上方,我在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." “错误1此声明通过部分限定的路径打开名称空间或模块'Microsoft.FSharp.Data'。调整此代码以使用名称空间的完整路径。此更改将使您的代码更加健壮,因为将新的构造添加到了F#和CLI库。”

What am i doing wrong? 我究竟做错了什么? I just want to reference one file from the other. 我只想引用另一个文件。

You need to open the module using its fully qualified name, that is including its namespace. 您需要使用其完全限定名称(包括名称空间)打开模块。 So in LanguageMapper.Program you need to open LanguageMapper.Data.Data (only the last bit is the module name). 因此,在LanguageMapper.Program您需要open LanguageMapper.Data.Data (只有最后一位是模块名称)。

The Compiler is complaining on your open definition because it only specifies to open a namespace or module named Data - and it finds one in Microsoft.FSharp.Data, probably because there are some 'automatic' opens for the Microsoft.FSharp namespaces. 编译器抱怨您的open定义,因为它仅指定打开一个名为Data的名称空间或模块-并且它在Microsoft.FSharp.Data中找到一个名称空间,这可能是因为Microsoft.FSharp命名空间有一些“自动”打开。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM