学生の備忘録なブログ

日々のことを忘れないためのブログです。一日一成果物も目標。技術系はQiitaにあげるように変更しました。

Haskellの環境構築 ~zipのインストーラーは使わないほうがいい(教訓)~

結論

結局,公式でもなんでも,zipで入れるとあんまよくないことが起こる

詰まった所と原因

  1. cabal hell 
  2. インストール方法がいくつかあるということ

cabal hell

 Haskellはパッケージの導入方法が2017/04/15時点で2つある.

 cabalstackである.

 これらは,どうやらstackの方が便利でかつ簡単であるということで,移行している間のようである.

 しかし,公式のzipからダウンロードできる,ghc.appにはcabalとstackの両方が入っている.私は何も考えずにgoogle先生haskellの環境構築の方法を聞き,時代遅れの方法である,cabalを使って色々インストールしてみて,そして詰まった.これはひとえに何も考えずにやってしまった自分が悪い.

教訓

 新しい言語の環境構築に際してはパッケージインストーラーがどれが一番新しく,どれが一番簡単なのかを十分に吟味すること.  軟弱な*.appとかは信用しないこと

最終的に参考になったサイト

どうやらこれが一番簡素で2017/04/15時点でうまくいきそうである.

qiita.com

% stack setup    
Preparing to install GHC to an isolated location.
This will not interfere with any system-level installation.
Downloaded ghc-8.0.1.                                      
Installed GHC.                                                                  
stack will use a sandboxed GHC it installed
For more information on paths, see 'stack path' and 'stack exec env'
To use this GHC and packages outside of a project, consider using:
stack ghc, stack ghci, stack runghc, or stack exec

適当な作業ディレクトリに移動

% stack new project1 
Downloading template "new-template" to create project "project1" in project1/ ...

The following parameters were needed by the template but not provided: author-email, author-name, category, copyright, github-username
You can provide them in /Users/e155755/.stack/config.yaml, like this:
templates:
  params:
    author-email: value
    author-name: value
    category: value
    copyright: value
    github-username: value
Or you can pass each one as parameters like this:
stack new project1 new-template -p "author-email:value" -p "author-name:value" -p "category:value" -p "copyright:value" -p "github-username:value"

Looking for .cabal or package.yaml files to use to init the project.
Using cabal packages:
- project1/project1.cabal

Selecting the best among 10 snapshots...

Downloaded lts-8.10 build plan.    
Selected mirror https://s3.amazonaws.com/hackage.fpcomplete.com/                                 
Downloading root                                                                                 
Selected mirror https://s3.amazonaws.com/hackage.fpcomplete.com/                                 
Downloading timestamp                                                                            
Downloading snapshot                                                                             
Downloading mirrors                                                                              
Cannot update index (no local copy)                                                              
Downloading index                                                                                
Updated package list downloaded                                                                  
Populated index cache.                                                                           
* Matches lts-8.10

Selected resolver: lts-8.10
Initialising configuration using resolver: lts-8.10
Total number of user packages considered: 1
Writing configuration to file: project1/stack.yaml
All done.

注意する所

 超適当なことを書いて申し訳ないが,stackはどうやら,プロジェクト単位で構築してくれるらしい,そのため使用する時,自分のしたいことが,globalに適応したいことなのか,プロジェクト単位でしたいことなのかを考えなければならない.

project1% stack build
project1-0.1.0.0: configure (lib + exe)
Configuring project1-0.1.0.0...
project1-0.1.0.0: build (lib + exe)
Preprocessing library project1-0.1.0.0...
[1 of 1] Compiling Lib              ( src/Lib.hs, .stack-work/dist/x86_64-osx/Cabal-1.24.2.0/build/Lib.o )
Preprocessing executable 'project1-exe' for project1-0.1.0.0...
[1 of 1] Compiling Main             ( app/Main.hs, .stack-work/dist/x86_64-osx/Cabal-1.24.2.0/build/project1-exe/project1-exe-tmp/Main.o )
Linking .stack-work/dist/x86_64-osx/Cabal-1.24.2.0/build/project1-exe/project1-exe ...
project1-0.1.0.0: copy/register
Installing library in
project1/.stack-work/install/x86_64-osx/lts-8.10/8.0.2/lib/x86_64-osx-ghc-8.0.2/project1-0.1.0.0-E2z62tZALLo4yNw20HlUkg
Installing executable(s) in
project1/.stack-work/install/x86_64-osx/lts-8.10/8.0.2/bin
Registering project1-0.1.0.0...

/project1% stack runghc app/Main.hs        
someFunc

参考

qiita.com

d.hatena.ne.jp

uid0130.blogspot.jp

qiita.com

Haskell環境構築_20151226_最新版_4_投稿済み_stack-1.0.0対応版.md - Qiita