How can I work with multiple C # files and libraries in F #?

I have a C # library with the following Namespace / Class:

namespace Helper
{
    public static class Util
    {
         /*static methods*/
    }
}

      

I am referencing the specified library in an F # project, and when I try to call one of the methods, I get:

error FS0039: The namespace or module 'Helper' is not defined.

      

This is an example of calling a method that doesn't work:

#light

let a = Seq.skip 1000 (Helper.Util.GetPrimes 200000);;

      

Am I missing something obvious? Using open Helper doesn't work either, and the weird thing is that IntelliSense actually works, it lists every method in the Util class.

Also, what is the standard practice for calling functions in some of my files from other files in the same project? I don't want to create complete objects just to access a few functions.

+1


a source to share


2 answers


For multiple files, see the first part, " Using Multiple F # Source Files and Useful Debugging Techniques, " and the final part, " Sneak Looks Into the F # Project System, Part Three ." The former discusses how top-level code in a file implicitly goes into a module with the same name as the filename, while the latter discusses how to order files in a project (since you can only see the data declared above / in front of you) ...



+3


a source


What does your GetPrimes method look like? This works for me ...

I have a solution with a C # library including this code:

namespace Scratch
{
    public static class Util
    {
        public static IEnumerable<int> GetNumbers(int upto)
        {
            int i = 0;
            while (i++<upto) yield return i;
        }
    }
}

      



And calling it from an F # project that references a C # project like this:

#light

let p = Seq.skip 1000 ( Scratch.Util.GetNumbers 2000000);;

      

+2


a source







All Articles