![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJAJtKQCltQIhFEXGxjcc35yOLuTmlmLaZZnpAHucbh-cOu2tSF5Q-ohRIOV_d6b6IxGk4HVK3AvEiuqRn_Hj6unaAB4nEZAl1x9L5t5wEGN9uMKaL71UPevrsJpT0jkD9s5GgFraNzH2R/s400/%25E3%2582%25B9%25E3%2582%25AF%25E3%2583%25AA%25E3%2583%25BC%25E3%2583%25B3%25E3%2582%25B7%25E3%2583%25A7%25E3%2583%2583%25E3%2583%2588+2012-06-04+22.06.19.png)
巷で話題のプログラミング本「すごいHaskell たのしく学ぼう!!」(略して すごいH本)を手に入れましたので、早速インストールしてみます。
Haskell Platformをインストールします。
Haskell Platformhttp://hackage.haskell.org/platform/
pkgファイルなので、インストーラに従ってインストール。
ターミナルを開いて「ghci」を実行すると、REPL (Real Eval Print Loop) が起動します。
$ ghci GHCi, version 7.0.4: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Loading package ffi-1.0 ... linking ... done. Prelude>
適当にいじってみます。
Prelude> 2+5 7 Prelude> "hello" == "hello" True Prelude> True \= False <interactive>:1:6: Not in scope: `\=' Prelude> True /= False True Prelude> succ 99 100 Prelude> length [5,4,3,2,1] 5 Prelude> reverse [5,4,3,2,1] [1,2,3,4,5] Prelude> ['A'..'Z'] "ABCDEFGHIJKLMNOPQRSTUVWXYZ" Prelude> [x*2 | x <- [1..20]] [2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40] Prelude> zip [1..] ["apple", "orange", "cherry", "mango"] [(1,"apple"),(2,"orange"),(3,"cherry"),(4,"mango")] Prelude>
うむ。面白い。
Ctrl+Dで抜けます。
HaskellでできたWebアプリケーションのフレームワークがいくつかありますが、ドキュメントが豊富なYesodをインストールしてみます。
インストールにはgccコンパイラが必要です。最新のXCodeではgccが入らず、LLVMになっとります。なので、↓からDLしてインストール。
github
kennethreitz / osx-gcc-installerターミナルからcabalコマンドを実行します。(結構時間がかかります)
$ cabal update Downloading the latest package list from hackage.haskell.org $ cabal install yesod-platform (ダウンロードとコンパイルとインストールログ) Updating documentation index /Users/inouetomoyuki/Library/Haskell/doc/index.html $
bash_profileに以下を追加します。
export PATH=$HOME/Library/Haskell/bin:$PATH
再読み込み。
$ source ~/.bash_profile
最初のWebを作ってみます。yesod initコマンドでいくつかの質問に答えていきます。自分の名前、プロジェクト名、データベースの種類を決めます。
$ mkdir Projects && cd !$ $ yesod init Welcome to the Yesod scaffolder. I'm going to be creating a skeleton Yesod project for you. What is your name? We're going to put this in the cabal and LICENSE files. Your name: Tomoyuki INOUE Welcome Tomoyuki INOUE. What do you want to call your project? We'll use this for the cabal name. Project name: Sample Yesod uses Persistent for its (you guessed it) persistence layer. This tool will build in either SQLite or PostgreSQL or MongoDB support for you. We recommend starting with SQLite: it has no dependencies. s = sqlite p = postgresql mongo = mongodb mysql = MySQL (experimental) So, what'll it be? s That's it! I'm creating your files now... Generating deploy/Procfile Generating config/sqlite.yml (・・・) Start your project: cd Sample && cabal install && yesod devel or if you use cabal-dev: cd Sample && cabal-dev install && yesod --dev devel
書いてある通りコマンドを実行します。
$ cd Sample && cabal install && yesod devel
開発サーバを起動します。
$ yesod devel Yesod devel server. Press ENTER to quit Resolving dependencies... Configuring Sample-0.0.0... Rebuilding application... Preprocessing library Sample-0.0.0... Preprocessing executables for Sample-0.0.0... Preprocessing test suites for Sample-0.0.0... Building Sample-0.0.0... Registering Sample-0.0.0... Starting development server: runghc -package-confdist/package.conf.inplace devel.hs Starting devel application Devel application launched: http://localhost:3000
http://localhost:3000/にアクセスします。
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDDCMEfImvmJ26YaIweHWYPF7HYKkpixqHcCAZ21PIW7nQ4FrPGdVpmAGF7rPu1o6tHcM1b4DFZR-ZCwJRx63XNHgvpc8JWSK4mVDCK6r43s8tixM2Hu3JjxZsEc5U5lqGyhTd0RlqxaLX/s400/%25E3%2582%25B9%25E3%2582%25AF%25E3%2583%25AA%25E3%2583%25BC%25E3%2583%25B3%25E3%2582%25B7%25E3%2583%25A7%25E3%2583%2583%25E3%2583%2588+2012-06-04+22.50.34.png)
無事インストールできました。
yesodは、超高速なWebアプリケーションフレームワークです。
公式のチュートリアルから引用です。
![](http://yannesposito.com/Scratch/img/blog/Yesod-tutorial-for-newbies/haskell-benchmark.png)
node.jsの約3.44倍高速だそうです。未来です。
スペックについては、こちらが詳しいです。
Haskell から見た node.jshttp://d.hatena.ne.jp/kazu-yamamoto/20110825/1314254885
1 件のコメント:
はじめまして。
OSX(10.7.4)でghc7.4.1をインストールした後、ご指定の方法でyesodをインストールしたところ、yesod-platform-1.0.5 depends on yesod-1.0.1.6 which failed to install.というエラーでインストールが止まってしまいます。直接の原因はyesod-1.0.1.6のインストールする時に「ld: symbol(s) not found for architecture i386」というエラーが出ている箇所だと思うのですが、何かオプション等をつけてインストールされたのでしょうか。もし心当たりがあれば教えていただけるとうれしいです。
コメントを投稿