学生の備忘録なブログ

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

Haskellの環境構築 ~importできないとき~

importできないときは

 参考書のコードをそのまま入れてみても,実際は動かないことが多い.これはどの言語にも起こる.めげない.

原因

 パッケージがそもそもない,あるいはコンパイラが参照できないか.この場合は参照である.

解決策

 stackのプロジェクト機能で環境構築をした.この場合はワークスペースディレクトリ内部に*.cabalという設定ファイルがあるため,ここのライブラリに書き加えれば良い.

改善する前

% stack build
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 )

/Users/hoge/Desktop/Software-engineering/project1/src/Lib.hs:4:1: error:
    Failed to load interface for ‘Data.Map’
    It is a member of the hidden package ‘containers-0.5.7.1’.
    Perhaps you need to add ‘containers’ to the build-depends in your .cabal file.
    Use -v to see a list of the files searched for.

--  While building package project1-0.1.0.0 using:
      /Users/hoge/.stack/setup-exe-cache/x86_64-osx/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --builddir=.stack-work/dist/x86_64-osx/Cabal-1.24.2.0 build lib:project1 exe:project1-exe --ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure 1

  Perhaps you need to add ‘containers’ to the build-depends in your .cabal file.

 ここから,containsersが足りないようだと分かる.  よって,設定ファイル*.cabalに', containers'を追記した.

name:                project1
version:             0.1.0.0
-- synopsis:
-- description:
homepage:            https://github.com/githubuser/project1#readme
license:             BSD3
license-file:        LICENSE
author:              Author name here
maintainer:          example@example.com
copyright:           2017 Author name here
category:            Web
build-type:          Simple
extra-source-files:  README.md
cabal-version:       >=1.10

library
  hs-source-dirs:      src
  exposed-modules:     Lib
  build-depends:       base >= 4.7 && < 5
                     , containers
  default-language:    Haskell2010

executable project1-exe
  hs-source-dirs:      app
  main-is:             Main.hs
  ghc-options:         -threaded -rtsopts -with-rtsopts=-N
  build-depends:       base
                     , project1
  default-language:    Haskell2010

test-suite project1-test
  type:                exitcode-stdio-1.0
  hs-source-dirs:      test
  main-is:             Spec.hs
  build-depends:       base
                     , project1
  ghc-options:         -threaded -rtsopts -with-rtsopts=-N
  default-language:    Haskell2010

source-repository head
  type:     git
  location: https://github.com/githubuser/project1

 これで実行することができた.

参考元

Stackでやる最速Haskell Hello world! (GHCのインストール付き!) - Qiita

Haskellの環境構築

できるかな?IDE導入編

Stackを使ったHaskellのインストール - Qiita

GitHub - rikvdkleij/intellij-haskell: IntelliJ plugin for Haskell

% stack install hindent 
attoparsec-0.13.1.0: configure
base-orphans-0.5.4: download
StateVar-1.1.0.4: download
cabal-doctest-1: download
attoparsec-0.13.1.0: build
base-orphans-0.5.4: configure
base-orphans-0.5.4: build
StateVar-1.1.0.4: configure
base-orphans-0.5.4: copy/register
StateVar-1.1.0.4: build
cabal-doctest-1: configure
StateVar-1.1.0.4: copy/register
cabal-doctest-1: build
haskell-src-exts-1.18.2: configure
monad-loops-0.4.3: download
haskell-src-exts-1.18.2: build
monad-loops-0.4.3: configure
monad-loops-0.4.3: build
cabal-doctest-1: copy/register
distributive-0.5.2: download
distributive-0.5.2: configure
monad-loops-0.4.3: copy/register
semigroups-0.18.2: download
distributive-0.5.2: build
semigroups-0.18.2: configure
semigroups-0.18.2: build
semigroups-0.18.2: copy/register
temporary-1.2.0.4: download
temporary-1.2.0.4: configure
distributive-0.5.2: copy/register
temporary-1.2.0.4: build
void-0.7.2: download
temporary-1.2.0.4: copy/register
void-0.7.2: configure
void-0.7.2: build
void-0.7.2: copy/register
contravariant-1.4: download
contravariant-1.4: configure
contravariant-1.4: build
contravariant-1.4: copy/register
comonad-5: download
comonad-5: configure
Package comonad uses a custom Cabal build, but does not use a custom-setup stanza
Not using the explicit setup deps approach based on configuration
Strongly recommend fixing the package's cabal file
comonad-5: build
Package comonad uses a custom Cabal build, but does not use a custom-setup stanza
Not using the explicit setup deps approach based on configuration
Strongly recommend fixing the package's cabal file
comonad-5: copy/register
Package comonad uses a custom Cabal build, but does not use a custom-setup stanza
Not using the explicit setup deps approach based on configuration
Strongly recommend fixing the package's cabal file
Package comonad uses a custom Cabal build, but does not use a custom-setup stanza
Not using the explicit setup deps approach based on configuration
Strongly recommend fixing the package's cabal file
bifunctors-5.4.1: download
bifunctors-5.4.1: configure
bifunctors-5.4.1: build
bifunctors-5.4.1: copy/register
attoparsec-0.13.1.0: copy/register
aeson-1.0.2.1: configure
aeson-1.0.2.1: build
aeson-1.0.2.1: copy/register
path-0.5.13: download
descriptive-0.9.4: download
yaml-0.8.22: download
descriptive-0.9.4: configure
descriptive-0.9.4: build
path-0.5.13: configure
path-0.5.13: build
yaml-0.8.22: configure
yaml-0.8.22: build
path-0.5.13: copy/register
path-io-1.2.2: download
path-io-1.2.2: configure
path-io-1.2.2: build
path-io-1.2.2: copy/register
descriptive-0.9.4: copy/register
haskell-src-exts-1.18.2: copy/register
yaml-0.8.22: copy/register
hindent-5.2.2: download
hindent-5.2.2: configure
hindent-5.2.2: build
hindent-5.2.2: copy/register
Completed 19 action(s).
Copying from /Users/e155755/.stack/snapshots/x86_64-osx/lts-8.10/8.0.2/bin/hindent to /Users/e155755/.local/bin/hindent

Copied executables to /Users/e155755/.local/bin:
- hindent
% stack install ghc-mod 
fail-4.9.0.0: download
fail-4.9.0.0: configure
cabal-helper-0.7.3.0: download
ansi-wl-pprint-0.6.7.3: download
djinn-lib-0.0.1.2: download
fail-4.9.0.0: build
ansi-wl-pprint-0.6.7.3: configure
fail-4.9.0.0: copy/register
ansi-wl-pprint-0.6.7.3: build
djinn-lib-0.0.1.2: configure
MonadRandom-0.5.1: download
djinn-lib-0.0.1.2: build
cabal-helper-0.7.3.0: configure
ansi-wl-pprint-0.6.7.3: copy/register
fclabels-2.0.3.2: download
cabal-helper-0.7.3.0: build
MonadRandom-0.5.1: configure
MonadRandom-0.5.1: build
fclabels-2.0.3.2: configure
fclabels-2.0.3.2: build
djinn-lib-0.0.1.2: copy/register
djinn-ghc-0.0.2.3: download
djinn-ghc-0.0.2.3: configure
djinn-ghc-0.0.2.3: build
MonadRandom-0.5.1: copy/register
ghc-syb-utils-0.2.3: download
ghc-syb-utils-0.2.3: configure
djinn-ghc-0.0.2.3: copy/register
ghc-syb-utils-0.2.3: build
optparse-applicative-0.13.2.0: download
fclabels-2.0.3.2: copy/register
optparse-applicative-0.13.2.0: configure
optparse-applicative-0.13.2.0: build
pipes-4.3.2: download
pipes-4.3.2: configure
pipes-4.3.2: build
ghc-syb-utils-0.2.3: copy/register
prelude-extras-0.4.0.3: download
prelude-extras-0.4.0.3: configure
prelude-extras-0.4.0.3: build
pipes-4.3.2: copy/register
cabal-helper-0.7.3.0: copy/register
profunctors-5.2: download
optparse-applicative-0.13.2.0: copy/register
profunctors-5.2: configure
prelude-extras-0.4.0.3: copy/register
safe-0.3.14: download
profunctors-5.2: build
safe-0.3.14: configure
semigroupoids-5.1: download
split-0.2.3.1: download
safe-0.3.14: build
split-0.2.3.1: configure
split-0.2.3.1: build
semigroupoids-5.1: configure
Package semigroupoids uses a custom Cabal build, but does not use a custom-setup stanza
Not using the explicit setup deps approach based on configuration
Strongly recommend fixing the package's cabal file
split-0.2.3.1: copy/register
safe-0.3.14: copy/register
semigroupoids-5.1: build
Package semigroupoids uses a custom Cabal build, but does not use a custom-setup stanza
Not using the explicit setup deps approach based on configuration
Strongly recommend fixing the package's cabal file
profunctors-5.2: copy/register
semigroupoids-5.1: copy/register
Package semigroupoids uses a custom Cabal build, but does not use a custom-setup stanza
Not using the explicit setup deps approach based on configuration
Strongly recommend fixing the package's cabal file
Package semigroupoids uses a custom Cabal build, but does not use a custom-setup stanza
Not using the explicit setup deps approach based on configuration
Strongly recommend fixing the package's cabal file
free-4.12.4: download
free-4.12.4: configure
free-4.12.4: build
free-4.12.4: copy/register
either-4.4.1.1: download
either-4.4.1.1: configure
either-4.4.1.1: build
either-4.4.1.1: copy/register
monad-journal-0.7.2: download
monad-journal-0.7.2: configure
monad-journal-0.7.2: build
monad-journal-0.7.2: copy/register
ghc-mod-5.7.0.0: download
ghc-mod-5.7.0.0: configure
ghc-mod-5.7.0.0: build
ghc-mod-5.7.0.0: copy/register
Completed 19 action(s).
Copying from /Users/e155755/.stack/snapshots/x86_64-osx/lts-8.10/8.0.2/bin/ghc-mod to /Users/e155755/.local/bin/ghc-mod
Copying from /Users/e155755/.stack/snapshots/x86_64-osx/lts-8.10/8.0.2/bin/ghc-modi to /Users/e155755/.local/bin/ghc-modi

Copied executables to /Users/e155755/.local/bin:
- ghc-mod
- ghc-modi

blogについて

就職説明会を思い起こして

 就職説明会を思い起こしてみて,そして「某R社を5日でクビになった話」を読んでみてふと思ったこと

http://megalodon.jp/2015-0307-0116-16/codeio.hateblo.jp/entry/2015/03/07/003348  

  1. facebookをやったほうが良いのか
  2. 業界のことを知っておくのにはどうすればよいか.

なぜか

 就職の際には理系は,その人の技術力が問われる.これをぱっとわかりやすく表すのと思うのは,

  1. sns
  2. githubリポジトリ
  3. blog

 であると思う.

 これらを充実させておけば,面接官は普段この人はどのような活動をしているかが分かる.  

 扱っている内容から,技術力,知識,やる気がある程度図れる.

結論

 就職期間に入るのをただ待つのではなく,それまでに実績を作りたい.

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

Haskellの実行

Haskellの実行をやってみた.

参考にしたサイト

d.hatena.ne.jp

実行結果

$runghc-7.10.3 hello.hs
Hello, World!

$ghc -o hello hello.hs
Hello, World!

$./hello
Hello, World!

M-! quickrun
Hello, World!

考察

 emacsでquickrunを使っても実行することができた.

Haskellの環境設定~pathを正しく通そう~

Haskellの導入について

 講義でHaskellの課題が出たが,早速環境構築で詰まった.

ghcが入らなくて詰まった.

 このサイトを参考にしたが以下のエラーが

qiita.com

zsh: command not found: ghci

これになったときは,パスが通ってないかもしれない!

パスの通し方.

 パスの書き方は,中途半端な理解なので,中略.

zmodload zsh/zprof && zprof
export GHC_DOT_APP="/Applications/ghc-7.10.3.app"
if [ -d "$GHC_DOT_APP" ]; then
  export PATH="${HOME}/.local/bin:${HOME}/.cabal/bin:${GHC_DOT_APP}/Contents/bin:${PATH}"
fi

結果

 pathを.zsh関連のファイルに片っ端から書いて,試した.

 よくよく見たら,インストーラーが自動で入れる,というか.zshenvに直接書き込んでくるpathが,自分の環境とあってなくて,入らなかったようである.

 /Applications がどこにあるのかややこしくなってる.ほんとにどうしようか.

教訓

  1. インストールしたものがnot found になったら,まずpathを確認する.

  2. インストーラーは万能ではないので,どんなパスの繋げ方をしているのか,確認する.

ラーニングピラミッド

はてbをみて,気になった記事

www.yukisako.xyz

気になった画像

https://cdn-ak.f.st-hatena.com/images/fotolife/M/McG/20170410/20170410140222.png

感想

 講義を聞いた時点での理解度が5%というのは,ショッキングだが,納得である.  とりあえず以上.

と思ったが,,,

 今日は就職説明会があり,それの備忘録を書いていくのが良いだろう.これは書かなければならないという何か自分の中に何か突き動かすものがあるから.  

自分の中の就職先

 自分は,機械学習関係を就職先として考えている.  就職先には,4年になってからでは遅い.大きな声では言えないらしいが,3年の8月とか,目をつけるだけなら,3年2月とかから,一日インターンとかで目を付けられているらしい.

 まあ,日本は特殊である.一斉に就職活動をするのは恐らくは戦後の集団就職の名残だろうと私は考えている.

 自分の中のコーチング的に言えばwant to,に目を向けなければならない.自分は自信の無さから,自分の本当にやりたいことから目をそむけてきた.自分が小さい頃から,,,,,,,という風に続けて書くつもりだったが,本当にそうだろうか.

本当にやりたいこと

 自分はいつもそれだなと思うが,本当にやりたいことはなんだろうかといつも考えている.    つまりは,迷走しているということだ.

 実際,自分の道はこれしかない,と言う気付きが人生の中であるのだろうか.あって欲しい.少なくとも,自分は自らの責任を以て,自主的に,精力的に何かに注力したことがない.今,自分はこの道ではないか,と思っている機械学習の道にも,pythonにちょっと触るだけで,放り投げてしまっている現状がある.

自分らしくない自分らしくない

私の動機を肯定的に見てみる

 予想は,三つ建てるべきである.

 一つ,楽観的予想,

 二つ,悲観的予想

 そして三つめに,現実的予想である

あとで,就職活動については追記する

  * 自己分析をすること. * 業界のこと,大手会社名,周辺企業の会社名,業務内容を興味のあるところを探す. * 常にアンテナをはり,新聞などから情報を得る. * 就活は3年次のインターンで決まっている.

これだけは覚えておきたい.