6

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.

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

It was this, plus the fact that i had to manually rearrange the file order in the project file as pointed out here stackoverflow.com/questions/1608240/…. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.