Add a traslating transformer to implement `MonadThrow` in terms of `MonadIO`
- Dominant language
- Haskell
- Stars
- 57
- Forks
- 38
- PR merge metrics
- No merged PRs in 30d
Description
I have the following:
```haskell
foo :: (MonadWhatever m, MonadThrow m) => ... -> m ()
```
Later, I have
```
bar :: (MonadIO, MonadWhatever m) =>
bar = do
...
foo
...
```
However, this won't typecheck because `bar` lacks the `MonadThrow` constraint necessary for `foo`. I don't want to add a `MonadThrow` constraint because I know that `MonadIO` implements that. My suggestion is that `exceptions` gains a new transformer that translates `MonadThrow` into `MonadIO`:
```haskell
-- | Translate 'MonadThrow' constraints to an underlying 'MonadIO' instance.
newtype ThrowToIOT m a = ThrowToIOT { throwToIO :: m a }
deriving newtype (Functor, Applicative, Monad, MonadIO, MonadUnliftIO)
instance MonadTrans ThrowToIOT where
lift = ThrowToIOT
instance MonadIO m => MonadThrow (ThrowToIOT m) where
throwM = liftIO . throwM
```
With this, I can now write:
```haskell
bar :: (MonadIO, MonadWhatever m) =>
bar = do
...
throwToIO foo
...
```
and everyone is happy.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.