4 ms·
Does anyone have some insight to what is going on in the Z monad bit? It looks like an Either monad with a bunch of error states instead of just the one.
by stonemetal 13y ago
Does anyone have some insight to what is going on in the Z monad bit? It looks like an Either monad with a bunch of error states instead of just the one.
- boothead 13y agoZ isn't a monad from what I can see... ZZ is the monad. It's an IO action that returns a ZResult (which is either a value or an error state as you said) and has access to an environment for logging, a database connection and a configuration. I'm not a Haskell expert though - so don't take that as truth until confirmed by someone else :-)
- tel 13y agoThere are two independent parts. The Z monad is nothing more than a ReaderT monad giving access to some config and environment information. Since it's a transformer they can execute actions in higher monads (like IO) pretty easily from Z, but it can also be used in pure code if you just need the configuration information. Parallel to that is the ZResultT monad. It's built on the ZResult monad (it should be easy enough to write a Monad instance for it anyway) which looks like an Identity monad with some "Z-specific" error handling layered in. ZResultT just lets you have a transformer stack interleaved with the ZResults. Then you combine those two stacks in ZZ which gives you both "Z-related" configuration and "Z-related" error states. It looks like the whole thing is specialized to make it easy to build functions pure functions which only need a handful of the effects and then weave them together into the ZZ monad which is likely to be run at the top level, right below Yesod.