# Are interface types allowed as interface choice arguments?

**URL:** <https://forum.canton.network/t/are-interface-types-allowed-as-interface-choice-arguments/5772>\
**Category:** App Development\
**Created:** [December 7, 2022, 3:31pm UTC](https://forum.canton.network/t/are-interface-types-allowed-as-interface-choice-arguments/5772 "2022-12-07T15:31:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![asarpeshkar](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/asarpeshkar/32/1601_2.png) [@asarpeshkar](https://forum.canton.network/u/asarpeshkar)\
**Post date:** [December 7, 2022, 3:31pm UTC](https://forum.canton.network/t/are-interface-types-allowed-as-interface-choice-arguments/5772/1 "2022-12-07T15:31:59Z")

</div>

The following doesn’t compile:

```haskell
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:

```haskell
  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 `Show` instance for `ILinkedList`:

```haskell
instance Show ILinkedList where
  show = show . view

```

The compiler complains that `Find` isn’t serializable.

```haskell
  error type checking interface Interface.ILinkedList choice Find:
  expected serializable type:
  * reason: choice argument
  * found: Interface:Find
  * problem:
  unserializable data type Interface:Find

```

Changing `tgt` to a non-interface type like `Int` resolves both issues (the need for a `Show` instance and the non-serializable `Find` error).

Are interface types allowed in interface choice arguments?

---

<div class="post-metadata">

**Author:** ![Gary\_Verhaegen](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/gary_verhaegen/32/81_2.png) [@Gary\_Verhaegen](https://forum.canton.network/u/Gary_Verhaegen)\
**Post date:** [December 7, 2022, 3:36pm UTC](https://forum.canton.network/t/are-interface-types-allowed-as-interface-choice-arguments/5772/2 "2022-12-07T15:36:39Z")

</div>

I’m not very familiar with interfaces, but I’d expect you to either have a `ContractId ILinkedList` or a `ILinkedListView` as argument. Having the interface itself doesn’t make sense to me.

---

<div class="post-metadata">

**Author:** ![asarpeshkar](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/asarpeshkar/32/1601_2.png) [@asarpeshkar](https://forum.canton.network/u/asarpeshkar)\
**Post date:** [December 7, 2022, 3:42pm UTC](https://forum.canton.network/t/are-interface-types-allowed-as-interface-choice-arguments/5772/3 "2022-12-07T15:42:13Z")

</div>

`ContractId ILinkedList` works for my purposes (`tgt` is the contract to find). Thanks.

Edit : `self` is available in interface choices so passing in the contract id to search for is the right thing to do, rather than trying to compare two `ILinkedList` values.

---

<div class="post-metadata">

**Author:** ![asarpeshkar](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/asarpeshkar/32/1601_2.png) [@asarpeshkar](https://forum.canton.network/u/asarpeshkar)\
**Post date:** [December 7, 2022, 5:37pm UTC](https://forum.canton.network/t/are-interface-types-allowed-as-interface-choice-arguments/5772/4 "2022-12-07T17:37:39Z")

</div>

On second thought, `ContractId ILinkedList` doesn’t really make sense as an argument for `Find`–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.
