# Why do templates need a Show instance?

**URL:** <https://forum.canton.network/t/why-do-templates-need-a-show-instance/3406>\
**Category:** App Development\
**Created:** [November 3, 2021, 1:12pm UTC](https://forum.canton.network/t/why-do-templates-need-a-show-instance/3406 "2021-11-03T13:12:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Krisztian\_Pinter](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/krisztian_pinter/32/2188_2.png) [@Krisztian\_Pinter](https://forum.canton.network/u/Krisztian_Pinter)\
**Post date:** [November 3, 2021, 1:12pm UTC](https://forum.canton.network/t/why-do-templates-need-a-show-instance/3406/1 "2021-11-03T13:12:06Z")

</div>

Why do templates need to be able to derive a `Show` instance? What is it used for exactly? I tried looking this up in the docs but I could not find an answer.

Also, why don’t keys need a `Show` instance? This works:

```haskell
data Foo = Foo Int
-- no Show instance for Foo

template Bar
  with
    p : Party
    x : Int
  where
    key (p, Foo x) : (Party, Foo)
    maintainer key._1
    signatory p

```

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [November 4, 2021, 9:22pm UTC](https://forum.canton.network/t/why-do-templates-need-a-show-instance/3406/2 "2021-11-04T21:22:30Z")

</div>

There is no super strict reason why we need one. It is currently used in the exception you get for failed `ensure` clauses for LF \>= 1.14 but that’s a relatively recent addition and we had the show requirement for ages. There are two main reasons why we have it:

1. Templates are by definition always serializable. That means that they can have a `Show` and `Eq` instance since things like functions are not possible.
2. The second one is more of an ease of use thing. Most developers are used to basically everything having a `toString` and equals method. So my autoderiving these instances for templates, you don’t have to worry about understanding deriving just as you’re getting started and instead things just work™.

In your example, why don’t you want to add a `Show` and `Eq` instance to `Foo`?

---

<div class="post-metadata">

**Author:** ![Krisztian\_Pinter](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/krisztian_pinter/32/2188_2.png) [@Krisztian\_Pinter](https://forum.canton.network/u/Krisztian_Pinter)\
**Post date:** [November 8, 2021, 12:56pm UTC](https://forum.canton.network/t/why-do-templates-need-a-show-instance/3406/3 "2021-11-08T12:56:58Z")

</div>

Thank you for the answer!

I was just wondering if the Show instance is used behind the scenes by anything specifically.

Adding a `Show`/`Eq` instance is not a problem in my example, I was just refactoring some code and when I added a new field to a template with a type that previously only appeared only in the key (which would be `Foo` in my example) I got an error. I was surprised because I assumed that it must have had a `Show` instance already. I was just wondering if there is a specific reason for keys not requiring a `Show` instance because this feels inconsistent to me.

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [November 8, 2021, 1:00pm UTC](https://forum.canton.network/t/why-do-templates-need-a-show-instance/3406/4 "2021-11-08T13:00:22Z")

</div>

> [@Krisztian\_Pinter](#):
>
> Adding a `Show` / `Eq` instance is not a problem in my example, I was just refactoring some code and when I added a new field to a template with a type that previously only appeared only in the key (which would be `Foo` in my example) I got an error. I was surprised because I assumed that it must have had a `Show` instance already. I was just wondering if there is a specific reason for keys not requiring a `Show` instance because this feels inconsistent to me.

keys are a bit different in that defining a key on a template does not define a new datatype. I think the distinction starts becoming clearer once you move from "why do templates require Show” to “why do templates autoderive Show”:

For a template autoderiving Show is nice since users don’t have to worry about understanding deriving. For a key we actually have the opposite: Given that it’s not a new datatype, we cannot autoderive the instance at the template definition. We could require it but then we force people to have to understand deriving (or manually define the instance) fairly early.

---

<div class="post-metadata">

**Author:** ![Ben\_M](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/ben_m/32/3080_2.png) [@Ben\_M](https://forum.canton.network/u/Ben_M)\
**Post date:** [January 19, 2022, 11:57pm UTC](https://forum.canton.network/t/why-do-templates-need-a-show-instance/3406/5 "2022-01-19T23:57:14Z")

</div>

> [@Krisztian\_Pinter](#):
>
> I tried looking this up in the docs but I could not find an answer.

@cocreature Thank you for those great responses, it makes sense, however as @Krisztian_Pinter said he could not find an answer.

From the perspective of building really comprehensive documentation for both Individuals and supported Customers, shouldn’t there be a **definitive** answer?
