The only thing you can generally get out of ContT rm is a value of type mr . A typical Run (ContT r) signature Run (ContT r) will be
Run (ContT r) = forall n b. Monad n => ContT rnb -> n (StT (ContT r) b)
which is equivalent
forall n b. ((b -> nr) -> nr) -> n (StT (ContT r) b)
The only possible type for StT (ContT r) b is r , but even then it is not possible to define a specific function of type b -> nr to go to ContT . And since liftWith given a function that requires a value of type Run (ContT r) , it cannot be implemented.
restoreT makes it even worse, because any value that can be extracted from the general ContT rma cannot be returned back to ContT rma . Thus, you lose both.
By the way, this is also the reason why you cannot make ContT a MonadFix . You cannot turn arbitrary a into arbitrary r and vice versa.
source share