F# 模块/命名空间错误

标签 f#

我的第一个使用 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/

相关文章:

f# - 如何使记录实现接口(interface)?

f# - 这个 f# echo 服务器出了什么问题?

optimization - 记或不记

asynchronous - F# Async.FromBeginEnd 不应该调用 End 函数?

winforms - 在 F# 中绘制 Windows 窗体

c# - 使用可选参数从 F# 对象在 C# 中创建对象

f# - 在 F# 中制作鱼

postgresql - 使用 F# 中的 Npgsql 的用户定义的 postgresql 类型

f# - 如何使用 FsCheck 生成器生成两条相同类型的记录,其中一条记录的属性与另一条记录不同

winforms - 如何强制 WinForms 控件填充 TableLayoutPanel 中多列跨单元格中的 FlowLayoutPanel?