Why there is no instance of `MonadTransControl` for` ContT`

I have no idea how to implement this, and I assume that this cannot be. Is there evidence or convincing argument that this is not possible?

What makes ContT special?

+5
source share
1 answer

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.

+2
source

Source: https://habr.com/ru/post/1260092/


All Articles