ReaderTを使用して次のようにリクエストへのアクセスを許可する単純なWAIアプリケーションを作成しました。
import qualified Network.Wai as W
handle :: (Resource a) => a -> ReaderT W.Request IO W.Response
ここhandle
で、は処理の大部分を実行する関数です。次に、アプリケーションでそれを呼び出します。
app :: W.Application
app = runReaderT (handle a) -- simplified; i don't think the value of a matters
main :: IO ()
main = run 3000 app
しかしrunhaskell main.hs
、私に次のことを与えます:
Couldn't match expected type `Control.Monad.Trans.Resource.ResourceT
IO'
with actual type `IO'
Expected type: ReaderT
W.Request (Control.Monad.Trans.Resource.ResourceT IO) W.Response
Actual type: ServerMonad W.Response
In the return type of a call of `handle'
In the first argument of `runReaderT', namely
`(handle a)'
これは2つの理由で私を混乱させます:
- なぜそのタイプを期待しているのか分かりません
- 呼び出し
resp <- runReaderT (handle a) defaultRequest
はGHCIで機能します!
なぜこうなった?