Installing Haskell packages on Mac

对着背影说爱祢 提交于 2019-12-03 05:36:38

问题


I can't seem to get a few Haskell packages to install on my Mac (10.6.8). I first tried Happstack and it failed and then I tried Snap.

Sometimes when I run ghci I get a segmentation fault.

Other times it works and goes like this:

GHCi, version 7.4.2: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude>

When trying to get Snap:

....
....
....
Loading package vector-0.10.0.1 ... linking ... done.
Loading package zlib-0.5.4.0 ... linking ... done.
Loading package zlib-bindings-0.1.1.3 ... linking ... done.
Loading package zlib-enum-0.2.3 ... linking ... done.
Loading package snap-core-0.9.3.1 ... linking ... done.
Loading package snap-server-0.9.3.3 ... linking ... done.
Loading package directory-tree-0.11.0 ... linking ... done.
cabal: Error: some packages failed to install:
snap-0.11.2 failed during the building phase. The exception was:
ExitFailure 11

I have seen this problem a few times but nothing really solved it for me. Any ideas?


回答1:


Have you tried using homebrew? It handles the dependencies for you. I am on Mac OS X 10.7.5, but these instructions should work for you.

Using homebrew, you can install haskell-platform using the brew command. It will take a while. The compile stage for haskell-platform took 15 minutes.

$ brew search haskell
haskell-platform

$ brew install haskell-platform
==> Installing haskell-platform dependency: ghc
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/ghc-7.4.2.lion.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring ghc-7.4.2.lion.bottle.1.tar.gz
==> Caveats
This brew is for GHC only; you might also be interested in haskell-platform.
==> Summary
🍺  /usr/local/Cellar/ghc/7.4.2: 5176 files, 767M
==> Installing haskell-platform
==> Downloading http://lambda.haskell.org/platform/download/2012.4.0.0/haskell-platform-2012.4.0.0.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/haskell-platform/2012.4.0.0 --enable-unsupported-ghc-version
==> make install
==> Caveats
Run `cabal update` to initialize the package list.

If you are replacing a previous version of haskell-platform, you may want
to unregister packages belonging to the old version. You can find broken
packages using:
  ghc-pkg check --simple-output
You can uninstall them using:
  ghc-pkg check --simple-output | xargs -n 1 ghc-pkg unregister --force
==> Summary
🍺  /usr/local/Cellar/haskell-platform/2012.4.0.0: 952 files, 208M, built in 15.3 minutes

Once installed, you should be able to run:

$ ghc
ghc: no input files
Usage: For basic information, try the `--help' option.

As well as the Haskell interpreter, ghci:

$ ghci
GHCi, version 7.4.2: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> putStrLn "Hello World"
Hello World
Prelude>
Leaving GHCi.

Hope this helps!




回答2:


brew install haskell-platform is no longer supported. You may want to

Error: No available formula for haskell-platform
We no longer package haskell-platform. Consider installing ghc and cabal-install instead:
brew install ghc cabal-install




回答3:


Since haskell-platform on homebrew for Mac is deprecated, you can use brew install ghc cabal-install instead. I did it on Yosemite and it took about one minute…

> $ brew install ghc cabal-install                                             
==> Downloading https://homebrew.bintray.com/bottles/ghc-7.10.1_1.yosemite.bottl
######################################################################## 100.0%
==> Pouring ghc-7.10.1_1.yosemite.bottle.tar.gz
🍺  /usr/local/Cellar/ghc/7.10.1_1: 5423 files, 821M
==> Downloading https://homebrew.bintray.com/bottles/cabal-install-1.22.2.0.yose
######################################################################## 100.0%
==> Pouring cabal-install-1.22.2.0.yosemite.bottle.1.tar.gz
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
==> Summary
🍺  /usr/local/Cellar/cabal-install/1.22.2.0: 6 files, 19M



回答4:


This is an old question but given it comes quiet high on Google search. This is how I got here.

$ brew update
$ brew install haskell-stack
$ stack --version
$ stack --help # "man stack" gives something completely different
$ stack setup # Install GHC
$ stack ghci

Source: http://seanhess.github.io/2015/08/04/practical-haskell-getting-started.html

Why stack and not cabal?

Edit:

I found annoying to have to write "stack ghci" each time I wanted to use "ghci". A solution to this was to simply add these lines to the ~/.bash_aliases file:

alias sghc='stack ghc'
alias sghci='stack ghci'
alias srunhaskell='stack runhaskell'

Then source the file to apply:

$ source ~/.bash_aliases

Then I can run ghci and / or haskell running these commands, and it will use the stack version:

$ sghc [filename]
$ sghci
$ srunhaskell



回答5:


Update: February 2016: Whilst other answers were helpful, I didn't find a complete, up-to-date answer.

The install is easy:

$ brew install ghc cabal-install

An extra step I needed to perform post-install was:

$ cabal update

followed by:

$ cabal install ghc-mod

See here for details.

Alternatively, instead of using homebrew for the install, visit Haskell Platform for the installer disk image - note that Haskell Platform is only compatible with OS X 10.6 and later.

Although, as a general rule I always use homebrew to manage my dependencies, when it comes to Haskell my recommendation (unless you really know what you are doing) is to just install this binary. This avoids any surprises further down the road. There is excellent documentation post install locally at: file:///Library/Haskell/doc/start.html

The popular answer to this question (using brew to install haskell-platform) is no longer supported.




回答6:


Unfortunately, GHC 7.4 isn't supported on OS X 10.6; the download page only has an installer for 10.7, and as you can see, they mean it. I know your problem from bitter experience—I was in exactly your boat for a good long while, and I never found a solution other than upgrading Mac OS X (or, presumably, downgrading GHC, but I didn't really want to do that). A colleague of mine did manage to get 7.4.1 running on OS X 10.5, but it took nontrivial effort on her part (she had to use a different version of GMP, namely 5.0.5, and edit GHC's configure script), and I never tried to replicate it myself.

In the end, you have four options, in roughly decreasing order of simplicity:

  1. Use an older Haskell Platform. This means downgrading to GHC 7.0.x (not GHC 7.2.x—that was never in the Platform); there's not a good record of which GHC versions were in which package versions, though. Wikipedia implies that 2011.2 was the first version with GHC 7.0.x and that 2012.2 was the first version with GHC 7.4.x, so I'd try 2011.4.0.0 first.
  2. Install GHC 7.2 (which is supported on OS X) on its own, and forgo the Haskell Platform. This can cause headaches, but is possible. Don't forget to install Cabal, cabal-install, all the packages that come with the platform, etc.
  3. Upgrade to OS X 10.7 or 10.8, if you feel like a more global (and pricier) change.
  4. Try to replicate what my colleague did. (Best of luck, but it's definitely possible.)



回答7:


Late 2017 answer. I'm running macOS Sierra -- 10.12.6 (16G29). This worked successfully with an install time on my MacBook Air of under five minutes:

brew cask install haskell-platform

Then ghc --version reported:

The Glorious Glasgow Haskell Compilation System, version 8.2.1



来源:https://stackoverflow.com/questions/15709129/installing-haskell-packages-on-mac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!