snapframework / snap-core

Core type definitions (Snap monad, HTTP types, etc) and utilities for web handlers.
http://snapframework.com/
BSD 3-Clause "New" or "Revised" License
317 stars 85 forks source link

How to use the (MonadBaseControl IO) instance of Snap? #309

Open complyue opened 3 years ago

complyue commented 3 years ago

Naively I tried liftBaseWith in a Snap action but inner writeText produces no effect at all.

I'm not sure I used MonadBaseControl correctly, but I failed to find a user side example on Github (as there're only instance impl. hits).

And quoting https://github.com/fpco/unliftio/issues/17#issuecomment-363655106

Continuation-based monads cannot have instances of MonadUnliftIO, the same as MonadBaseControl and MonadMask.

Am I right to see Snap as a "continuation-based" monad? If so, is the MonadBaseControl instance flawed or wrong at all?

Basically, I need to escape from Snap into nested IO, to run some scripting code leveraging STM, where I want to perform writeText etc. by the scripts to generate proper http payload. Ideally I want to wrap the full set of Snap API available for scripting, how can I do that?

I'd like to contribute some new public API if that's lacking and doable, but need some guidance and esp. a confirmation before heading that way.