10000hの技術メモ

この先生きのこるための勉強内容&時間記録

Haskell入門 1.2 〜 1.3

Haskell入門 関数型プログラミング言語の基礎と実践

Haskell入門 関数型プログラミング言語の基礎と実践

コンパイラとしてGHC、ビルドツールとしてStackを使う。

1.2 実行環境の構築

Stackのインストール

curl -sSL https://get.haskellstack.org/ | sh

WARNINGが出た。

WARNING: '/Users/yoshikiito/.local/bin' is not on your PATH.
    For best results, please add it to the beginning of PATH in your profile.

一旦スルー。

GHCのインストールなど

$ stack setup

ここでトラブる。

configure: WARNING: configure can't recognize your CPP program, you may need to set --with-hs-cpp-flags=FLAGS explicitly configure: error: in /Users/yoshikiito/.stack/programs/x86_64-osx/ghc-8.0.2.temp/ghc-8.0.2': configure: error: C compiler cannot create executables Seeconfig.log' for more details

Error: Error encountered while configuring GHC with /Users/yoshikiito/.stack/programs/x86_64-osx/ghc-8.0.2.temp/ghc-8.0.2/configure --prefix=/Users/yoshikiito/.stack/programs/x86_64-osx/ghc-8.0.2/ run in /Users/yoshikiito/.stack/programs/x86_64-osx/ghc-8.0.2.temp/ghc-8.0.2/

ここで指定されたconfig.logの中身を見てみると、

$ sudo xcodebuild -license

しろと書いてあるので実行。

ライセンス条項に同意したのち、再度$stack setupを行うことで、インストールが完了した。

いちおう参考:c++ - Haskell Stack Setup - Can't Recognize CPP Program - Stack Overflow

1.3 REPLとスクリプトの実行

対話的な実行環境REPL(Read-Eval-Print Loop)

ghciはStackから起動する。

$stack ghci

各種commandは本を参照。

ファイルに書いたスクリプトを直接実行

$ stack runghc hello.hs

今回の勉強時間 1時間30分

累計勉強時間 19時間13分