在此功能的Cardano定义中使用的语法是什么?
如何解释此功能:
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
我认为 friendlyvalityrange
函数使用部分函数概念概念,但仍然无法理解它。
friendlyValityRange
's era
and (下部,上行)
参数以这样的分离方式传递?
我尝试模仿它使用“遵循演示”,但仍无法完成。
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您缺少 nofollow noreferrer“>模式同步。 Take a look at 第105行
这说明了第一个组件为
txvalitynolowerbound
code> txvalityuperperbound velityuperityupersupersupertiupipperboundinshelleyera ttlleyera ttl 模式shelleyttl ttl
带有ttl
绑定到正确的值。因此,
shelleyttl ttl
在匹配特定类型的元组中!
您的
weighanalyse
实际上与您所引用的示例不匹配,但会按照以下方式进行:You are missing Pattern Synonyms. Take a look at line 105
This says that a tuple where the first component is
TxValidityNoLowerBound
and the second component isTxValidityUpperBound ValidityUpperBoundInShelleyEra ttl
can be used as the patternShelleyTtl ttl
withttl
bound to the correct value.So
ShelleyTtl ttl
inmatches a particular type of tuple!
Your
weightAnalyse
does not really match the example you are referencing but would go along the lines of: