Scotty and the Reader Monad

62 views Asked by At

I'm trying to bring the Reader monad in my Scotty application, as a means of having a unified root path for URL expansion internally. I can't seem to wrap my head around how Scotty handles monad transformation - normally, I would just see something like runTransformerT ..., but scottyT has a lot of internal plumbing to do, so the result is really just a MonadIO n => n () (forced to IO () if used in the main function, like I am here).

Here is my code so far:

main :: IO ()
main = scottyT 3000
  (\x -> runReaderT x "foo.com")
  id $ do
    root <- lift ask
    get "/" $
      text root

And the error I'm getting:

src/Main.hs:16:21:
    Couldn't match type ‘IO’ with ‘ReaderT r0 IO’
    Expected type: ReaderT r0 IO a
      Actual type: IO a
    In the first argument of ‘runReaderT’, namely ‘x’
    In the expression: runReaderT x "foo.com"

How do I use this magic?

0

There are 0 answers