Haskell に入門するために開発環境を整える
『すごい H 本』こと『すごい Haskell たのしく学ぼう!』をざざっと読んだので、実際に手を動かしてみたい。ということで、開発環境を整える。
Stack
Stack というツールで GHC (コンパイラ)のインストールやコードのビルドができるらしい。
- Home - The Haskell Tool Stack
- 本気で Haskell したい人向けの Stack チュートリアル - Qiita
- Stackでやる最速Haskell Hello world! (GHCのインストール付き!) - Qiita
まず Homebrew でインストール。
$ brew install stack
新規プロジェクト hello-world
を作る。
$ stack new hello-world Downloading template "new-template" to create project "hello-world" in hello-world/ ... The following parameters were needed by the template but not provided: author-name You can provide them in /Users/mimikakimemo/.stack/config.yaml, like this: templates: params: author-name: value Or you can pass each one as parameters like this: stack new hello-world new-template -p "author-name:value" 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/mimikakimemo/.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 hello-world 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: - hello-world/ Selecting the best among 15 snapshots... 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 index downloaded Update complete Populated index cache. * Matches lts-13.5 Selected resolver: lts-13.5 Initialising configuration using resolver: lts-13.5 Total number of user packages considered: 1 Writing configuration to file: hello-world/stack.yaml All done.
途中の Downloading index
でやたらと時間がかかってフリーズしたかと思ったが、10分ほどで完了した。
$ cd hello-world $ tree -a . ├── .gitignore ├── ChangeLog.md ├── LICENSE ├── README.md ├── Setup.hs ├── app/ │ └── Main.hs ├── hello-world.cabal ├── package.yaml ├── src/ │ └── Lib.hs ├── stack.yaml └── test/ └── Spec.hs
stack build
で GHC のインストールもしてくれる。
$ stack build Preparing to install GHC to an isolated location. This will not interfere with any system-level installation. Downloaded ghc-8.6.3. Installed GHC. [1 of 2] Compiling Main ( /Users/mimikakimemo/.stack/setup-exe-src/setup-mPHDZzAJ.hs, /Users/mimikakimemo/.stack/setup-exe-src/setup-mPHDZzAJ.o ) [2 of 2] Compiling StackSetupShim ( /Users/mimikakimemo/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs, /Users/mimikakimemo/.stack/setup-exe-src/setup-shim-mPHDZzAJ.o ) Linking /Users/mimikakimemo/.stack/setup-exe-cache/x86_64-osx/tmp-Cabal-simple_mPHDZzAJ_2.4.0.1_ghc-8.6.3 ... Building all executables for `hello-world' once. After a successful build of all of them, only specified executables will be rebuilt. hello-world-0.1.0.0: configure (lib + exe) Configuring hello-world-0.1.0.0... hello-world-0.1.0.0: build (lib + exe) Preprocessing library for hello-world-0.1.0.0.. Building library for hello-world-0.1.0.0.. [1 of 2] Compiling Lib ( src/Lib.hs, .stack-work/dist/x86_64-osx/Cabal-2.4.0.1/build/Lib.o ) [2 of 2] Compiling Paths_hello_world ( .stack-work/dist/x86_64-osx/Cabal-2.4.0.1/build/autogen/Paths_hello_world.hs, .stack-work/dist/x86_64-osx/Cabal-2.4.0.1/build/Paths_hello_world.o ) Preprocessing executable 'hello-world-exe' for hello-world-0.1.0.0.. Building executable 'hello-world-exe' for hello-world-0.1.0.0.. [1 of 2] Compiling Main ( app/Main.hs, .stack-work/dist/x86_64-osx/Cabal-2.4.0.1/build/hello-world-exe/hello-world-exe-tmp/Main.o ) [2 of 2] Compiling Paths_hello_world ( .stack-work/dist/x86_64-osx/Cabal-2.4.0.1/build/hello-world-exe/autogen/Paths_hello_world.hs, .stack-work/dist/x86_64-osx/Cabal-2.4.0.1/build/hello-world-exe/hello-world-exe-tmp/Paths_hello_world.o ) Linking .stack-work/dist/x86_64-osx/Cabal-2.4.0.1/build/hello-world-exe/hello-world-exe ... hello-world-0.1.0.0: copy/register Installing library in /Users/mimikakimemo/repos/hello-world/.stack-work/install/x86_64-osx/lts-13.5/8.6.3/lib/x86_64-osx-ghc-8.6.3/hello-world-0.1.0.0-NpaWwN61fJ91LUORGYsB Installing executable hello-world-exe in /Users/mimikakimemo/repos/hello-world/.stack-work/install/x86_64-osx/lts-13.5/8.6.3/bin Registering library for hello-world-0.1.0.0..
stack exec <プロジェクト名>-exe
で実行できるらしい。
$ stack exec hello-world-exe someFunc
用意されている app/Main.hs
の内容。
module Main where import Lib main :: IO () main = someFunc
インポートされている src/Lib.hs
はこうなっている。
module Lib ( someFunc ) where someFunc :: IO () someFunc = putStrLn "someFunc"
よって、最終行を someFunc = putStrLn "Hello, world!"
に書き換えてビルド・実行すれば、
$ stack build hello-world-0.1.0.0: unregistering (local file changes: src/Lib.hs) hello-world-0.1.0.0: build (lib + exe) Preprocessing library for hello-world-0.1.0.0.. Building library for hello-world-0.1.0.0.. [2 of 2] Compiling Lib ( src/Lib.hs, .stack-work/dist/x86_64-osx/Cabal-2.4.0.1/build/Lib.o ) Preprocessing executable 'hello-world-exe' for hello-world-0.1.0.0.. Building executable 'hello-world-exe' for hello-world-0.1.0.0.. [1 of 2] Compiling Main ( app/Main.hs, .stack-work/dist/x86_64-osx/Cabal-2.4.0.1/build/hello-world-exe/hello-world-exe-tmp/Main.o ) [Lib changed] Linking .stack-work/dist/x86_64-osx/Cabal-2.4.0.1/build/hello-world-exe/hello-world-exe ... hello-world-0.1.0.0: copy/register Installing library in /Users/mimikakimemo/repos/hello-world/.stack-work/install/x86_64-osx/lts-13.5/8.6.3/lib/x86_64-osx-ghc-8.6.3/hello-world-0.1.0.0-NpaWwN61fJ91LUORGYsB Installing executable hello-world-exe in /Users/mimikakimemo/repos/hello-world/.stack-work/install/x86_64-osx/lts-13.5/8.6.3/bin Registering library for hello-world-0.1.0.0.. $ stack exec hello-world-exe Hello, world!
Hello, world!
と表示される。
その他
- 作者: Miran Lipovača,田中英行,村主崇行
- 出版社/メーカー: オーム社
- 発売日: 2012/05/23
- メディア: 単行本(ソフトカバー)
- 購入: 25人 クリック: 580回
- この商品を含むブログ (73件) を見る
XREA 上の既存サイトに対して無料 SSL の設定をする
XREA で無料 SSL が使えるようになっていたので、独自ドメインで運用しているサイトに対して、今さらながらこれを有効にした。
無料SSLの新規設定 | サイト設定 | マニュアル | 無料から使える高機能・高品質レンタルサーバー | XREA(エクスリア)
これまでは、"Main" サイトに独自ドメインを割り当てて運用していた。この "Main" のサイト設定を開き、上のマニュアルを参考に設定しようとしたが、「無料 SSL」の項目がグレーアウトしていて選択できない。
そこで、以下のように設定すると、うまくいくことがわかった。
- "Main" のドメインを、独自ドメインからデフォルトの
<アカウント名>.sXXX.xrea.com
に変更 - [サイト設定の新規作成] ボタンをクリックし、以下の設定で作成
- ドキュメントルートが変更されるので、
putblic_html
の内容をpublic_html/<独自ドメイン>
へと移動
この設定方法に関しては、 XREA 掲示板の以下の書き込みを参考にした。
ちなみにこの無料 SSL は、Let's Encrypt を利用しているらしい。
11ac 対応で GbE なルータ FFP-1200DHP を購入した
これまでは、2年半ぐらい前に買った Buffalo のルータ WZR-HP-G302H を使っていた。
が、最近 WAN 側の接続が一日一回ぐらい切れるようになり、調子が悪かった。無線も 2.4GHz 帯のみだったり、11ac に対応していなかったりと、今どきの使い方だと少し不満も出てきたので、ここで買い替えることにした。
- 出版社/メーカー: プラネックス
- 発売日: 2013/11/05
- メディア: Personal Computers
- この商品を含むブログ (4件) を見る
買ったのは Planex の FFP-1200DHP という機種。Amazon のタイムセールで見つけて、あまり考えずに選んだ。4,980円。この FFP-1200DHP は、下の MZK-1200DHP の包装を簡易にした(だけの)ものらしく、500円ぐらい安くなっている。
PLANEX 11ac 無線LAN中継機 オールギガ 866+300Mbps MZK-1200DHP(SC) 見えルンです対応
- 出版社/メーカー: PLANEX
- メディア: エレクトロニクス
- この商品を含むブログを見る
写真だと本体の色がグレーやアイボリーあたりにも見えるが、実物を見てみると薄い水色といった感じ。少し変わった色だが、とくに不満はない。これまでの WZR-HP-G302H は黒の鏡面仕上げで、ホコリが気になっていた。大きさもこちらの方がコンパクトで良い。現在、以下の機器が LAN 内にある。
- 有線
- LIVA
- 鼻毛鯖
- 無線(11ac対応)
- 無線(11ac非対応)
- kobo glo
- プリンタ
デフォルトの設定画面は、かなりシンプルでわかりやすいデザインになっている。もちろん、詳細設定もできる。今回設定した部分は以下のとおり。
- SSID を hogehoge_nomap にする
- LAN 側の IP アドレスを 192.168.111.1 から 192.168.11.1 に変更(前の環境に合わせる)
- DHCP を無効にする(LIVA で動かしている dnsmasq を使う)
- 「ポートフォワード」で 5555/TCP, 500/UDP, 4500/UDP を LIVA に転送する(SoftEther VPN 用)
まだ使い始めだが、とりあえず良い感じ。
NTP の設定
Chinachu で録画開始のタイミングがズレると思ったら、そういえば NTP の設定をしていなかった。というわけで設定。
$ sudo apt-get install ntp
/etc/ntp.conf の同期先サーバーの設定を変更。
# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board # on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for # more information. server ntp1.jst.mfeed.ad.jp server ntp2.jst.mfeed.ad.jp server ntp3.jst.mfeed.ad.jp
ntpd を再起動。
$ sudo service ntp restart
低価格 SSD 「Crucial MX100」を買って LIVA のストレージにした
LIVA の内蔵ストレージ(eMMC)は32GBしかないため、地デジを録画するとたったの数時間分でいっぱいになってしまう。録画したファイルを貯めておけるような NAS は持っていないので、LIVA にストレージを外付けすることにした。
安くて大容量な HDD にしようかとも思ったが、今回は速くて静音な SSD にした。ちょうど先月 Crucial MX100 が発売され、コストパフォーマンスの良さが話題になっていたので、これの 256GB モデル CT256MX100SSD1 を選択。
Crucial MX100 2.5インチ内蔵型SSD 256GB SATAIII CT256MX100SSD1
- 出版社/メーカー: Crucial Technology
- 発売日: 2014/06/05
- メディア: Personal Computers
- この商品を含むブログ (1件) を見る
そのころ(先月半ば)は品薄状態だったこともあり、結局 BUY MORE 秋葉原本店で並行輸入品を購入。並行輸入品の保証期間は10ヶ月だが、その分若干割安で税込10,980円だった。
一緒に、2.5インチ SSD/HDD 外付けケース「黒角MINI OWL-ESL25S/U3(B)」を購入。このケースはアルミ製でちゃちくなく、USB 3.0 に対応している。ヨドバシで1,990円。
このケースに SSD を入れ、LIVA の USB 3.0 ポートに繫いだ。が、LIVA の USB ポートの出力が足りないのか、それだけではうまく動かない。ケースに付属している電源補助ケーブル(2股になったUSB ケーブル)を使い、USB 3.0, USB 2.0 の両ポートに接続すると一応動くが、それでも転送速度がかなり遅くなる。面倒だったので詳しく調べなかったが、USB 2.0 の上限速度(480Mbps)程度になっていた。
これでは使い物にならないため、セルフパワーの USB 3.0 ハブを買ってきてここに外付けケースを接続することにした。セルフパワー USB 3.0 ハブはまだあまり選択肢がないようで、値段がちょっと高い。エレコムの U3H-T403SBK を2,590円で買った。
ELECOM USBハブ 超高速USB3.0対応 強力マグネット・コードキーパー付 セルフ・バスパワー両対応 4ポート 1.0m ブラック 【PS4対応】 U3H-T403SBK
- 出版社/メーカー: エレコム
- 発売日: 2013/01/31
- メディア: Personal Computers
- この商品を含むブログを見る
外付けケース(SSD)―― USB 3.0 ハブ ―― LIVA USB 3.0 ポート という形になり、これでようやく快適に動くようになった。速度も十分出ている。
結局いろいろ買ってしまったが、安定して動いているのでとりあえず満足。