jbssm
jbssm

Reputation: 7151

Mono, F# libraries not working under Mac OSX

I have a very simple question. I tried to google it, but to no avail.

I installed Mono and F# with Macports in OSX. There are some bugs in F# interactive, but still it's usable if you call it from emacs with F# mode.

Now, the problem is that although F# is there and works, even the simplest of libraries/functions are not available. For instance, the following code doesn't run, with the error that it can't find, neither sum, neither out:

let sumMultiples n =
    [1..n]
    |> List.filter (fun i -> (i%3 = 0 || i%5 = 0))
    |> List.sum

let out = sumMultiples 999

printfn "%d" out

And the error given is:

test.fs(6,12): error FS0039: The value, constructor, namespace or type 'sum' is not defined.


test.fs(10,17): error FS0039: The value or constructor 'out' is not defined.
stopped due to error

What I'm I missing here?

Upvotes: 2

Views: 798

Answers (2)

pad
pad

Reputation: 41290

This is the summary of discussion with @jbssm through comments:

  • The original configuration is Mono 2.10.6 and F# 1.9.4.19 (an old F# version dated back to 2008) installed through MacPorts. His attempt to remove those packages and install Mono from disk image gets the test code work, but results in a weird error Failed to install ctrl-c handler - Ctrl-C handling will not be available. Error was: Exception has been thrown by the target of an invocation. whenever starting fsi.

And lets start my answer from here:

  1. To get out of fsi without Ctrl-C, I think you always can use #quit;;. To solve the new problem, you may find the answer of the following question helpful.
  2. I find it a little bit weird because your new F# configuration should work. Have you installed new Mono and F# using or not using MacPorts because it's a known bug of F# on MacPorts? If you're not using MacPorts, my guess is there are some data left from the old Mono installation on MacPorts which conflicts with the new Mono installation. If the first suggestion doesn't work, maybe you should follow the below procedure:

    1. Remove old Mono installation.
    2. Install latest Mono version from disk image: Mono 2.10 onwards includes F# package already so no need to install a separate F# package.
    3. Try your test script with fsi on the terminal.
    4. Update Emacs configuration (if needed) and try to run F# on Emacs.

    I have Mono 2.10 with F# running on my Mac (though I don't use Emacs), so I don't think there's any problem installing Mono 2.10 from scratch.

Please give follow-up information, if any of them works for you.

Upvotes: 2

Harold
Harold

Reputation: 1794

Here are some instructions I recently wrote up for getting F# working under Mono (on Mac) https://github.com/Phrogz/laink/wiki/F%23s-on-Mac

You code works after following those steps:

~/code/fs harold$ cat test.fs
let sumMultiples n =
    [1..n]
    |> List.filter (fun i -> (i%3 = 0 || i%5 = 0))
    |> List.sum

let out = sumMultiples 999

printfn "%d" out

~/code/fs harold$ fsc test.fs
Microsoft (R) F# 2.0 Compiler build 2.0.0.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

~/code/fs harold$ mono test.exe
233168

Upvotes: 2

Related Questions