[Haskell-cafe] writing wizards in Yesod
Olaf Klinke
olf at aatal-apotheke.de
Thu Aug 27 10:04:52 UTC 2020
On Thu, 2020-08-27 at 01:20 +0300, Georgi Lyubenov wrote:
> Hi!
>
> I believe the canonical way to handle this in Yesod is the "reader
> pattern"
> (https://www.fpcomplete.com/blog/2017/06/readert-design-pattern):
> * it's by the same author
>From the top of that post:
"If you must have some mutable state, put it in Env as a mutable
reference (IORef, TVar, etc)."
So the official guideline is exactly as I detailed in my original post.
> * yesod is a ReaderT
Yes, but it's
MonadReader (HandlerData site site) (HandlerFor site)
So I'd have to encode my state in one of
HandlerData
handlerRequest :: !YesodRequest
handlerEnv :: !(RunHandlerEnv child site)
handlerState :: !(IORef GHState)
handlerResource :: !InternalState
which has no fields for holding arbitrary data. And I centainly don't
want to encode several Kilobytes of loaded data in the request URL.
Olaf
> and I'm not aware of a way to replace this monad with
> one of your own (e.g. some effects systems State monad, which you can
> then
> run as a MVar, so that you have concurrent writing/reading possible
> between
> the different threads spawned by yesod for handling each request)
>
> ======
> Georgi
More information about the Haskell-Cafe
mailing list