-
Notifications
You must be signed in to change notification settings - Fork 86
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
Improve support for monad stacks #1539
Conversation
I see that I left some stuff in a different commit, two tiny definitions. Will force-push. 99% of the work is here. |
f53e3e9
to
4b170ec
Compare
Done. |
74e6f57
to
0e59cca
Compare
Am getting non-termination in the simulator. Don't yet know if it's due to these changes. Will continue digging tomorrow. |
Ok, non-termination was just stupidity on my part. This PR is good to go. |
0e59cca
to
e374611
Compare
e374611
to
be9af36
Compare
Rebased on latest |
be9af36
to
51bd0c7
Compare
51bd0c7
to
f201496
Compare
Ok, ready again to be merged pending review by @dcoutts . |
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.
Looks fine.
Looks like there's a bunch of unrelated code changes here though, like reordering imports. No objection to doing that, but preferably in a separate PR that does only that.
interpretPickScript :: (MonadSTMTx stm, Ord peeraddr) | ||
=> TVar_ stm PickScript |
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.
Why do we need to change things like this?
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.
Neither TVar
nor STM
is injective, so if you were to write TVar m a -> STM m ..
, the monad m
is entirely ambiguous, and you'd have to introduce a Proxy
. This seemed cleaner.
@@ -913,7 +914,7 @@ initScript = newTVarM | |||
stepScript :: MonadSTM m => TVar m (Script a) -> m a | |||
stepScript scriptVar = atomically (stepScriptSTM scriptVar) | |||
|
|||
stepScriptSTM :: MonadSTM m => TVar m (Script a) -> STM m a | |||
stepScriptSTM :: MonadSTMTx stm => TVar_ stm (Script a) -> stm a |
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.
Required or just because we can? This leaks MonadSTMTx
into app code which adds cognitive overhead.
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.
Same answer as above.
@@ -1,6 +1,7 @@ | |||
{-# LANGUAGE DataKinds #-} | |||
{-# LANGUAGE FlexibleContexts #-} | |||
{-# LANGUAGE ScopedTypeVariables #-} | |||
{-# LANGUAGE TypeFamilies #-} |
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.
related?
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.
Yes.
@@ -27,7 +28,7 @@ import Control.Tracer | |||
import qualified Network.Mux.Bearer.Pipe as Mx | |||
import Ouroboros.Network.Mux | |||
|
|||
import Ouroboros.Network.Block (encodeTip, decodeTip) | |||
import Ouroboros.Network.Block (decodeTip, encodeTip) |
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.
related?
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.
No, just inconsistent use of the formatter in this repo.
The main change in this commit is split in MonadSTM, which avoids the injectivity requirement, enabling GeneralizedNewtypeDeriving for MonadSTM. The remainder of the changes are related, and similarly intended to faciliate the derivation of monad stacks.
f201496
to
70edb92
Compare
bors r+ |
1539: Improve support for monad stacks r=edsko a=edsko The main change in this commit is split in MonadSTM, which avoids the injectivity requirement, enabling GeneralizedNewtypeDeriving for MonadSTM. The remainder of the changes are related, and similarly intended to faciliate the derivation of monad stacks. Note that a similar change could be made to `MonadTimer`, but I didn't need it and so I've not done that yet. With this PR, we can define something like ```haskell newtype MockTime m a = MockTime (ReaderT () m a) deriving ( Functor , Applicative , Monad , MonadTrans , MonadThrow , MonadSTM , MonadDelay , MonadTime ) ``` and have it Just Work (TM). (Of course, this particular definition isn't very useful, just a proof of concept.) Co-authored-by: Edsko de Vries <[email protected]>
1539: Improve support for monad stacks r=edsko a=edsko The main change in this commit is split in MonadSTM, which avoids the injectivity requirement, enabling GeneralizedNewtypeDeriving for MonadSTM. The remainder of the changes are related, and similarly intended to faciliate the derivation of monad stacks. Note that a similar change could be made to `MonadTimer`, but I didn't need it and so I've not done that yet. With this PR, we can define something like ```haskell newtype MockTime m a = MockTime (ReaderT () m a) deriving ( Functor , Applicative , Monad , MonadTrans , MonadThrow , MonadSTM , MonadDelay , MonadTime ) ``` and have it Just Work (TM). (Of course, this particular definition isn't very useful, just a proof of concept.) Co-authored-by: Edsko de Vries <[email protected]>
The main change in this commit is split in MonadSTM, which avoids the injectivity requirement, enabling GeneralizedNewtypeDeriving for MonadSTM. The remainder of the changes are related, and similarly
intended to faciliate the derivation of monad stacks.
Note that a similar change could be made to
MonadTimer
, but I didn't need it and so I've not done that yet.With this PR, we can define something like
and have it Just Work (TM). (Of course, this particular definition isn't very useful, just a proof of concept.)