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

标签 haskell

我首先从https://www.haskell.org/platform/设置了Haskell,但是ghc-mod的沙箱存在问题,要对其进行更新,我需要一个更新的cabal,它需要一个更新的ghc。或类似的东西。 (https://stackoverflow.com/a/28049104/131227 ??)

所以我删除了所有内容,并从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

应用可接受的答案(似乎已安装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

奇怪的是,它需要当前安装的Cabal版本:
> cabal --version
cabal-install version 1.22.0.0
using version 1.22.0.0 of the Cabal library

最佳答案

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

真棒FPComplete组(称为stack)提供了一种更好的命令行工具,用于安装Haskell二进制文件和库,这意味着您可以使用stack install ghc-mod安装ghc-mod(在项目外部使其全局),并且可以正常工作。二进制文件将安装到~/.local/bin,并应放在您的路径上,以便您的编辑器可以找到它。

我将把下面的内容留给任何想知道阴谋 hell 真正含义的人。

DanielG的叉子有问题

我在Haskell reddit上询问时,NihillstDandy解释说Mac OS X的GHC没有注册Cabal库。对于从http://ghcformacosx.github.io/进行的安装,情况并非如此。它确实注册了Cabal库。

ghc-mod需要cabal库才能工作,但无法与cabal库一起编译。相反,它使用cabal-helper进行编译,并且看起来是否具有cabal库的注册版本。如果找不到,则cabal-helper-wrapper将安装一个 private 副本,在这种情况下,安装与cabal-install编译版本相同的版本cabal-1.22.0.0会很累。

当我安装DanielG's 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:程序“快乐”版本
    > = 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-7.10和低于7.10版本编译的ghc-mod或任何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.22替换为较旧的cabal-1.20.0.3。注意,将源下载到哪个目录都没有关系。
  • here为您的操作系统下载GHC-7.8.4源码
  • tar -xf path_to_zipped_source
  • cd path_to_ghc-7.8.4

  • 下一步将在您安装ghc-7.10的同一文件夹中将ghc-7.8.4作为ghc-7.8.4安装。 -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(仅删除符号链接(symbolic link))。
  • rm`which cabal`

  • 并创建到cabal-1.20.0.4的符号链接(symbolic link)。顺便说一句,您将需要删除使用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即可。如果它没有引发任何错误,那么您就可以了。

    关于haskell - 如何在OS/X上设置Haskell + ghc-mod?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29540829/

    相关文章:

    list - Haskell:列表理解

    haskell - 如何在 haskell 中组合 'freer' 效果?

    haskell - 在 Haskell 中将 IO 字符串写入标准输出

    haskell - 在 json 解析中使用文件名 (Haskell Aeson)

    haskell - 如何将列表中的元素与所有其他元素相乘?

    haskell - 如何将状态与管道一起使用?

    haskell - 仿函数泛化问题

    sockets - Haskell 中的原始套接字

    haskell - 使用 ContT 构造函数创建新的 Monad Cont

    indentation - 缩进在这里起什么作用?为什么一个缩进不起作用?