=== (Is this strict equality operator)?
- prajwalhegde3OP
Hi All,
Going through one of the IOU samples… just wanted to know if, “===” is this some kind of equality operator ? If yes, what is the use of this operator ?
module IouTrade where import DA.Assert import Iou template IouTrade with buyer : Party seller : Party baseIouCid : IouCid baseIssuer : Party baseCurrency : Text baseAmount : Decimal quoteIssuer : Party quoteCurrency : Text quoteAmount : Decimal where signatory buyer observer seller -- BEGIN_IOU_COMPOSITE_CHOICE choice IouTrade_Accept : (IouCid, IouCid) with quoteIouCid : IouCid controller seller do baseIou <- fetch baseIouCid baseIssuer === baseIou.issuer baseCurrency === baseIou.currency baseAmount === baseIou.amount buyer === baseIou.owner quoteIou <- fetch quoteIouCid quoteIssuer === quoteIou.issuer quoteCurrency === quoteIou.currency quoteAmount === quoteIou.amount seller === quoteIou.owner quoteIouTransferCid <- exercise quoteIouCid Iou_Transfer with newOwner = buyer transferredQuoteIouCid <- exercise quoteIouTransferCid IouTransfer_Accept baseIouTransferCid <- exercise baseIouCid Iou_Transfer with newOwner = seller transferredBaseIouCid <- exercise baseIouTransferCid IouTransfer_Accept return (transferredQuoteIouCid, transferredBaseIouCid) -- END_IOU_COMPOSITE_CHOICE choice TradeProposal_Reject : () controller seller do return () - cocreature 2
No, there is no strict equality operator in Daml.
==requires that both sides have the same type so it’s not even clear to me what strict equality would check in addition to that in Daml.In Daml,
===is a synonym forassertEq. It checks if the two values are equal using==and if they are not it throws an assertion failure which will abort the transaction.The definition of
===is fairly simple, I recommend to take a look if you’re interested. - prajwalhegde3
Thank you @cocreature
- prajwalhegde3
Hello,
Was trying to use assertEq in my choice to check if two date values are equal
But for some reason getting this error:
• Couldn't match expected type ‘Update a0’ with actual type ‘(Date, Date) -> m0 ()’ • Probable cause: ‘assertEq’ is applied to too few arguments In a stmt of a 'do' block: assertEq (transferDate, nowDate)What does “expected type ‘Update a0’” mean ?
Any sample code would be helpful.
Thank you!
- cocreature 1
To pass two arguments to a function you need to use
assertEq transferDate nowDate.assertEq (transferDate, nowDate)passes a single argument with that argument being a tuple which doesn’t match the type ofassertEq.The error is telling you that you are in a context where the compiler expects something of type
Update awhereais a type variable so there could be different options that typecheck. But what you specified has type(Date, Date) -> m0 ()(againm0is a type variable) which is the type ofassertEq (transferDate, nowDate): It expects a second argument of the same type, in your case a tuple, to compare it to. - prajwalhegde3
Thank you @cocreature as always helping out with the doubts