reserve というツールを使うとHaskellでホットリロードしながらWebアプリを開発することが出来ます。
インストールは
$ git clone git@github.com:sol/reserve.git
$ cd reserve
$ cabal sandbox init
$ cabal install --only-dependencies
$ cabal build
とすると./dist/build/reserve/
にreserve
というバイナリが出来あがります。使い方は簡単で公式のREADMEがとても参考になります。
ここではStackと一緒に使う方法を紹介します。試しに以下の様なプロジェクトを作ります。
$ stack new web-app
web-app.cabal
name: web-app
version: 0.1.0.0
executable web-app-exe
hs-source-dirs: app
main-is: Main.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends: base
, scotty
default-language: Haskell2010
app/Main.hs
{-# LANGUAGE OverloadedStrings #-}
import Web.Scotty
main :: IO ()
main = scotty 3000 $ do
get "/" $ do
text "hello\n"
次のように実行します
$ stack exec -- ../reserve/dist/build/reserve/reserve app/Main.hs
http://localhost:12000
これでhttp://localhost:12000にアクセスするとhello
と表示されると思います。この状態でアプリを落とさずにファイルを以下のように変更してみましょう。
main = scotty 3000 $ do
get "/" $ do
text "hello\n"
+ get "/hello" $ do
+ text "world\n"
そしてhttp://localhost:12000/helloにアクセスするとちゃんとworld
と表示されると思います。