简体   繁体   中英

F# Module/Namespace Error

My first program with 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:

"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."

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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