LoginSignup
5

More than 5 years have passed since last update.

Haskell インストールメモ

Posted at

はじめに

このメモは,私が Haskell を Mac OS X にインストールしたときの作業メモです.全ての工程は haskell.org の Wiki ページ, https://www.haskell.org/haskellwiki/Mac_OS_X の手順に基づいています.作業時のバージョンは,

  • Mac OS X 10.8.5
  • Haskell Platform 2014.2.0.0 for Mac OS X, 64bit

でした.

インストール手順

Haskell Platform

Wiki ページのリンクから Haskell Platform をダウンロードしてインストールします.

環境変数 PATH

~PATH~ を設定してパスを通します.

  • .zshenv

      export PATH=$HOME/Library/Haskell/bin:$PATH
    
  • init.el

      (add-to-list 'exec-path (expand-file-name "~/Library/Haskell/bin"))
    
    

clang で動くようにパッチを当てる

Xcode 5 の gcc は clang で,そのままでは GHC が動きまん.https://gist.github.com/mzero/7245290 の指示に従ってパッチを当てます.

hugs98

Wiki ページには MacPorts を使ってインストールするよう書いてあったのですが省略.

cabal-homebrew

Wiki によると C ライブラリに依存する Haskell のライブラリがあって,その依存先 C ライブラリは MacPorts でインストールするのが良いと書いてあります.しかし,私は Homebrew 派なので cabal-homebrew というスクリプトを用意します.

  • ~/Library/Haskell/bin/cabal-homebrew

      #!/bin/bash
    
      export CPPFLAGS=-I/opt/homebrew/include
      export LDFLAGS=-L/opt/homebrew/lib
      cabal $@ --extra-include-dirs=/opt/homebrew/
    
    
  • 使いかた

      $ cabal-macports install foobar
    
    

エディタの設定

あとにします.

mkbndl のインストール

「Haskell で Mac OS X アプリをつくるには mkbndl を使えばよい」という趣旨の記述が Wiki ページにありますが, インストール方法が書かれていません.Wiki ページのリンクを辿ると mkbndl が Haskell パッケージらしいことが分かり, もう少し調べると,Haskell プラットホームインストール時に同時にインストールされる cabal でインストールできることがわかるので,インストールします.

  $ cabal install mkbndl

  ,**********************************************************************

  === Configuration for cabal has been written to
      /Users/********/.cabal/config

  === Executables will be installed in:
      /Users/********/Library/Haskell/bin

      You may wish to place this on your PATH by adding the following
      line to your ~/.bash_profile:

      export PATH="$HOME/Library/Haskell/bin:$PATH"

  === When documentation is built, a master index to all documentation
      will be placed in:

      /Users/********/Library/Haskell/doc/index.html

      You may wish to bookmark that file once it gets built (after the
      first cabal install).

  ,**********************************************************************

  Downloading the latest package list from hackage.haskell.org
  Note: there is a new version of cabal-install available.
  To upgrade, run: cabal install cabal-install
  cabal: Can't parse
  "/Library/Frameworks/GHC.framework/Versions/7.8.3-x86_64/usr/lib/ghc-7.8.3/settings"

~cabal~ コマンド実行がはじめてのせいか,いろいろとメッセージが表示されます.あとでメッセージの指示に従っておきます.

  • 設定ファイル
    • /Users/********/.cabal/config
  • パスを通す
    • /Users/********/Library/Haskell/bin
    • 既に通した
  • cabal をアップデート
    • cabal install cabal-install

そして,一番最後に気になるメッセージが,

  cabal: Can't parse
  "/Library/Frameworks/GHC.framework/Versions/7.8.3-x86_64/usr/lib/ghc-7.8.3/settings"

さきほど,Xcode 5 の clang 対応のためにあてたパッチがファイルを壊しているようです.確認してみると,

  diff -U 2 /Library/Frameworks/GHC.framework/Versions/7.8.3-x86_64/usr/lib/ghc-7.8.3/settings.bak /Library/Frameworks/GHC.framework/Versions/7.8.3-x86_64/usr/lib/ghc-7.8.3/settings
  --- /Library/Frameworks/GHC.framework/Versions/7.8.3-x86_64/usr/lib/ghc-7.8.3/settings.bak ...
  +++ /Library/Frameworks/GHC.framework/Versions/7.8.3-x86_64/usr/lib/ghc-7.8.3/settings ...
  @@ -1,4 +1,4 @@
   [ ("GCC extra via C opts"," -fwrapv")
  -, ("C compiler command","/usr/bin/gcc")
  +, ("C compiler command"/usr/bin/ghc-clang-wrapper")
   , ("C compiler flags"," -m64 -fno-stack-protector")
   , ("C compiler link flags"," -m64")

  Diff finished.  Mon Nov 17 08:19:50 2014

地味に壊していたようなので直しておきます.

直したら cabal-install です.

  $ cabal install cabal-install
  ...

  $ cabal install mkbndl
  ...

  Preprocessing executable 'mkbndl' for mkbndl-0.2.1...

  Main.hs:1:1:
      Ambiguous module name ‘Prelude’:
        it was found in multiple packages: base haskell98-2.0.0.3
  cabal: Error: some packages failed to install:
  mkbndl-0.2.1 failed during the building phase. The exception was:
  ExitFailure 1

mkbndl はあきらめることにします.

Emacs/ghc-mod 環境構築

Emacs で Haskell を書けるように ghc-mod の環境をつくります.

ghc-mod インストール

http://www.mew.org/~kazu/proj/ghc-mod/en/install.html の手順に従います.

  $ cabal update

  $ cabal install ghc-mod

かなり時間かかります.

haskell-mode のインストール

  • \~/.emacs.d/Cask(depends-on "ghc") を追加
  • cask コマンドを実行してインストール
  • init.el に追加:

      (require 'haskell-mode)
      (add-hook 'haskell-mode-hook 'turn-on-haskell-unicode-input-method)
      (add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
      (eval-after-load "haskell-mode"
        '(progn
           (define-key haskell-mode-map (kbd "C-,") 'haskell-move-nested-left)
           (define-key haskell-mode-map (kbd "C-.") 'haskell-move-nested-right)))
      (add-hook 'haskell-mode-hook 'turn-on-haskell-decl-scan)
      (eval-after-load "which-func"
        '(add-to-list 'which-func-modes 'haskell-mode))
      (eval-after-load "haskell-mode"
          '(define-key haskell-mode-map (kbd "C-c C-c") 'haskell-compile))
      (eval-after-load "haskell-cabal"
          '(define-key haskell-cabal-mode-map (kbd "C-c C-c") 'haskell-compile))
      (eval-after-load "haskell-mode"
        '(progn
          (define-key haskell-mode-map (kbd "C-x C-d") nil)
          (define-key haskell-mode-map (kbd "C-c C-z") 'haskell-interactive-switch)
          (define-key haskell-mode-map (kbd "C-c C-l") 'haskell-process-load-file)
          (define-key haskell-mode-map (kbd "C-c C-b") 'haskell-interactive-switch)
          (define-key haskell-mode-map (kbd "C-c C-t") 'haskell-process-do-type)
          (define-key haskell-mode-map (kbd "C-c C-i") 'haskell-process-do-info)
          (define-key haskell-mode-map (kbd "C-c M-.") nil)
          (define-key haskell-mode-map (kbd "C-c C-d") nil)))
    
    

ghc (Emacs) インストール

上に示した公式サイトの手順では

Please use stable MELPA to download Emacs front-end.

となっていたのですが,私の Cask 設定はそうなっていないので,普通の MELPA を使います.

  • \~/.emacs.d/Cask(depends-on "ghc") を追加
  • cask コマンドを実行してインストール
  • init.el に追加:

      (require 'ghc)
      (autoload 'ghc-init "ghc" nil t)
      (autoload 'ghc-debug "ghc" nil t)
      (add-hook 'haskell-mode-hook 'ghc-init)
    
    

おわりに

つらい

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5