Open echaozh opened 10 years ago
It would be possible to change ScottyT
to following. It makes type somewhat more complicated but makes functions for runnning ScottyT
simpler (no ∀a. m a → n a
parameter).
data ScottyT e m n a = ScottyT (StateT (ScottyState e m) n a)
scottyAppT :: (Monad m, Monad n)
=> (m Response -> IO Response)
-> ScottyT e m n ()
-> n Application
I'm not sure about advantages of this approach but it does make sense.
I'm also wondering about this. I'm experimenting with building a library on top of scotty and this design choice makes that diffidult. I would like to use my own, custom monad stack for ScottyT
, but would like to let users supply their own handlers for routes, since ActionT
would then need the same custom monad. I'm not very familiar with Scotty's code, but is there a good reason for this being the case? Would it be hard to change? :)
ScottyT
andActionT
share the same monad as their type parameters. From the code, I see thatScottyState
needs the monad to be used in the routes, as they're constructed fromActionT
. However, the monad wrapped by theScottyT
does not need to be the same monad. It's only used at initialization, and have nothing to do withActionT
. CanScottyT
be modified to use too different monads, 1 for routes, and 1 for initialization? Or perhaps dropping the second monad altogether and fix it asIdentity
? It looks like it cannot do much at initialization, and one can always initialize before callingscottyT
.Also, why not allow Scotty specific middlewares around actions and inside WAI ones? Say if I want to parse the cookies in the request before every action, and store the results in the monad to be used in each
ActionT
, there is no convenient way to do that with WAI middlewares.