# How to use gflist?

**URL:** <https://discourse.ats-lang.org/t/how-to-use-gflist/480>\
**Category:** Google Group\
**Created:** [June 16, 2015, 8:01am UTC](https://discourse.ats-lang.org/t/how-to-use-gflist/480 "2015-06-16T08:01:10Z")\
**Posts on this page:** 5\
**Page:** 1

<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:** [June 16, 2015, 8:01am UTC](https://discourse.ats-lang.org/t/how-to-use-gflist/480/1 "2015-06-16T08:01:10Z")

</div>

This one looks like a bug. Let me see if it can be easily fixed.On Tue, Jun 16, 2015 at 3:16 AM, Kiwamu Okabe [kiw...@debian.or.jp](mailto:kiw...@debian.or.jp) wrote:

> Hi all,
> 
> Now I’m writing some code using gflist.
> 
> ```auto
> #include "share/atspre_define.hats"
> #include "share/atspre_staload.hats"
> 
> staload "libats/SATS/ilist_prf.sats"
> staload "libats/SATS/gflist.sats"
> staload _ = "libats/DATS/gflist.dats"
> 
> implement main0 () = {
> val (pf1 | xs1) = list2gflist ($list{int}(1, 2, 3))
> val (pf2 | xs2) = list2gflist ($list{int}(4, 3, 2, 1))
> val (pf_append | xs3) = gflist_append (xs1, xs2)
> }
> 
> ```
> 
> However, the code has error on GCC side.
> 
> $ patscc test\_gflist.dats -DATS\_MEMALLOC\_LIBC  
> In file included from test\_gflist\_dats.c:15:0:  
> test\_gflist\_dats.c: In function ‘loop\_2\_\_2\_\_1’:  
> /home/kiwamu/src/ATS-Postiats/ccomp/runtime/pats\_ccomp\_instrset.h:260:35:  
> error: assignment to expression with array type  
> #define ATSINSmove(tmp, val) (tmp = val)  
> ^  
> test\_gflist\_dats.c:910:1: note: in expansion of macro ‘ATSINSmove’  
> ATSINSmove(tmp10\_\_1, ATSSELcon(arg0, postiats\_tysum\_0, atslab\_\_0)) ;  
> ^  
> /home/kiwamu/src/ATS-Postiats/ccomp/runtime/pats\_ccomp\_instrset.h:287:74:  
> warning: assignment makes integer from pointer without a cast  
> #define ATSINSstore\_con1\_ofs(tmp, tysum, lab, val) (((tysum\*)(tmp))-\>lab  
> = val)  
> ^  
> test\_gflist\_dats.c:939:1: note: in expansion of macro  
> ‘ATSINSstore\_con1\_ofs’  
> ATSINSstore\_con1\_ofs(tmp12\_\_1, postiats\_tysum\_3, atslab\_\_0, tmp10\_\_1) ;  
> ^
> 
> How to use gflist?
> 
> ## Thank’s,
> 
> Kiwamu Okabe at METASEPI DESIGN
> 
> –  
> 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/CAEvX6dmYKd5yV%2B2%2BFG%3DJXJ%2B31YFJj83863FCsoJrW0-CioXneg%40mail.gmail.com](https://groups.google.com/d/msgid/ats-lang-users/CAEvX6dmYKd5yV%2B2%2BFG%3DJXJ%2B31YFJj83863FCsoJrW0-CioXneg%40mail.gmail.com)  
> .

---

<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:** [June 16, 2015, 5:09pm UTC](https://discourse.ats-lang.org/t/how-to-use-gflist/480/2 "2015-06-16T17:09:05Z")

</div>

I fixed the issue with gflist. Here is a small file for testing gflist:

> <https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAMPLE/ATSLIB/libats_gflist.dats>

Code involving gflist has not really been run until now. So far the primary  
use of gflist is for education  
in program verification.On Tue, Jun 16, 2015 at 4:01 AM, Hongwei Xi [gmh...@gmail.com](mailto:gmh...@gmail.com) wrote:

> This one looks like a bug. Let me see if it can be easily fixed.
> 
> On Tue, Jun 16, 2015 at 3:16 AM, Kiwamu Okabe [kiw...@debian.or.jp](mailto:kiw...@debian.or.jp) wrote:
> 
> > Hi all,
> > 
> > Now I’m writing some code using gflist.
> > 
> > ```auto
> > #include "share/atspre_define.hats"
> > #include "share/atspre_staload.hats"
> > 
> > staload "libats/SATS/ilist_prf.sats"
> > staload "libats/SATS/gflist.sats"
> > staload _ = "libats/DATS/gflist.dats"
> > 
> > implement main0 () = {
> > val (pf1 | xs1) = list2gflist ($list{int}(1, 2, 3))
> > val (pf2 | xs2) = list2gflist ($list{int}(4, 3, 2, 1))
> > val (pf_append | xs3) = gflist_append (xs1, xs2)
> > }
> > 
> > ```
> > 
> > However, the code has error on GCC side.
> > 
> > $ patscc test\_gflist.dats -DATS\_MEMALLOC\_LIBC  
> > In file included from test\_gflist\_dats.c:15:0:  
> > test\_gflist\_dats.c: In function ‘loop\_2\_\_2\_\_1’:  
> > /home/kiwamu/src/ATS-Postiats/ccomp/runtime/pats\_ccomp\_instrset.h:260:35:  
> > error: assignment to expression with array type  
> > #define ATSINSmove(tmp, val) (tmp = val)  
> > ^  
> > test\_gflist\_dats.c:910:1: note: in expansion of macro ‘ATSINSmove’  
> > ATSINSmove(tmp10\_\_1, ATSSELcon(arg0, postiats\_tysum\_0, atslab\_\_0)) ;  
> > ^  
> > /home/kiwamu/src/ATS-Postiats/ccomp/runtime/pats\_ccomp\_instrset.h:287:74:  
> > warning: assignment makes integer from pointer without a cast  
> > #define ATSINSstore\_con1\_ofs(tmp, tysum, lab, val) (((tysum\*)(tmp))-\>lab  
> > = val)
> > 
> > ^  
> > test\_gflist\_dats.c:939:1: note: in expansion of macro  
> > ‘ATSINSstore\_con1\_ofs’  
> > ATSINSstore\_con1\_ofs(tmp12\_\_1, postiats\_tysum\_3, atslab\_\_0, tmp10\_\_1) ;  
> > ^
> > 
> > How to use gflist?
> > 
> > ## Thank’s,
> > 
> > Kiwamu Okabe at METASEPI DESIGN
> > 
> > –  
> > 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/CAEvX6dmYKd5yV%2B2%2BFG%3DJXJ%2B31YFJj83863FCsoJrW0-CioXneg%40mail.gmail.com](https://groups.google.com/d/msgid/ats-lang-users/CAEvX6dmYKd5yV%2B2%2BFG%3DJXJ%2B31YFJj83863FCsoJrW0-CioXneg%40mail.gmail.com)  
> > .

---

<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:** [June 19, 2015, 3:20am UTC](https://discourse.ats-lang.org/t/how-to-use-gflist/480/3 "2015-06-19T03:20:14Z")

</div>

Search INV in this forum, and you can find some explanation. For instance:

[Redirecting to Google Groups](https://groups.google.com/forum/#!searchin/ats-lang-users/INV/ats-lang-users/ptwztS9IHWg/NcyCP1vjTB8JOn) Thursday, June 18, 2015 at 10:49:34 PM UTC-4, Kiwamu Okabe wrote:

> Hi Hongwei,
> 
> On Fri, Jun 19, 2015 at 9:01 AM, gmhwxi \<[gmh...@gmail.com](mailto:gmh...@gmail.com) \<javascript:\>\> wrote:
> 
> > extern  
> > fun{a:t@ype}  
> > gflist\_append\_length  
> > {xs1,xs2:ilist}{n1,n2:int}  
> > ( pf1: LENGTH (xs1, n1), pf2: LENGTH (xs2, n2)  
> > | xs1: gflist (INV(a), xs1), xs2: gflist (a, xs2)  
> > ): [res:ilist] (LENGTH (res, n1+n2), APPEND (xs1, xs2, res) | gflist (a,  
> > res))
> > 
> > You use INV(a) to tell the typechecker how a type constraint should be  
> > generated with respect xs1.
> 
> For my eye, INV(a) has no meaning.
> 
> abst@ype // S2Einvar  
> invar\_t0ype\_t0ype (a:t@ype) = a  
> vtypedef  
> INV (a: t@ype) = invar\_t0ype\_t0ype (a)
> 
> How does it work?
> 
> ## Regards,
> 
> Kiwamu Okabe at METASEPI DESIGN

---

<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:** [June 17, 2015, 5:02pm UTC](https://discourse.ats-lang.org/t/how-to-use-gflist/480/4 "2015-06-17T17:02:57Z")

</div>

Where could I find your code?On Wednesday, June 17, 2015 at 1:08:03 AM UTC-4, Kiwamu Okabe wrote:

> Hi Hongwei,
> 
> On Wed, Jun 17, 2015 at 2:09 AM, Hongwei Xi \<[gmh...@gmail.com](mailto:gmh...@gmail.com) \<javascript:\>\> wrote:
> 
> > I fixed the issue with gflist. Here is a small file for testing gflist:
> 
> My code is also available to be compiled.
> 
> ## Thank’s,
> 
> Kiwamu Okabe at METASEPI DESIGN

---

<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:** [June 19, 2015, 12:01am UTC](https://discourse.ats-lang.org/t/how-to-use-gflist/480/5 "2015-06-19T00:01:56Z")

</div>

extern fun{a:t@ype} gflist\_append\_length {xs1,xs2:ilist}{n1,n2:int} (pf1:  
LENGTH (xs1, n1), pf2: LENGTH (xs2, n2) | xs1: gflist (a, xs1), xs2: gflist  
(a, xs2)): [res:ilist] (LENGTH (res, n1+n2), APPEND (xs1, xs2, res) |  
gflist (a, res))

changes to

extern  
fun{a:t@ype}  
gflist\_append\_length  
{xs1,xs2:ilist}{n1,n2:int}  
( pf1: LENGTH (xs1, n1), pf2: LENGTH (xs2, n2)  
| xs1: gflist (INV(a), xs1), xs2: gflist (a, xs2)  
): [res:ilist] (LENGTH (res, n1+n2), APPEND (xs1, xs2, res) | gflist (a, res  
))

You use INV(a) to tell the typechecker how a type constraint should be  
generated with respect xs1.On Thursday, June 18, 2015 at 6:04:18 AM UTC-4, Kiwamu Okabe wrote:

> Hi Hongwei,
> 
> > 
> 
> [https://github.com/jats-ug/practice-ats/blob/master/test\_gflist/main.dats](https://github.com/jats-ug/practice-ats/blob/master/test_gflist/main.dats)
> 
> I found an error, while change the main0 function as following:
> 
> $ git diff . | cat  
> diff --git a/test\_gflist/main.dats b/test\_gflist/main.dats  
> index dd058b3…a6e1ca3 100644  
> — a/test\_gflist/main.dats  
> +++ b/test\_gflist/main.dats  
> @@ -26,5 +26,5 @@ implement main0 () = {  
> val (pf2 | xs2) = list2gflist l2  
> val (pf\_len, pf\_append | xs3) = gflist\_append\_length (pf1, pf2 | xs1,  
> xs2)  
> val (pf3 | l3) = gflist2list xs3
> 
> - val () = print\_list l3
> 
> - val () = print\_list l3  
> }  
> $ patscc main.dats -DATS\_MEMALLOC\_LIBC  
> In file included from main\_dats.c:15:0:  
> main\_dats.c: In function ‘ATSLIB\_056\_prelude\_\_fprint\_val\_\_27\_\_1’:  
> main\_dats.c:2531:22: error: ‘PMVtmpltcstmat’ undeclared (first use in  
> this function)  
> ATSINSmove(tmp65\_\_1, PMVtmpltcstmat0(arg1))  
> ;  
> ^
> 
> In future, it should be fixed?
> 
> ## Thank’s,
> 
> Kiwamu Okabe
