tags:

views:

231

answers:

3

Forgive me if the answer seems obvious.

I created a Visual Studio solution and added two projects to it, one an f# Library (called MathLibrary) and the second, a c# frontend (called frontend, I'm aware of my creativity).

So I add a reference to the MathLibrary DLL in my frontend project, compiled the MathLibrary DLL (to make sure) and attempted to use it in my frontend project. At which point my compiler complained that it was an undefined reference. It was my understanding that adding the appropriate reference would allow me access to my DLL, but clearly I'm missing an important step.

Any help?

A: 

Does it perhaps show up as Module1.SomeClass. The default file in an F# library project is called Module1, and if you don't start the source code file with either a namespace or module declaration, you generate code in a module with the same name as the filename.

You might try adding namespace FsLib to the top of your F# library code that defines some class, and then see if FsLib.SomeClass works in C#.

Brian
Ok, I tried this and it did not work. At this point I realized that the .fs file had a different name that the namespace I was using for it. I'm not sure why the file requires the same name as the namespace (as I could have multiple files in the same namespace), but that was what caused it to compile properly
tzenes
@tzenes, if you've found the solution, consider adding it as an answer and accepting it.
Benjol
@tzones: there is no realtionship between a .fs file's name, and the namespaces/modules therein contained... except in the case where you completely omit any namespace or module declarations; in this case, the compile assumes a module with the same name as the file. While I am glad you were able to compile, I don't think you've hit upon the actual problem/solution.
pblasucci
@pblasucci would you mind putting that as an answer as it is the correct answer to my question? (assuming a module with the same name as the file)
tzenes
@tzones: sure, no worries.
pblasucci
A: 

Did the F# library build successfuly? Can you see the DLL file and does it contain any classes and namespaces if you open it using Reflector?

In any case, you'll also need to add reference to FSharp.Core.dll (which is a library containing core F# types such as lists, etc. and is referenced by any dll that the F# compiler produces). However, I suppose the error message you'd get if you just needed to add this reference would be different.

Tomas Petricek
+1  A: 

There is no realtionship between a .fs file's name, and the namespaces/modules therein contained... except in the case where you completely omit any namespace or module declarations; in this case, the compile assumes a module with the same name as the file. While I am glad you were able to compile, I don't think you've hit upon the actual problem/solution.

pblasucci