How to interpret this function:
friendlyValidityRange
:: CardanoEra era
-> (TxValidityLowerBound era, TxValidityUpperBound era)
-> Aeson.Value
friendlyValidityRange era = \case
ShelleyTtl ttl -> object ["time to live" .= ttl]
(lowerBound, upperBound)
| isLowerBoundSupported || isUpperBoundSupported ->
object
[ ...
]
| otherwise -> Null
where
isLowerBoundSupported = isJust $ validityLowerBoundSupportedInEra era
isUpperBoundSupported = isJust $ validityUpperBoundSupportedInEra era
I thought the friendlyValidityRange function utilize the partial function concept, but still failed to understand it.
How can friendlyValidityRange's era and (lowerBound, upperBound) parameters be passed in such separated way?
I try to mimic it use follow demo, still unable to finished it.
module Main where
data Age = Child | Adult
-- Function that accept two agrs: Age, (weightMin, weightMax) , and return health description string
weightAnalyse :: Age -> (Int, Int) -> String
weightAnalyse age = \case
Child -> ? -- how to comsume the (min, max) tuple
Adult -> ?
main :: IO ()
main = do
weightAnalyse Child (30, 60)
weightAnalyse Adult (60, 130)
You are missing Pattern Synonyms. Take a look at line 105
This says that a tuple where the first component is
TxValidityNoLowerBoundand the second component isTxValidityUpperBound ValidityUpperBoundInShelleyEra ttlcan be used as the patternShelleyTtl ttlwithttlbound to the correct value.So
ShelleyTtl ttlinmatches a particular type of tuple!
Your
weightAnalysedoes not really match the example you are referencing but would go along the lines of: