-
Notifications
You must be signed in to change notification settings - Fork 21
Refactorisation of MonadTimers & monad transformer instances #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
85d9a8c
to
d8b5f14
Compare
c1cdd26
to
5cb6170
Compare
4cbb906
to
2776115
Compare
I removed the rather controversial monad transformer instances for |
2776115
to
c8d0de2
Compare
instance MonadCatch m => MonadCatch (StateT s m) where | ||
catch (StateT m) f = StateT $ \s -> catch (m s) (\e -> runStateT (f e) s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compare with exceptions
package
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
notes after a conversation with @dcoutts:
I think my original notes were not adequate with respect to the second point. As I remember we concluded that |
c13c2fe
to
a82d7b8
Compare
|
||
-- | @since 1.0.0.0 | ||
instance MonadCatch m => MonadCatch (StateT s m) where | ||
catch (StateT m) f = StateT $ \s -> catch (m s) (\e -> runStateT (f e) s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is compatible with what exception package does; it's using liftCatch
.
a82d7b8
to
280f200
Compare
instance MonadCatch m => MonadCatch (ExceptT e m) where | ||
catch (ExceptT m) f = ExceptT $ catch m (runExceptT . f) | ||
|
||
generalBracket acquire release use = ExceptT $ do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instance (Monoid w, MonadCatch m) => MonadCatch (WriterT w m) where | ||
catch (WriterT m) f = WriterT $ catch m (runWriterT . f) | ||
|
||
generalBracket acquire release use = WriterT $ fmap f $ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
catch (RWST m) f = RWST $ \r s -> catch (m r s) (\e -> runRWST (f e) r s) | ||
|
||
-- | general bracket ignores the state produced by the release callback | ||
generalBracket acquire release use = RWST $ \r s -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
catch (StateT m) f = StateT $ \s -> catch (m s) (\e -> runStateT (f e) s) | ||
|
||
-- | general bracket ignores the state produced by the release callback | ||
generalBracket acquire release use = StateT $ \s -> fmap f $ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3f834ff
to
7037211
Compare
The latter one returns time in nanoseconds as a `Word64` value, the same as `GHC.Clock.getMonotonicTimeNSec`. `MonadMonotonicTime` has a single method which returns time measured in `DiffTime`. For `IOSim` the latter one is more precise, `IOSim` measures time using `DiffTime`.
This means we also remove `registerDelayCancellable` from `io-classes`.
Haddocks & layout.
* MonadDelay * MonadTimer
`ReaderT`, `WriterT`, `StateT` and `RWST` have now instances which also transform the `STM m` monad. This open a possibility to provide `MonadAsync` instances for monad transformers stacks.
We don't need anymore `WrappedSTM` as it's only used for `ContT` monad transformer.
`si-timers` also provides `MonadTimer` and `MonadDelay`. They use the same name as one in `io-classes` as it's not expected to depend on both in one module. The `si-timers` provides `defaultRegisterDelayCancellable` which is used for two purposes: * provide `IO` instance * test the `IO` instance in `IOSim` This patch also reverts a change in one of the previous patches. `IOSim` is using `DiffTime` for its `NewTimeout` primitive operation. The `UpdateTimeout` is removed as it is not used.
No description provided.