tags:

views:

380

answers:

2

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

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

I have referenced said library in a 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 the method call not working:

#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 does work, 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 wanna create full objects just to access a few functions.

+2  A: 

What does your GetPrimes method look like? It work 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 a F# project that references the C# project like this:

#light

let p = Seq.skip 1000 ( Scratch.Util.GetNumbers 2000000);;
John Weldon
Hi, I managed to isolate the problem, I can call the C# method now. The problem was that I could not send the statement to FSI, but I can compile it and run it from the main file. What I would like to know is, how can I define functions in one file and call them from another file? Preferably not creating classes/objects. I couldn't find anything on the Internet.
sker
+3  A: 

Regarding multiple files, see the first portion of "Using multiple F# source files, and a useful debugging technique", as well as the final portion of "Sneak peeks into the F# project system, part three". The former discusses how top-level code in a file implicitly goes in a module of the same name as the filename, whereas the latter discusses how to order files in the project (since you can only see stuff declared above/before you).

Brian
Thanks, that's what I needed. Although I couldn't call my functions without explicitly defining the module, but it works and that's what matters.
sker