# Redefining function template

**URL:** <https://discourse.ats-lang.org/t/redefining-function-template/207>\
**Category:** Google Group\
**Created:** [November 25, 2015, 3:37pm UTC](https://discourse.ats-lang.org/t/redefining-function-template/207 "2015-11-25T15:37:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_Jones](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@Mike\_Jones](https://discourse.ats-lang.org/u/Mike_Jones)\
**Post date:** [November 25, 2015, 3:37pm UTC](https://discourse.ats-lang.org/t/redefining-function-template/207/1 "2015-11-25T15:37:49Z")

</div>

This code gives compile error:

mike: 4385(line=147, offs=36) – 4406(line=147, offs=57): error(3): the  
dynamic expression cannot be assigned the type [S2Efun(FUN; lin=0; eff=S2EFFset(1); npf=-1; S2Ecst(hex\_t), S2Ecst(hex\_t); S2Ecst(uint8))].  
mike: 4385(line=147, offs=36) – 4406(line=147, offs=57): error(3):  
mismatch of static terms (tyleq):  
The actual term is: S2Eapp(S2Ecst(g0uint\_t0ype); S2Eextkind(atstype\_uint8))  
The needed term is: S2Efun(FUN; lin=0; eff=S2EFFset(1); npf=-1;  
S2Ecst(hex\_t), S2Ecst(hex\_t); S2Ecst(uint8))  
patsopt(TRANS3): there are [1] errors in total.  
exit(ATS): uncaught exception:  
\_2home\_2hwxi\_2Research\_2ATS\_2dPostiats\_2src\_2pats\_error\_2esats\_\_FatalErrorExn(1025)

Which I think means hex\_to\_byte\_ is not returning a function type. I have a  
similar one without parameters that works, but I am not sure how to  
structure this code so that it works with parameters. The goal being to  
instantiate the template so I can effectively turn it off to make inlining  
tradeoffs. In the present case, compiling for my Cypress A9 target in debug  
mode is exploding the size of the code and there is not enough memory. I  
suppose I could also tell the compiler not to inline, but let’s see if I  
can make this work for the more general case.

extern fun{} hex\_to\_byte (msn: hex\_t, lsn: hex\_t) : uint8  
implement{} hex\_to\_byte (msn, lsn) = let  
…  
in  
…  
end

extern fun hex\_to\_byte\_(msn: hex\_t, lsn: hex\_t) : $d2ctype(hex\_to\_byte\<\>)  
implement hex\_to\_byte\_(msn, lsn) = hex\_to\_byte(msn, lsn)

#define hex\_to\_byte hex\_to\_byte\_

---

<div class="post-metadata">

**Author:** ![Mike\_Jones](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@Mike\_Jones](https://discourse.ats-lang.org/u/Mike_Jones)\
**Post date:** [November 25, 2015, 6:01pm UTC](https://discourse.ats-lang.org/t/redefining-function-template/207/2 "2015-11-25T18:01:51Z")

</div>

I solved another instantiation problem, and the one magically disappeared.  
I don’t know why, but I’m moving forward.

---

<div class="post-metadata">

**Author:** ![Mike\_Jones](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@Mike\_Jones](https://discourse.ats-lang.org/u/Mike_Jones)\
**Post date:** [November 25, 2015, 4:52pm UTC](https://discourse.ats-lang.org/t/redefining-function-template/207/3 "2015-11-25T16:52:32Z")

</div>

I had that originally, but failed in the C compile. It turned out that I  
needed: staload \_ = “prelude/DATS/integer\_fixed.dats”

It seems that this staload is required in the file that instantiates the  
template, not the file that defines it. Furthermore, it appears that  
staload of dats file is recursive, because this load was not in the  
original file that instantiated. It had to pick it up from some other load.

Is there some easy way such that if you staload load a dats file the proper  
staload dependencies come with it, and the compiler checks that you have  
them in the file defining the template so that anyone that reuses your code  
does not have to struggle to find the missing staload for its templates?On Wednesday, November 25, 2015 at 8:42:19 AM UTC-7, gmhwxi wrote:

> > > extern fun hex\_to\_byte\_(msn: hex\_t, lsn: hex\_t) : $d2ctype(hex\_to\_byte\<\>)
> 
> Should be
> 
> extern fun hex\_to\_byte\_ : $d2ctype(hex\_to\_byte\<\>)
> 
> On Wed, Nov 25, 2015 at 10:37 AM, Mike Jones \<[pro...@gmail.com](mailto:pro...@gmail.com) \<javascript:\>\> wrote:
> 
> > This code gives compile error:
> > 
> > mike: 4385(line=147, offs=36) – 4406(line=147, offs=57): error(3): the  
> > dynamic expression cannot be assigned the type [S2Efun(FUN; lin=0; eff=S2EFFset(1); npf=-1; S2Ecst(hex\_t), S2Ecst(hex\_t); S2Ecst(uint8))].  
> > mike: 4385(line=147, offs=36) – 4406(line=147, offs=57): error(3):  
> > mismatch of static terms (tyleq):  
> > The actual term is: S2Eapp(S2Ecst(g0uint\_t0ype);  
> > S2Eextkind(atstype\_uint8))  
> > The needed term is: S2Efun(FUN; lin=0; eff=S2EFFset(1); npf=-1;  
> > S2Ecst(hex\_t), S2Ecst(hex\_t); S2Ecst(uint8))  
> > patsopt(TRANS3): there are [1] errors in total.  
> > exit(ATS): uncaught exception:  
> > \_2home\_2hwxi\_2Research\_2ATS\_2dPostiats\_2src\_2pats\_error\_2esats\_\_FatalErrorExn(1025)
> > 
> > Which I think means hex\_to\_byte\_ is not returning a function type. I have  
> > a similar one without parameters that works, but I am not sure how to  
> > structure this code so that it works with parameters. The goal being to  
> > instantiate the template so I can effectively turn it off to make inlining  
> > tradeoffs. In the present case, compiling for my Cypress A9 target in debug  
> > mode is exploding the size of the code and there is not enough memory. I  
> > suppose I could also tell the compiler not to inline, but let’s see if I  
> > can make this work for the more general case.
> > 
> > extern fun{} hex\_to\_byte (msn: hex\_t, lsn: hex\_t) : uint8  
> > implement{} hex\_to\_byte (msn, lsn) = let  
> > …  
> > in  
> > …  
> > end
> > 
> > extern fun hex\_to\_byte\_(msn: hex\_t, lsn: hex\_t) : $d2ctype(hex\_to\_byte\<\>)  
> > implement hex\_to\_byte\_(msn, lsn) = hex\_to\_byte(msn, lsn)
> > 
> > #define hex\_to\_byte hex\_to\_byte\_
> > 
> > –  
> > You received this message because you are subscribed to the Google Groups  
> > “ats-lang-users” group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [ats-lang...@googlegroups.com](mailto:ats-lang...@googlegroups.com) \<javascript:\>.  
> > To post to this group, send email to [ats-l...@googlegroups.com](mailto:ats-l...@googlegroups.com)  
> > \<javascript:\>.  
> > Visit this group at [http://groups.google.com/group/ats-lang-users](http://groups.google.com/group/ats-lang-users).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/ats-lang-users/c9060a56-9f54-472c-b3b1-d2d050c3161e%40googlegroups.com](https://groups.google.com/d/msgid/ats-lang-users/c9060a56-9f54-472c-b3b1-d2d050c3161e%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/ats-lang-users/c9060a56-9f54-472c-b3b1-d2d050c3161e%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/ats-lang-users/c9060a56-9f54-472c-b3b1-d2d050c3161e%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .

---

<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:** [November 25, 2015, 3:42pm UTC](https://discourse.ats-lang.org/t/redefining-function-template/207/4 "2015-11-25T15:42:19Z")

</div>

> > extern fun hex\_to\_byte\_(msn: hex\_t, lsn: hex\_t) : $d2ctype(hex\_to\_byte\<\>)

Should be

extern fun hex\_to\_byte\_ : $d2ctype(hex\_to\_byte\<\>)On Wed, Nov 25, 2015 at 10:37 AM, Mike Jones [proc...@gmail.com](mailto:proc...@gmail.com) wrote:

> This code gives compile error:
> 
> mike: 4385(line=147, offs=36) – 4406(line=147, offs=57): error(3): the  
> dynamic expression cannot be assigned the type [S2Efun(FUN; lin=0; eff=S2EFFset(1); npf=-1; S2Ecst(hex\_t), S2Ecst(hex\_t); S2Ecst(uint8))].  
> mike: 4385(line=147, offs=36) – 4406(line=147, offs=57): error(3):  
> mismatch of static terms (tyleq):  
> The actual term is: S2Eapp(S2Ecst(g0uint\_t0ype); S2Eextkind(atstype\_uint8))  
> The needed term is: S2Efun(FUN; lin=0; eff=S2EFFset(1); npf=-1;  
> S2Ecst(hex\_t), S2Ecst(hex\_t); S2Ecst(uint8))  
> patsopt(TRANS3): there are [1] errors in total.  
> exit(ATS): uncaught exception:  
> \_2home\_2hwxi\_2Research\_2ATS\_2dPostiats\_2src\_2pats\_error\_2esats\_\_FatalErrorExn(1025)
> 
> Which I think means hex\_to\_byte\_ is not returning a function type. I have  
> a similar one without parameters that works, but I am not sure how to  
> structure this code so that it works with parameters. The goal being to  
> instantiate the template so I can effectively turn it off to make inlining  
> tradeoffs. In the present case, compiling for my Cypress A9 target in debug  
> mode is exploding the size of the code and there is not enough memory. I  
> suppose I could also tell the compiler not to inline, but let’s see if I  
> can make this work for the more general case.
> 
> extern fun{} hex\_to\_byte (msn: hex\_t, lsn: hex\_t) : uint8  
> implement{} hex\_to\_byte (msn, lsn) = let  
> …  
> in  
> …  
> end
> 
> extern fun hex\_to\_byte\_(msn: hex\_t, lsn: hex\_t) : $d2ctype(hex\_to\_byte\<\>)  
> implement hex\_to\_byte\_(msn, lsn) = hex\_to\_byte(msn, lsn)
> 
> #define hex\_to\_byte hex\_to\_byte\_
> 
> –  
> You received this message because you are subscribed to the Google Groups  
> “ats-lang-users” group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [ats-lang-user...@googlegroups.com](mailto:ats-lang-user...@googlegroups.com).  
> To post to this group, send email to [ats-lan...@googlegroups.com](mailto:ats-lan...@googlegroups.com).  
> Visit this group at [http://groups.google.com/group/ats-lang-users](http://groups.google.com/group/ats-lang-users).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/ats-lang-users/c9060a56-9f54-472c-b3b1-d2d050c3161e%40googlegroups.com](https://groups.google.com/d/msgid/ats-lang-users/c9060a56-9f54-472c-b3b1-d2d050c3161e%40googlegroups.com)  
> [https://groups.google.com/d/msgid/ats-lang-users/c9060a56-9f54-472c-b3b1-d2d050c3161e%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/ats-lang-users/c9060a56-9f54-472c-b3b1-d2d050c3161e%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .

---

<div class="post-metadata">

**Author:** ![Mike\_Jones](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@Mike\_Jones](https://discourse.ats-lang.org/u/Mike_Jones)\
**Post date:** [November 25, 2015, 5:40pm UTC](https://discourse.ats-lang.org/t/redefining-function-template/207/5 "2015-11-25T17:40:52Z")

</div>

This one is causing problems with g0uint\_t0ype and array\_get\_at\_gint in  
terms of missing casts, and including unsafe.sats/dats and basics\_sta.sats  
are not fixing it, even though they are defined in these. Do I need to  
change the second implement somehow? Perhaps to account for the existential?

extern fun{} set\_n {n0: nat | n0 \>= 3 && n0 \<= 127} (count: int(n0)): void  
implement{} set\_n {n0} (count) = let  
…  
in  
…  
end

extern  
fun set\_n\_ : $d2ctype(set\_n\<\>)  
implement set\_n\_(count) = set\_n(count)

#define set\_n set\_n\_

---

<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:** [November 25, 2015, 10:16pm UTC](https://discourse.ats-lang.org/t/redefining-function-template/207/6 "2015-11-25T22:16:41Z")

</div>

> I had that originally, but failed in the C compile. It turned out that I  
> needed: staload \_ = “prelude/DATS/integer\_fixed.dats”
> 
> It seems that this staload is required in the file that instantiates the  
> template, not the file that defines it. Furthermore, it appears that  
> staload of dats file is recursive, because this load was not in the  
> original file that instantiated. It had to pick it up from some other load.
> 
> Is there some easy way such that if you staload load a dats file the  
> proper staload dependencies come with it, and the compiler checks that you  
> have them in the file defining the template so that anyone that reuses your  
> code does not have to struggle to find the missing staload for its  
> templates?

There is no such an easy way right now.\> On Wednesday, November 25, 2015 at 8:42:19 AM UTC-7, gmhwxi wrote:

> > > > extern fun hex\_to\_byte\_(msn: hex\_t, lsn: hex\_t) :  
> > > > $d2ctype(hex\_to\_byte\<\>)
> > 
> > Should be
> > 
> > extern fun hex\_to\_byte\_ : $d2ctype(hex\_to\_byte\<\>)
> > 
> > On Wed, Nov 25, 2015 at 10:37 AM, Mike Jones [pro...@gmail.com](mailto:pro...@gmail.com) wrote:
> > 
> > > This code gives compile error:
> > > 
> > > mike: 4385(line=147, offs=36) – 4406(line=147, offs=57): error(3): the  
> > > dynamic expression cannot be assigned the type [S2Efun(FUN; lin=0; eff=S2EFFset(1); npf=-1; S2Ecst(hex\_t), S2Ecst(hex\_t); S2Ecst(uint8))].  
> > > mike: 4385(line=147, offs=36) – 4406(line=147, offs=57): error(3):  
> > > mismatch of static terms (tyleq):  
> > > The actual term is: S2Eapp(S2Ecst(g0uint\_t0ype);  
> > > S2Eextkind(atstype\_uint8))  
> > > The needed term is: S2Efun(FUN; lin=0; eff=S2EFFset(1); npf=-1;  
> > > S2Ecst(hex\_t), S2Ecst(hex\_t); S2Ecst(uint8))  
> > > patsopt(TRANS3): there are [1] errors in total.  
> > > exit(ATS): uncaught exception:  
> > > \_2home\_2hwxi\_2Research\_2ATS\_2dPostiats\_2src\_2pats\_error\_2esats\_\_FatalErrorExn(1025)
> > > 
> > > Which I think means hex\_to\_byte\_ is not returning a function type. I  
> > > have a similar one without parameters that works, but I am not sure how to  
> > > structure this code so that it works with parameters. The goal being to  
> > > instantiate the template so I can effectively turn it off to make inlining  
> > > tradeoffs. In the present case, compiling for my Cypress A9 target in debug  
> > > mode is exploding the size of the code and there is not enough memory. I  
> > > suppose I could also tell the compiler not to inline, but let’s see if I  
> > > can make this work for the more general case.
> > > 
> > > extern fun{} hex\_to\_byte (msn: hex\_t, lsn: hex\_t) : uint8  
> > > implement{} hex\_to\_byte (msn, lsn) = let  
> > > …  
> > > in  
> > > …  
> > > end
> > > 
> > > extern fun hex\_to\_byte\_(msn: hex\_t, lsn: hex\_t) : $d2ctype(hex\_to\_byte\<\>)  
> > > implement hex\_to\_byte\_(msn, lsn) = hex\_to\_byte(msn, lsn)
> > > 
> > > #define hex\_to\_byte hex\_to\_byte\_
> > > 
> > > –  
> > > You received this message because you are subscribed to the Google  
> > > Groups “ats-lang-users” group.  
> > > To unsubscribe from this group and stop receiving emails from it, send  
> > > an email to [ats-lang...@googlegroups.com](mailto:ats-lang...@googlegroups.com).  
> > > To post to this group, send email to [ats-l...@googlegroups.com](mailto:ats-l...@googlegroups.com).  
> > > Visit this group at [http://groups.google.com/group/ats-lang-users](http://groups.google.com/group/ats-lang-users).  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/ats-lang-users/c9060a56-9f54-472c-b3b1-d2d050c3161e%40googlegroups.com](https://groups.google.com/d/msgid/ats-lang-users/c9060a56-9f54-472c-b3b1-d2d050c3161e%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/ats-lang-users/c9060a56-9f54-472c-b3b1-d2d050c3161e%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/ats-lang-users/c9060a56-9f54-472c-b3b1-d2d050c3161e%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .
