Contract Keys and equality
- Tamas_KalczaOP 3
I thought contract keys have be in the
Eqclass, however that does not seem to be the case. Why is that?template ContractKeyExample with party : Party value : Text where signatory party key (Record with a = value, b = party) : KeyType -- key Tuple (party, value) : KeyType maintainer keyTypeToParty key data KeyType = Tuple (Party, Text) | Record with a : Text, b : Party keyTypeToParty: KeyType -> Party keyTypeToParty (Tuple (p, _)) = p keyTypeToParty Record {a, b} = b - shaynefletcher 2
For a template
twith a key typek, it appears thattandksatisfy the following constraints (from ‘daml-stdlib-src/DA/Internal/Template/Functions.daml’):-- | Constraint satisfied by template keys. type TemplateKey t k = ( Template t , HasKey t k , HasLookupByKey t k , HasFetchByKey t k , HasMaintainer t k , HasToAnyContractKey t k , HasFromAnyContractKey t k )As far as I can tell, none of the constraint components induce a constraint that there be an
Eqinstance onk(orOrdorShowfor that matter). - cocreature 2
The reason why you end up with
ShowandEqrequirements for the template type is that thetemplatesyntax in DAML will automatically deriveShowandEqfor the template type.The key type isn’t defined as part of the
templatesyntax, you are referencing a key type defined up front (e.g. in the simplest case aParty) so we don’t derive anything.Your key type still has to be serializable which means that you can compare it (as evidenced by the DAML-LF generic equality in 1.dev) and you could also render it as a string but it does not automatically give you instances of
EqandShow.