# ScopedTypeVariables and TypeApplications

**URL:** <https://forum.canton.network/t/scopedtypevariables-and-typeapplications/3863>\
**Category:** App Development\
**Created:** [February 7, 2022, 6:56pm UTC](https://forum.canton.network/t/scopedtypevariables-and-typeapplications/3863 "2022-02-07T18:56:32Z")\
**Posts on this page:** 3\
**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:** [February 7, 2022, 6:56pm UTC](https://forum.canton.network/t/scopedtypevariables-and-typeapplications/3863/1 "2022-02-07T18:56:32Z")

</div>

Is there a limitation on using a scoped type variable in a visible type application? For example, the following doesn’t compile with “error:Not in scope: type variable ‘t’”:

```haskell
qck : TemplateKey t k => forall t k. Proxy t -> Party -> k -> Script (Optional (ContractId t, t))
qck _ = queryContractKey @t

```

Context: I’d like to write a class method that queries for a template type t in the class head, but that doesn’t work, and neither does this standalone declaration with an explicit forall.

What am I doing wrong?

---

<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:** [February 7, 2022, 7:24pm UTC](https://forum.canton.network/t/scopedtypevariables-and-typeapplications/3863/2 "2022-02-07T19:24:15Z")

</div>

Your `forall` is too far nested down. You need to pull it outside the constraint. Then your example compiles perfectly fine:

```haskell
qck : forall t k. TemplateKey t k => Proxy t -> Party -> k -> Script (Optional (ContractId t, t))
qck _ = queryContractKey @t

```

---

<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:** [February 7, 2022, 8:38pm UTC](https://forum.canton.network/t/scopedtypevariables-and-typeapplications/3863/3 "2022-02-07T20:38:56Z")

</div>

Thanks, that worked.
