Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About the monads in ScottyT and ActionT #74

Open
echaozh opened this issue Mar 5, 2014 · 2 comments
Open

About the monads in ScottyT and ActionT #74

echaozh opened this issue Mar 5, 2014 · 2 comments
Labels

Comments

@echaozh
Copy link
Contributor

echaozh commented Mar 5, 2014

ScottyT and ActionT share the same monad as their type parameters. From the code, I see that ScottyState needs the monad to be used in the routes, as they're constructed from ActionT. However, the monad wrapped by the ScottyT does not need to be the same monad. It's only used at initialization, and have nothing to do with ActionT. Can ScottyT be modified to use too different monads, 1 for routes, and 1 for initialization? Or perhaps dropping the second monad altogether and fix it as Identity? It looks like it cannot do much at initialization, and one can always initialize before calling scottyT.

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.

@Shimuuar
Copy link

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.

@ehamberg
Copy link

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? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants