你如何在OS/X上设置Haskell + ghc-mod?

z5h*_*z5h 17 haskell

我首先从https://www.haskell.org/platform/建立了Haskell,但是ghc-mod遇到了沙箱的问题并且要更新它我需要一个更新的集合,需要更新的ghc.或类似的东西.(/sf/answers/1963437311/ ??)

所以我删除了所有内容,并从http://ghcformacosx.github.io/安装.然后,设置一个新沙箱的一些奇怪的失败是因为某些东西没有适当的快乐依赖.(https://github.com/haskell-suite/haskell-src-exts/issues/14)

好.安装快乐.现在尝试(再次)安装ghc-mod,我得到一个巨大的混乱(下面).

我应该使用http://www.stackage.org/吗?
我看到有人提到ghc-pkg recachecabal install cabal-install......我需要做的事情是什么?

混乱:

Resolving dependencies... Configuring ghc-mod-5.2.1.2... Building ghc-mod-5.2.1.2... Failed to install ghc-mod-5.2.1.2 Build log ( /Users/mark/.cabal/logs/ghc-mod-5.2.1.2.log ): Configuring ghc-mod-5.2.1.2... Building ghc-mod-5.2.1.2... Preprocessing library ghc-mod-5.2.1.2...

Language/Haskell/GhcMod/Convert.hs:1:51: Warning:
    -XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS [ 1 of 38] Compiling Language.Haskell.GhcMod.Read ( Language/Haskell/GhcMod/Read.hs, dist/build/Language/Haskell/GhcMod/Read.o ) [ 2 of 38] Compiling Language.Haskell.GhcMod.Cabal21 ( Language/Haskell/GhcMod/Cabal21.hs, dist/build/Language/Haskell/GhcMod/Cabal21.o ) [ 3 of 38] Compiling Language.Haskell.GhcMod.Cabal18 ( Language/Haskell/GhcMod/Cabal18.hs, dist/build/Language/Haskell/GhcMod/Cabal18.o ) [ 4 of 38] Compiling Language.Haskell.GhcMod.Cabal16 ( Language/Haskell/GhcMod/Cabal16.hs, dist/build/Language/Haskell/GhcMod/Cabal16.o ) [ 5 of 38] Compiling Language.Haskell.GhcMod.GHCChoice ( Language/Haskell/GhcMod/GHCChoice.hs, dist/build/Language/Haskell/GhcMod/GHCChoice.o ) [ 6 of 38] Compiling Language.Haskell.GhcMod.Error ( Language/Haskell/GhcMod/Error.hs, dist/build/Language/Haskell/GhcMod/Error.o )

Language/Haskell/GhcMod/Error.hs:12:1: Warning:
    Module ‘Control.Monad.Error’ is deprecated:
      Use Control.Monad.Except instead

Language/Haskell/GhcMod/Error.hs:40:10: Warning:
    In the use of type constructor or class ‘Error’
    (imported from Control.Monad.Error, but defined in Control.Monad.Trans.Error):
    Deprecated: "Use Control.Monad.Trans.Except instead"

Language/Haskell/GhcMod/Error.hs:40:10: Warning:
    In the use of type constructor or class ‘Error’
    (imported from Control.Monad.Error, but defined in Control.Monad.Trans.Error):
    Deprecated: "Use Control.Monad.Trans.Except instead" [ 7 of 38] Compiling Language.Haskell.GhcMod.Utils ( Language/Haskell/GhcMod/Utils.hs, dist/build/Language/Haskell/GhcMod/Utils.o )

Language/Haskell/GhcMod/Utils.hs:15:1: Warning:
    The import of ‘Control.Applicative’ is redundant
      except perhaps to import instances from ‘Control.Applicative’
    To import instances alone, use: import Control.Applicative()

Language/Haskell/GhcMod/Utils.hs:45:51: Warning:
    In the use of ‘strMsg’
    (imported from Language.Haskell.GhcMod.Error, but defined in Control.Monad.Trans.Error):
    Deprecated: "Use Control.Monad.Trans.Except instead" [ 8 of 38] Compiling Language.Haskell.GhcMod.Types ( Language/Haskell/GhcMod/Types.hs, dist/build/Language/Haskell/GhcMod/Types.o ) [ 9 of 38] Compiling Language.Haskell.GhcMod.Gap ( Language/Haskell/GhcMod/Gap.hs, dist/build/Language/Haskell/GhcMod/Gap.o )

Language/Haskell/GhcMod/Gap.hs:256:18:
    Not in scope: data constructor ‘ExposePackageId’
    Perhaps you meant ‘ExposePackage’ (imported from DynFlags) cabal: Error: some packages failed to install: ghc-mod-5.2.1.2 failed during the building phase. The exception was: ExitFailure 1
Run Code Online (Sandbox Code Playgroud)

应用接受的答案(似乎安装ghc-mod)后,运行gch-mod会给出以下结果:

> ghc-mod check x.hs
cabal-helper-wrapper: Installing a private copy of Cabal, this might take a
while but will only happen once per Cabal version.

If anything goes horribly wrong just delete this directory and try again:
    /Users/mark/.ghc-mod/cabal-helper

If you want to avoid this automatic installation altogether install version
1.22.0.0 of Cabal manually (into your user or global package-db):
    $ cabal install Cabal-1.22.0.0
...In order, the following would be installed:
filepath-1.3.0.1 (latest: 1.4.0.0) (new version)
directory-1.2.2.1 (new version)
process-1.2.3.0 (reinstall) changes: directory-1.2.2.0 -> 1.2.2.1,
filepath-1.4.0.0 -> 1.3.0.1
Cabal-1.22.0.0 (latest: 1.22.2.0) (new version)
cabal: The following packages are likely to be broken by the reinstalls:
ghc-7.10.1
Cabal-1.22.2.0
Use --force-reinstalls if you want to install anyway.
cabal-helper-wrapper: Installing Cabal version 1.22.0.0 failed.
nYou have two choices now:
- Either you install this version of Cabal in your globa/luser package-db
  somehow
n- Or you can see if you can update your cabal-install to use a different
  version of the Cabal library that we can build with:
    $ cabal install cabal-install --constraint 'Cabal > 1.22.0.0'
nTo check the version cabal-install is currently using try:
    $ cabal --version

ghc-mod: readCreateProcess: /Users/mark/.cabal/libexec/cabal-helper-wrapper "/Users/mark/work/haskell/ixberg/dist" "entrypoints" "source-dirs" "ghc-options" "ghc-src-options" "ghc-pkg-options" "--with-ghc=ghc" "--with-ghc-pkg=ghc-pkg" "--with-cabal=cabal" (exit 1): failed
Run Code Online (Sandbox Code Playgroud)

奇怪的是,它想要当前安装的Cabal版本:

> cabal --version
cabal-install version 1.22.0.0
using version 1.22.0.0 of the Cabal library
Run Code Online (Sandbox Code Playgroud)

Sky*_*old 23

编辑(2015年8月)更好的修复

一个更好的命令行工具,用于通过称为堆栈的令人敬畏的FPComplete组安装Haskell二进制文件和库意味着您可以安装ghc-mod (在项目外部使其成为全局)并且它将正常工作.二进制文件将被安装到您的路径并且应该放在您的路径上,以便您的编辑器可以找到它.stack install ghc-mod~/.local/bin

我会留下以下任何想要了解地狱真正意义的人.

DanielG's Fork的问题

我问过Haskell reddit和NihillstDandy解释说Mac OS X的GHC没有注册Cabal库.从http://ghcformacosx.github.io/开始安装不是这样.它确实注册了Cabal库.

ghc-mod需要cabal库才能工作,但它不能用cabal库编译.相反,它使用cabal-helper进行编译,并查看您是否拥有cabal库的注册版本.如果它没有找到任何,那么cabal-helper-wrapper将安装一个私人副本,在这种情况下,它厌倦安装与cabal-install编译的cabal-1.22.0.0相同的版本.

当我安装DanielG的Fork时,它适用于我当前的项目,但在其他项目中测试后,我得到了同样的错误.这是fork而不是Haskell的问题(据我所知).


原始答案

所以,当我把这篇文章放在一起时,ghc-mod已经修复为GHC-7.10.感谢DanielG!

  • git clone https://github.com/DanielG/ghc-mod
  • cd ghc-mod
  • cabal install -j4

如果你得到的错误说"setup-Simple-Cabal-1.22.2.0-x86_64-osx-ghc-7.10.1:程序'happy'version> = 1.17是必需的,但找不到它."

  • cabal install happy -j4

任何其他问题都一样,它应该工作.(虽然你很高兴安装,所以它应该工作).


本文的其余部分是关于如何将cabal可执行文件(也称为cabal-install)降级到版本1.20.0.3.虽然你真的可以用它来降级到任何版本.由于ghc-mod的工作分支可以与GHC-7.10和cabal-1.22一起使用,因此您无需降级即可修复ghc-mod.

我只是把这篇文章的其余部分留在这里了,不幸的是,这是Haskell作为一个整体的问题.Halcyonnix是处理Haskell在这方面的缺点的方法.


如何在Haskell降级Cabal

当我写这篇文章ghc-mod时,也没有任何用GHC-7.10和7.10以下版本编译的fork打破了cabal-1.22沙箱.

但是,即使您使用GHC-7.8.4(7.10之前的版本)和cabal-1.20.0.3编译ghc-mod,您仍然无法在cabal-1.22及更高版本创建的沙箱中使用ghc-mod.因此,使用ghc-mod的唯一方法是将整个系统降级为cabal-1.20.0.3或不使用沙箱.这意味着你仍然可以使用GHC-7.10,但你必须使用旧版本的cabal.这是除非你想等到召集人或其他人为GHC-7.10修复它.它已经过了一个多星期,但是某种Haskell程序员将它固定在一个分支中(见上文).


如果这是你仍然需要的东西,那么如何用GHC-7.8.4和cabal-1.20.0.3编译ghc-mod.另外,我将旧的cabal-1.20.0.3替换为可执行的cabal-1.22.请注意,您下载源的目录无关紧要.

  • 这里下载适用于您的操作系统的GHC-7.8.4源代码
  • tar -xf path_to_zipped_source
  • cd path_to_ghc-7.8.4

接下来的步骤将ghc-7.8.4作为ghc-7.8.4安装在与ghc-7.10相同的文件夹中.-j4告诉make使用4个线程来编译它.

  • ./configure
  • make install -j4

要获得正确版本的cabal我们可以请求cabal获取它.

  • cabal get cabal-install-1.20.0.3
  • cd cabal-install-1.20.0.3

现在用ghc-7.8.4安装cabal.在这里cabal-1.22将拉出所有的重要性,并且应该给你一些关于安装另一个版本的cabal库的警告(不要与cabal-install混淆),这不应该引起问题.

  • cabal --with-compiler=ghc-7.8.4 install

所以现在你应该安装cabal-1.20.0.4,但不是你的路径.它将在〜/ .cabal/bin中.我们需要使这个全局化,所以删除cabal-1.22(它只删除符号链接).

  • rm`哪个cabal`

并创建cabal-1.20.0.4的符号链接.顺便说一下,您将需要删除使用cabal-1.22制作的所有沙箱,并使用cabal-1.20.0.4重新制作它们.

如果你没有,realpath你只需键入cabal的完整路径即可.我用它来获得自信.

  • cd ~/.cabal/bin
  • ln -s`realpath cabal`/usr/local/bin

现在这就是我在我的mac上编译ghc-mod的方式(你可能会遇到自己的问题).我不确定为什么cabal不能在一次通话中做到这一点,但这最终有效.

  • cabal --with-compiler=ghc-7.8.4 install happy
  • cabal --with-compiler=ghc-7.8.4 install haskell-src-exts-1.16.0.1
  • cabal --with-compiler=ghc-7.8.4 install hlint-1.9.19
  • cabal --with-compiler=ghc-7.8.4 install ghc-mod

现在你应该能够从任何地方调用ghc-mod.为了测试它只需输入ghc-mod你有后cabal sandbox init.如果它没有抛出任何错误那么你明白了.