LoginSignup
22
28

More than 5 years have passed since last update.

Haskell開発環境の構築 (Linux編)

Last updated at Posted at 2015-07-18

はじめに

この記事では、以下二点を目標に話を進める。

  • Linux 上に最低限の Haskell 開発環境を構築する
  • vim で ghc-mod による入力補完が使えるようにする

以下の点は扱わない。

  • cabal ファイルの書き方
  • stack の使い方
  • vim プラグインの導入/使い方

stack 導入

Haskell 環境構築のため、まずは stack を導入する。
stack は最近登場した Haskell のパッケージ管理/ビルドツール1で、色々便利なので入れておく。

筆者の利用する Arch Linux では yaourt で導入可能。

yaourt -S haskell-stack

GHC とライブラリの導入

導入は stack が自動でやってくれる。

  • 以下コマンドを実行
stack setup

プロジェクト作成

stack を使ってプロジェクトを作成する。

# 作業ディレクトリに移動
cd workspace/sample

# プロジェクトの作成
stack new

# ビルド
stack build

# 実行
stack exec new-template-exe

ghc-mod 導入

Haskell の高度な補完のため、 ghc-mod を導入する。

stack install cabal-install ghc-mod

ghc-mod のラッパー作成

ghc-mod などのツールは stack exec コマンド経由でのみ実行可能であり、このままでは vim から認識できない。vim から認識させるため、Haskell プラグイン自体を修正してもよいが、今回はラッパースクリプトを用意して対応する。

  • 以下のスクリプトをパスの通ったところ(/usr/local/bin など)に配置する。
ghc-mod
#!/bin/sh

stack exec -- ghc-mod $*
ghc-mod-configure
#!/bin/sh

PATH=$(stack path --bin-path):$PATH cabal configure \
  --package-db=clear \
  --package-db=global \
  --package-db=$(stack path --snapshot-pkg-db) \
  --package-db=$(stack path --local-pkg-db)
  • プロジェクトの状態を更新する
    • cabal ファイル更新のたびに再実行が必要
# 作業ディレクトリに移動
cd workspace/sample

# 更新
ghc-mod-configure

vim

neobundle で以下のパッケージをインストールする

設定は適宜

スクリーンショット

vim-ghc-mod.png

課題

  • cabal ファイル変更時に stack build, ghc-mod-configure の再実行が必要

参考/関連


  1. Rubyist 向けにいうと、 stack ≒ rbenv + ruby-install + bundler + rake 

22
28
1

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
22
28