-
Notifications
You must be signed in to change notification settings - Fork 720
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
partially monomorphise & de-generify Env #4521
Changes from 1 commit
6f9786c
5cbd4a3
b1c5479
aab193f
8ddfaed
64ccd8d
d707426
4d22bb9
80feb2a
42c40a5
359874c
2d49382
f175d16
29db9a0
4a7eb72
8f8991a
2fd0d23
12447bc
499e245
c883487
731e16d
a848918
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ module Cardano.Benchmarking.Script.Env ( | |
, traceDebug | ||
, traceError | ||
, traceBenchTxSubmit | ||
, getProtoParamMode | ||
, setProtoParamMode | ||
, get | ||
, set | ||
) where | ||
|
@@ -42,10 +44,12 @@ import Cardano.Benchmarking.Script.Store | |
|
||
import Cardano.TxGenerator.Types (TxGenError(..)) | ||
|
||
data Env = Env { dmap :: DMap Store Identity } | ||
data Env = Env { dmap :: DMap Store Identity | ||
, protoParams :: Maybe ProtocolParameterMode | ||
} | ||
|
||
emptyEnv :: Env | ||
emptyEnv = Env { dmap = DMap.empty } | ||
emptyEnv = Env { dmap = DMap.empty, protoParams = Nothing } | ||
|
||
type ActionM a = ExceptT Error (RWST IOManager () Env IO) a | ||
|
||
|
@@ -73,12 +77,21 @@ askIOManager = lift RWS.ask | |
set :: Store v -> v -> ActionM () | ||
set key val = lift $ RWS.modify $ (\e -> e { dmap = DMap.insert key (pure val) (dmap e)}) | ||
|
||
setProtoParamMode :: ProtocolParameterMode -> ActionM () | ||
setProtoParamMode val = lift $ RWS.modify $ (\e -> e { protoParams = pure val }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that you'll have more of those cases, I'd split this into a combination of:
|
||
|
||
get :: Store v -> ActionM v | ||
get key = do | ||
lift (RWS.gets $ (\e -> DMap.lookup key $ dmap e)) >>= \case | ||
Just (Identity v) -> return v | ||
Nothing -> throwE $ LookupError key | ||
|
||
getProtoParamMode :: ActionM ProtocolParameterMode | ||
getProtoParamMode = do | ||
lift (RWS.gets $ (\e -> protoParams e)) >>= \case | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, we can similarly to the setter, extract a generic helper that calls a supplied reader on top of the common There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll mop up the read accessors in a sweep after finishing off all the Store cases. The set accessors might still be worthwhile vs. open-coding, though lift $ modify lambda isn't too big a deal either. |
||
Just x -> return x | ||
Nothing -> throwE $ UserError "Unset ProtocolParams" | ||
|
||
traceBenchTxSubmit :: (forall txId. x -> Tracer.TraceBenchTxSubmit txId) -> x -> ActionM () | ||
traceBenchTxSubmit tag msg = do | ||
tracers <- get BenchTracers | ||
|
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.
Just a very minor nitpick about formatting -- I'd:
=
andEnv
aligning the latter naturally.,
aligning the latter with the{
}
on its own line...which is how multi-line is done frequently.