简体   繁体   English

Mono,F#库在Mac OSX下不起作用

[英]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. 我在OSX中用Macports安装了Mono和F#。 There are some bugs in F# interactive, but still it's usable if you call it from emacs with F# mode. F#交互中有一些错误,但是如果您以F#模式从emacs调用它,仍然可以使用。

Now, the problem is that although F# is there and works, even the simplest of libraries/functions are not available. 现在的问题是,尽管F#可用并且可以使用,但即使是最简单的库/功能也无法使用。 For instance, the following code doesn't run, with the error that it can't find, neither sum , neither out : 例如,以下代码无法运行,并且找不到错误, sumout都不存在:

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? 我在这里想念什么?

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 这是我最近为使F#在Mono(在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

This is the summary of discussion with @jbssm through comments: 这是通过评论与@jbssm进行讨论的摘要:

  • 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. 原始配置是通过MacPorts安装的Mono 2.10.6和F#1.9.4.19(旧的F#版本可追溯到2008年)。 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. 他尝试从磁盘映像中删除那些软件包并安装Mono获得了测试代码,但是导致了一个奇怪的错误。 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. 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. 每当启动fsi时。

And lets start my answer from here: 让我们从这里开始我的答案:

  1. To get out of fsi without Ctrl-C, I think you always can use #quit;; 为了在没有Ctrl-C的情况下#quit;; ,我认为您总是可以使用#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. 我觉得有些奇怪,因为您的新F#配置应该可以使用。 Have you installed new Mono and F# using or not using MacPorts because it's a known bug of F# on MacPorts? 您是否使用或不使用MacPorts安装了新的Mono和F#,因为它是MacPorts上F#的已知错误 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. 如果您不使用MacPorts,我的猜测是MacPorts上的旧Mono安装剩余了一些数据,这些数据与新的Mono安装冲突。 If the first suggestion doesn't work, maybe you should follow the below procedure: 如果第一个建议不起作用,则可能应遵循以下步骤:

    1. Remove old Mono installation . 删除旧的Mono安装
    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. 从磁盘映像安装最新的Mono版本 :Mono 2.10及更高版本已包含F#软件包,因此无需安装单独的F#软件包。
    3. Try your test script with fsi on the terminal. 在终端上使用fsi尝试测试脚本。
    4. Update Emacs configuration (if needed) and try to run F# on Emacs. 更新Emacs配置(如果需要),并尝试在Emacs上运行F#。

    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. 我的Mac上运行的是F#的Mono 2.10(尽管我不使用Emacs),所以我认为从头开始安装Mono 2.10没有任何问题。

Please give follow-up information, if any of them works for you. 如果有任何适合您的信息,请提供后续信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM