# View equality in template function

**URL:** <https://discourse.ats-lang.org/t/view-equality-in-template-function/21>\
**Category:** Google Group\
**Created:** [March 26, 2015, 6:03am UTC](https://discourse.ats-lang.org/t/view-equality-in-template-function/21 "2015-03-26T06:03:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Artyom\_Shalkhakov](https://avatars.discourse-cdn.com/v4/letter/a/6bbea6/32.png) [@Artyom\_Shalkhakov](https://discourse.ats-lang.org/u/Artyom_Shalkhakov)\
**Post date:** [March 26, 2015, 6:03am UTC](https://discourse.ats-lang.org/t/view-equality-in-template-function/21/1 "2015-03-26T06:03:21Z")

</div>

Hello all,

Here’s an issue:

> <https://gist.github.com/ashalkhakov/85b3046c0432f93d08df>

Is there a solution not involving unsafe casts? This sort of  
loop-construction seems like a very common thing to do. Threading views is  
also common, but templates do not allow that. If env is given a viewtype  
(@[int][N] @ A | void), it still doesn’t work (no template is found for  
fwork).

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [March 26, 2015, 5:51pm UTC](https://discourse.ats-lang.org/t/view-equality-in-template-function/21/2 "2015-03-26T17:51:16Z")

</div>

Unfortunately, this cannot be done.

The only way I can see to make it safe is this:

absvtype myenv = void  
// implement the following two proof functions  
prfun myenv\_decode (&myenv \>\> void): @[int][N]@A  
prfun myenv\_encode (&void \>\> myenv, @[int][N]@A): void

implement  
loop$fwork (env) = … // using decode and encode

…loop()…On Thursday, March 26, 2015 at 2:03:21 AM UTC-4, Artyom Shalkhakov wrote:

> Hello all,
> 
> Here’s an issue:
> 
> [View equalities in templates · GitHub](https://gist.github.com/ashalkhakov/85b3046c0432f93d08df)
> 
> Is there a solution not involving unsafe casts? This sort of  
> loop-construction seems like a very common thing to do. Threading views is  
> also common, but templates do not allow that. If env is given a viewtype  
> (@[int][N] @ A | void), it still doesn’t work (no template is found for  
> fwork).

---

<div class="post-metadata">

**Author:** ![Artyom\_Shalkhakov](https://avatars.discourse-cdn.com/v4/letter/a/6bbea6/32.png) [@Artyom\_Shalkhakov](https://discourse.ats-lang.org/u/Artyom_Shalkhakov)\
**Post date:** [March 27, 2015, 2:13am UTC](https://discourse.ats-lang.org/t/view-equality-in-template-function/21/3 "2015-03-27T02:13:47Z")

</div>

> Unfortunately, this cannot be done.
> 
> The only way I can see to make it safe is this:
> 
> absvtype myenv = void  
> // implement the following two proof functions  
> prfun myenv\_decode (&myenv \>\> void): @[int][N]@A  
> prfun myenv\_encode (&void \>\> myenv, @[int][N]@A): void
> 
> implement  
> loop$fwork (env) = … // using decode and encode
> 
> …loop()…

Okay, if you say so. I’ll be using some unsafe casts then.\> On Thursday, March 26, 2015 at 2:03:21 AM UTC-4, Artyom Shalkhakov wrote:

> > Hello all,
> > 
> > Here’s an issue:
> > 
> > [View equalities in templates · GitHub](https://gist.github.com/ashalkhakov/85b3046c0432f93d08df)
> > 
> > Is there a solution not involving unsafe casts? This sort of  
> > loop-construction seems like a very common thing to do. Threading views is  
> > also common, but templates do not allow that. If env is given a viewtype  
> > (@[int][N] @ A | void), it still doesn’t work (no template is found for  
> > fwork).
