[input-output-hk/cardano-sl] [CBR-243] improve wallet worker start-up and exception handling (#3330)

k0001 commented on this pull request.

> @@ -55,13 +56,11 @@ data WalletWorkerState b = WalletWorkerState

makeLenses »WalletWorkerState

— A helper function for lifting a `WalletActionInterp` through a monad transformer.
-lifted :: (Monad m, MonadTrans t) => WalletActionInterp m b -> WalletActionInterp (t m) b
-lifted i = WalletActionInterp
— { applyBlocks = lift . applyBlocks i
— , switchToFork = \n bs -> lift (switchToFork i n bs)
— , emit = lift . emit i
— }
+instance MFunctor WalletActionInterp where
+ hoist nat i = WalletActionInterp
+ { applyBlocks = fmap nat (applyBlocks i)
+ , switchToFork = fmap (fmap nat) (switchToFork i)
+ , emit = fmap nat (emit i) }

> First of all, I think this is not a lawful use of MFunctor, because WalletActionInterp m isn’t a Monad.

It doesn’t need to be, it needs to be a functor in the category of monads. And `WalletActionInterp m` is one of those. The handwavy basic requirement is that the kind of the functor is `(* -> *) -> * -> *`, and that `m` only ever shows up in positive positions inside `f`. Here’s an example in the wild of something that is *not* a functor in the category of monads, even though its kind matches the expectation of `MFunctor`: https://hackage.haskell.org/package/di-monad-1.2/docs/Di-Monad.html#v:hoistDiT

Добавить комментарий