Are interface types allowed as interface choice arguments?
- asarpeshkarOP
The following doesn’t compile:
interface ILinkedList where viewtype LinkedListView owner : Party choice Find : Optional (ContractId ILinkedList) with tgt : ILinkedList controller owner this do undefined choice Tail : Optional (ContractId ILinkedList) controller owner this do pure (view this).tail data LinkedListView = LinkedListView with tail : Optional (ContractId ILinkedList) deriving (Eq, Show)with the error:
daml/Interface.daml:8:10: error: • No instance for (Show ILinkedList) arising from the first field of ‘Find’ (type ‘ILinkedList’) Possible fix: use a standalone 'deriving instance' declaration, so you can specify the instance context yourself • When deriving the instance for (Show Find)After adding a
Showinstance forILinkedList:instance Show ILinkedList where show = show . viewThe compiler complains that
Findisn’t serializable.error type checking interface Interface.ILinkedList choice Find: expected serializable type: * reason: choice argument * found: Interface:Find * problem: unserializable data type Interface:FindChanging
tgtto a non-interface type likeIntresolves both issues (the need for aShowinstance and the non-serializableFinderror).Are interface types allowed in interface choice arguments?
- Gary_Verhaegen
I’m not very familiar with interfaces, but I’d expect you to either have a
ContractId ILinkedListor aILinkedListViewas argument. Having the interface itself doesn’t make sense to me. - asarpeshkar
ContractId ILinkedListworks for my purposes (tgtis the contract to find). Thanks.Edit :
selfis available in interface choices so passing in the contract id to search for is the right thing to do, rather than trying to compare twoILinkedListvalues. - asarpeshkar
On second thought,
ContractId ILinkedListdoesn’t really make sense as an argument forFind–if you have the contract id already you can just fetch the contract, there’s no need to search for it. So maybe this use-case is not a good fit for interfaces.