目的
RHEL7でHaskellを利用できる環境を用意する。
環境
Google Cloud Platform環境のVMインスタンス
$ cat /etc/os-release NAME="Red Hat Enterprise Linux Server" VERSION="7.6 (Maipo)" $ arch x86_64
手順
ダウンロード
yumコマンドでインストール可能です。
まずはどのようなパッケージがあるかyum search
で検索すると以下のようにつらつらと表示されます。
# yum search haskell ============================= N/S matched: haskell ============================= emacs-haskell-mode.noarch : Haskell editing mode for Emacs emacs-haskell-mode-el.noarch : Elisp source files for Haskell-mode under GNU : Emacs ghc-haskell-platform-devel.x86_64 : Haskell Platform library development files ... haskell-platform.x86_64 : Standard Haskell distribution ...
その中にあるhaskell-platformをプラットフォームとしてインストールします。
# yum install haskell-platform Resolving Dependencies --> Running transaction check ... Complete!
動作確認も兼ねてHaskellのインタプリタであるghci
を利用します。
ちなみにGlasgow Haskell CompilerのInteractive環境ということでGHCIです。
yumコマンドによるインストールが完了していれば以下パスに実体は存在します。
# which ghci /usr/bin/ghci
バージョンは7.6.3のようです。
# ls -l /usr/bin/ghci lrwxrwxrwx. 1 root root ... /usr/bin/ghci -> ghci-7.6.3
ハンズオン
インタプリタを起動すると以下のようにパッケージが読み込まれます。
# ghci GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Prelude>
実際にいくつか試しますが、Haskellを一通り触る上で以下のサイトは参考になります。
Starting Out - Learn You a Haskell for Great Good!
その中で一部抜粋です。
四則演算
Prelude> 2 + 15 * 2 - 10 / 2 27.0
関数の利用
Prelude> succ 9 + max 5 4 + min 6 3 18
ちなみにsuccとは引数に1を足した結果を返す関数です。
関数の自作
ghciでは変数や関数を定義する際にlet
を利用します。
Prelude> let doubleMe x = x + x Prelude> doubleMe 3 6
doubleMeという引数を2倍にする関数を作成できます。
終わりに
関数型プログラミングの代名詞とも言えるHaskellですが、RedHatEnterpriseLinuxの場合はyumコマンド一発でインストールできます。
同様のことに興味がある方はぜひ試してみてください。