Re: Is this group still active?

2024-02-13 Thread Hongwei Xi
The group has been dormant for quite some time.

>> I hope all is well with development on ATS3 at least!

Thank you!

It is ongoing, and, hopefully, we will have a release this year.

Cheers!

--Hongwei


On Wed, Feb 14, 2024 at 1:08 AM Gianni  wrote:

> Hello,
> I was wondering if this group was still active for questions since I
> noticed that there are a lot of spam messages, no new topics since last
> year, and no new questions specific to the language for two years :(
>
> I hope all is well with development on ATS3 at least!
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/2f0b73ed-a7ad-4ac3-a200-6fd86f0bdfe8n%40googlegroups.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLr0CzF29cWd6OuBS4fcrm%3Df3BCbzRXBG20tBiObS33qjg%40mail.gmail.com.


Re: Non-consuming linear stream

2022-07-12 Thread Hongwei Xi
By the way, qlist is not flat; it is based on list. To have a flat one, you
can use dynarray
(which is like vector in C++). I suppose that dynarray can further shorten
the running time.

On Tue, Jul 12, 2022 at 8:44 AM Hongwei Xi  wrote:

> Thanks for this very interesting example!
>
> I did my test03 that more or less matches your test07:
>
> https://github.com/githwxi/ATS-Postiats/tree/master/libats/TEST
>
> Yes, it is significantly more efficient (time-wise) than both of test01
> and test02 that I did earlier. However, it is not memory-efficient. You
> can find some measurements in the source code.
>
> A qlist is essentially a list. To free it, you can take out the list and
> free
> it and then free the (empty) qlist. Please see my test03.dats. Also, if
> you use valgrind on test03, you can see that all the allocated blocks
> are freed at the end (except the one for the closure passed to the
> higher-order
> function stream_vt_take_while):
>
> ==23360== Memcheck, a memory error detector
> ==23360== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
> ==23360== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright
> info
> ==23360== Command: ./test03
> ==23360==
> nprime(1048576) = 82025
> ==23360==
> ==23360== HEAP SUMMARY:
> ==23360== in use at exit: 16 bytes in 1 blocks
> ==23360==   total heap usage: 328,108 allocs, 328,107 frees, 6,563,160
> bytes allocated
> ==23360==
> ==23360== LEAK SUMMARY:
> ==23360==definitely lost: 16 bytes in 1 blocks
> ==23360==indirectly lost: 0 bytes in 0 blocks
> ==23360==  possibly lost: 0 bytes in 0 blocks
> ==23360==still reachable: 0 bytes in 0 blocks
> ==23360== suppressed: 0 bytes in 0 blocks
> ==23360== Rerun with --leak-check=full to see details of leaked memory
> ==23360==
> ==23360== For counts of detected and suppressed errors, rerun with: -v
> ==23360== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
>
> For efficiency, it is important to minimize the use of non-linear streams.
> For instance, after seeing your test04, my immediate "solution" is to use
> primes()
> to implement primes_vt() and then uses primes_vt() to generate a linear
> stream of
> prime numbers.
>
> Again, thanks for the example. I hope that ATS3 will be a lot more
> convenient to use
> than ATS2 while being at least equally performant both time-wise and
> memory-wise :)
>
> Cheers!
>
> --Hongwei
>
>
> On Tue, Jul 12, 2022 at 2:54 AM Dambaev Alexander 
> wrote:
>
>> Hi,
>>
>> I had replaced list_vt with qlist and now it is the most efficient
>> version I could get now:
>> ```
>> patscc -O2 -DATS_MEMALLOC_LIBC -I"../libs/" -o test7   TEST/test7.dats
>> /run/current-system/sw/bin/time ./test7
>> 1077871
>> 0.84user 0.01system 0:00.85elapsed 100%CPU (0avgtext+0avgdata
>> 35108maxresident)k
>> 0inputs+0outputs (0major+8486minor)pagefaults 0swaps
>> ```
>> in comparison to haskell's:
>> ```
>> 1.16user 0.02system 0:01.18elapsed 99%CPU (0avgtext+0avgdata
>> 74492maxresident)k
>> 0inputs+0outputs (0major+17827minor)pagefaults 0swaps
>> ```
>> I have to note, that test4 is more correct than test3: it is the same,
>> except that it is using GC to collect stream()
>> ```
>> patscc -O2 -DATS_MEMALLOC_GCBDW -lgc -o test4   TEST/test4.dats
>> /run/current-system/sw/bin/time ./test4
>> 1077871
>> 2.13user 0.03system 0:02.13elapsed 101%CPU (0avgtext+0avgdata
>> 97344maxresident)k
>> ```
>> which is expected to use less memory, but increases time to GC (as
>> expected as well), but, technically, this version is the closest to
>> haskell's one.
>>
>> for 2^30 constraint:
>> ```
>> patscc -O2 -DATS_MEMALLOC_LIBC -I"../libs/" -o test7   TEST/test7.dats
>> /run/current-system/sw/bin/time ./test7
>> 54400028
>> 227.79user 0.63system 3:48.43elapsed 99%CPU (0avgtext+0avgdata
>> 1701428maxresident)k
>> 0inputs+0outputs (0major+425064minor)pagefaults 0swaps
>> ```
>> haskell version with GHC8.10:
>> ```
>> 54400028
>> 278.48user 0.62system 4:38.75elapsed 100%CPU (0avgtext+0avgdata
>> 3016564maxresident)k
>> 0inputs+0outputs (0major+753319minor)pagefaults 0swaps
>> ```
>> and test4
>> ```
>> patscc -O2 -DATS_MEMALLOC_GCBDW -lgc -o test4   TEST/test4.dats
>> /run/current-system/sw/bin/time ./test4
>> 54400028
>> 704.39user 1.81system 11:46.22elapsed 99%CPU (0avgtext+0avgdata
>> 4966216maxresident)k
>> 0inputs+0outputs (0major+1241156minor)pagefaults 0swaps
>> ```
>> I am wondering why test4 performs 

Re: Non-consuming linear stream

2022-07-12 Thread Hongwei Xi
;>>
>>>> вс, 10 июл. 2022 г. в 03:12, gmhwxi :
>>>>
>>>>>
>>>>> I see.
>>>>>
>>>>> By the way, when I tried test1 and test3 on my machine, the latter is
>>>>> only about 10% faster than the former.
>>>>>
>>>>> It should be easy to have a version in ATS that beats Haskell:
>>>>>
>>>>> You first produce a non-linear thePrimes. Then you produce a linear
>>>>> thePrimes2 (where isPrime uses thePrimes).
>>>>> In this way, the memory foot print should be very small. And I bet the
>>>>> running time is much faster. Try 2^28 or 2^30 :)
>>>>>
>>>>> On Saturday, July 9, 2022 at 10:37:03 PM UTC-4 ice.r...@gmail.com
>>>>> wrote:
>>>>>
>>>>>> I will check ATS3 version, meanwhile GHC 8.10 produces much more
>>>>>> optimised code:
>>>>>>
>>>>>> ```
>>>>>> [nix-shell:/data/devel/mobt2/haskell]$ ghc --version
>>>>>> The Glorious Glasgow Haskell Compilation System, version 8.10.7
>>>>>> [nix-shell:/data/devel/mobt2/haskell]$ ghc -O2 --make app/Main.hs -o
>>>>>> haskell
>>>>>> [1 of 1] Compiling Main ( app/Main.hs, app/Main.o )
>>>>>> Linking haskell ...
>>>>>> [nix-shell:/data/devel/mobt2/haskell]$ $(which time) ./haskell
>>>>>> 1077871
>>>>>> 1.04user 0.00system 0:01.05elapsed 100%CPU (0avgtext+0avgdata
>>>>>> 72140maxresident)k
>>>>>> 0inputs+0outputs (0major+17298minor)pagefaults 0swaps
>>>>>> ```
>>>>>> in comparison to ATS2 versions from repo above:
>>>>>>
>>>>>> ```
>>>>>> [nix-shell:/data/devel/mobt2/ats2/src]$ make
>>>>>> patscc -O2 -DATS_MEMALLOC_LIBC -I"../libs/" -o test3   TEST/test3.dats
>>>>>> /run/current-system/sw/bin/time ./test3
>>>>>> 1077871
>>>>>> 1.11user 0.01system 0:01.12elapsed 100%CPU (0avgtext+0avgdata
>>>>>> 102456maxresident)k
>>>>>> 0inputs+0outputs (0major+25327minor)pagefaults 0swaps
>>>>>> patscc -O2 -DATS_MEMALLOC_LIBC -I"../libs/" -o test1   TEST/test1.dats
>>>>>> /run/current-system/sw/bin/time ./test1
>>>>>> 1077871
>>>>>> 2.11user 0.03system 0:02.14elapsed 99%CPU (0avgtext+0avgdata
>>>>>> 203448maxresident)k
>>>>>> 0inputs+0outputs (0major+50589minor)pagefaults 0swaps
>>>>>> ```
>>>>>> ie, non-linear version (test1) is twice slower and using 2x memory of
>>>>>> test3 (which converts stream into stream_vt). But still, haskell version 
>>>>>> is
>>>>>> faster and using less memory :)
>>>>>>
>>>>>> вс, 10 июл. 2022 г. в 02:21, gmhwxi :
>>>>>>
>>>>>>> Here is a version I wrote in ATS3:
>>>>>>>
>>>>>>>
>>>>>>> https://github.com/githwxi/ATS-Xanadu/blob/master/xatslib/libcats/TEST/test02_isPrime.dats
>>>>>>>
>>>>>>> Currently, I can only compile the ATS3 code to JS. The generated JS
>>>>>>> code runs about 10 times slower
>>>>>>> than the C code generated from compiling a comparable ATS2
>>>>>>> implementation:
>>>>>>>
>>>>>>> |thePrimes2| = 1077871
>>>>>>>
>>>>>>> real0m23.060s
>>>>>>> user   0m23.380s
>>>>>>> sys 0m0.188s
>>>>>>> On Saturday, July 9, 2022 at 5:33:43 PM UTC-4 gmhwxi wrote:
>>>>>>>
>>>>>>>> I took a look. Your ATS code looks very fine to me.
>>>>>>>>
>>>>>>>> I did some profiling on my own. In my trials, your ATS code is
>>>>>>>> actually a lot faster than
>>>>>>>> the Haskell code you posted. Note that my ghc version is very old:
>>>>>>>> GHC 7.10.3
>>>>>>>>
>>>>>>>> ## ATS ##
>>>>>>>>
>>>>>>>> (* Your code using non-linear stream *)
>>>>>>>> hwxi@hongwei-t440p:/tmp$ patscc -O2 -o primes -DATS_MEMALLOC_LIBC
>>>>>>>> primes.d

Re: Non-consuming linear stream

2022-07-11 Thread Hongwei Xi
>>>> 7.10.3
>>>>>
>>>>> ## ATS ##
>>>>>
>>>>> (* Your code using non-linear stream *)
>>>>> hwxi@hongwei-t440p:/tmp$ patscc -O2 -o primes -DATS_MEMALLOC_LIBC
>>>>> primes.dats
>>>>> hwxi@hongwei-t440p:/tmp$ time ./primes
>>>>> 1077871
>>>>>
>>>>> real0m3.118s
>>>>> user0m3.064s
>>>>> sys 0m0.048s
>>>>>
>>>>> ## Haskell ##
>>>>> (* Your haskell version *)
>>>>> (*
>>>>> Glasgow Haskell Compiler, Version 7.10.3, stage 2 booted by GHC
>>>>> version 7.10.3
>>>>> *)
>>>>>
>>>>> hwxi@hongwei-t440p:/tmp$ ghc -O2 primes.hs
>>>>> Linking primes ...
>>>>> hwxi@hongwei-t440p:/tmp$ time ./primes
>>>>> 1077871
>>>>>
>>>>> real0m8.195s
>>>>> user0m8.152s
>>>>> sys 0m0.040s
>>>>>
>>>>> 
>>>>>
>>>>> ## ATS ##
>>>>> (*My version using linear stream that is based on yours*)
>>>>>
>>>>> hwxi@hongwei-t440p:/tmp$ patscc -O2 -o primes2 -DATS_MEMALLOC_LIBC
>>>>> primes2.dats
>>>>> hwxi@hongwei-t440p:/tmp$ time ./primes2
>>>>> 1077871
>>>>>
>>>>> real0m2.120s
>>>>> user0m2.092s
>>>>> sys 0m0.000s
>>>>>
>>>>> On Saturday, July 9, 2022 at 12:50:11 PM UTC-4 ice.r...@gmail.com
>>>>> wrote:
>>>>>
>>>>>> My initial motivation was this Haskell source code:
>>>>>> https://github.com/dambaev/mobt2/blob/master/haskell/app/Main.hs
>>>>>> which is using lazy list (of course) and recursive binding and I decided 
>>>>>> to
>>>>>> check if it will be possible to get something similar
>>>>>>
>>>>>> ATS version using non-linear stream is here:
>>>>>> https://github.com/dambaev/mobt2/blob/master/ats2/src/TEST/test1.dats
>>>>>> , but it takes to much memory as `stream_take_while` duplicates data, as 
>>>>>> I
>>>>>> have got, that datatype constructor can't be unfolded with `@stream_cons`
>>>>>> pattern match
>>>>>>
>>>>>> There is another version, that generates primes with non-linear
>>>>>> stream and then, converting it to linear stream
>>>>>> https://github.com/dambaev/mobt2/blob/master/ats2/src/TEST/test3.dats
>>>>>> . This is the closest version to haskell's one. but still is using more
>>>>>> space and as twice as slow as Haskell, so I had started to think of how 
>>>>>> to
>>>>>> eliminate intermediate data structure.
>>>>>>
>>>>>> So, not a production issue, hehe, just found an interesting topic to
>>>>>> dig in :)
>>>>>>
>>>>>> сб, 9 июл. 2022 г. в 11:11, Hongwei Xi :
>>>>>>
>>>>>>> By looking at your first version, my simple answer is that a linear
>>>>>>> stream cannot be used
>>>>>>> in this way. The second version is possible but I am not sure what
>>>>>>> you wanted to do exactly.
>>>>>>> If you show me how to use a non-linear stream to do it, then I could
>>>>>>> probably say more.
>>>>>>>
>>>>>>> On Sat, Jul 9, 2022 at 5:26 AM Dambaev Alexander 
>>>>>>> wrote:
>>>>>>>
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> I had tried to implement function of type:
>>>>>>>>
>>>>>>>> ```
>>>>>>>> fun
>>>>>>>>   {a:t0p}
>>>>>>>>   isPrime
>>>>>>>>   ( xs: !stream_vt( int)
>>>>>>>>   , x: int
>>>>>>>>   ):
>>>>>>>>   bool
>>>>>>>> ```
>>>>>>>>
>>>>>>>> Ie, I want to force evaluation of some portion of a stream, but I
>>>>>>>> need to preserve it for a later use.
>>>>>>>>
>>>>>>>> I had tried to make a simil

Re: Non-consuming linear stream

2022-07-09 Thread Hongwei Xi
By looking at your first version, my simple answer is that a linear stream
cannot be used
in this way. The second version is possible but I am not sure what you
wanted to do exactly.
If you show me how to use a non-linear stream to do it, then I could
probably say more.

On Sat, Jul 9, 2022 at 5:26 AM Dambaev Alexander 
wrote:

> Hi,
>
> I had tried to implement function of type:
>
> ```
> fun
>   {a:t0p}
>   isPrime
>   ( xs: !stream_vt( int)
>   , x: int
>   ):
>   bool
> ```
>
> Ie, I want to force evaluation of some portion of a stream, but I need to
> preserve it for a later use.
>
> I had tried to make a similar version:
> ```
> fun
>   {a:t0p}
>   isPrime
>   ( xs: stream_vt( int)
>   , x: int
>   ):
>   ( stream_vt( int), bool)
> ```
>
> but failed as well, so I decided to ask for a direction if someone had
> tried to do similar stuff
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CAHjn2KwFq7JH%2BiZE7bWCJ_L7oZ38K-kmGBFii7DZsdxWLDsGmg%40mail.gmail.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLqp62MaoG8hugJ8h2mUt%2BsSAJ2eu6uRuJ%3D5nMOc4EbcfQ%40mail.gmail.com.


Re: design question

2022-02-08 Thread Hongwei Xi
Currently, my practice is just declare something like:

abstype myenum = int

or

abstype myenum(i:int) = int

Then implement 'myenum' somewhere in a file. It can clearly be done, but it
is really tedious,
involving a lot of boilerplate type of code. I suppose some kind of
meta-programming can be
supported so as to reduce/eliminate this kind of coding.


On Tue, Feb 8, 2022 at 6:47 PM Raoul Duke  wrote:

> hi, a scenario
>
> enum of n values.
> api function that takes the enum.
> but throws error for some subset of enum values.
>
> how could we statically be told, enforce do not call the api fn in those
> cases?
>
> besides "rtfm".
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CAJ7XQb7erubNjQotU8ap_J4_4Eaks%2B%3DDabqyZU6jeRnGMYGf7w%40mail.gmail.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLoX0O-RraTymYT6JEJNzEmwRhQbJuUdEKT54tJrkCT8-A%40mail.gmail.com.


Re: Help with Templates, cannot find missing implementation somewhere...

2021-12-30 Thread Hongwei Xi
Where can I find your source code so that I can produce the error you are
referring to?

--Hongwei


On Thu, Dec 30, 2021 at 12:47 PM d4v3y_5c0n3s  wrote:

> Ok, so I've been able to get the "dict" type to be abstract, but I can't
> seem to get "bucket" to be abstract.  I tried adding the "= ptr" part you
> suggested, but I'm not having any luck.  Using your solution, the code will
> compile, unless I test the "dict" type by calling "dict_new" &
> "dict_delete."  Looking at the error messages, the problem appears to be
> related to the "dict_delete" call, and I've provided the error below so you
> can see for yourself.  I know that there are a lot of details missing, so
> let me know if you'd like me to provide any more details.
>
> Error message:
> In file included from dict_dats.c:15:
> dict_dats.c: In function ‘loop_95__95__1’:
> dict_dats.c:6190:28: error: ‘PMVtmpltcstmat’ undeclared (first use in this
> function)
>  6190 | ATSINSmove_void(tmp195__1,
> PMVtmpltcstmat[0](array_uninitize$clear S2Eapp(S2Ecst(g0int_t0ype); S2Eextkind(atstype_int)))>)(arg2,
> ATSPMVrefarg1(arg0))) ;
>   |^~
> /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:284:39:
> note: in definition of macro ‘ATSINSmove_void’
>   284 | #define ATSINSmove_void(tmp, command) command
>   |   ^~~
> dict_dats.c:6190:28: note: each undeclared identifier is reported only
> once for each function it appears in
>  6190 | ATSINSmove_void(tmp195__1,
> PMVtmpltcstmat[0](array_uninitize$clear S2Eapp(S2Ecst(g0int_t0ype); S2Eextkind(atstype_int)))>)(arg2,
> ATSPMVrefarg1(arg0))) ;
>   |^~
> /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:284:39:
> note: in definition of macro ‘ATSINSmove_void’
>   284 | #define ATSINSmove_void(tmp, command) command
>   |   ^~~
> dict_dats.c:6190:46: error: ‘array_uninitize$clear’ undeclared (first use
> in this function)
>  6190 | ATSINSmove_void(tmp195__1,
> PMVtmpltcstmat[0](array_uninitize$clear S2Eapp(S2Ecst(g0int_t0ype); S2Eextkind(atstype_int)))>)(arg2,
> ATSPMVrefarg1(arg0))) ;
>   |  ^
> /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:284:39:
> note: in definition of macro ‘ATSINSmove_void’
>   284 | #define ATSINSmove_void(tmp, command) command
>   |   ^~~
> dict_dats.c:6190:68: warning: implicit declaration of function ‘S2Eapp’
> [-Wimplicit-function-declaration]
>  6190 | ATSINSmove_void(tmp195__1,
> PMVtmpltcstmat[0](array_uninitize$clear S2Eapp(S2Ecst(g0int_t0ype); S2Eextkind(atstype_int)))>)(arg2,
> ATSPMVrefarg1(arg0))) ;
>   |
>  ^~
> /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:284:39:
> note: in definition of macro ‘ATSINSmove_void’
>   284 | #define ATSINSmove_void(tmp, command) command
>   |   ^~~
> dict_dats.c:6190:75: warning: implicit declaration of function ‘S2Ecst’
> [-Wimplicit-function-declaration]
>  6190 | ATSINSmove_void(tmp195__1,
> PMVtmpltcstmat[0](array_uninitize$clear S2Eapp(S2Ecst(g0int_t0ype); S2Eextkind(atstype_int)))>)(arg2,
> ATSPMVrefarg1(arg0))) ;
>   |
> ^~
> /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:284:39:
> note: in definition of macro ‘ATSINSmove_void’
>   284 | #define ATSINSmove_void(tmp, command) command
>   |   ^~~
> dict_dats.c:6190:82: error: ‘BUCKET’ undeclared (first use in this
> function)
>  6190 | ATSINSmove_void(tmp195__1,
> PMVtmpltcstmat[0](array_uninitize$clear S2Eapp(S2Ecst(g0int_t0ype); S2Eextkind(atstype_int)))>)(arg2,
> ATSPMVrefarg1(arg0))) ;
>   |
>^~
> /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:284:39:
> note: in definition of macro ‘ATSINSmove_void’
>   284 | #define ATSINSmove_void(tmp, command) command
>   |   ^~~
> dict_dats.c:6190:89: error: expected ‘)’ before ‘;’ token
>  6190 | move_void(tmp195__1,
> PMVtmpltcstmat[0](array_uninitize$clear S2Eapp(S2Ecst(g0int_t0ype); S2Eextkind(atstype_int)))>)(arg2,
> ATSPMVrefarg1(arg0))) ;
>   |
>  ~  ^
>
> /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:284:39:
> note: in definition of macro ‘ATSINSmove_void’
>   284 | #define ATSINSmove_void(tmp, command) command
>   |   ^~~
> dict_dats.c:6190:145: error: expected expression before ‘)’ token
>  6190 | lear S2Eextkind(atstype_int)))>)(arg2, ATSPMVrefarg1(arg0))) ;
>   |
> ^
>
> /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:284:39:
> note: in definition of macro ‘ATSINSmove_void’
>   284 | #define ATSINSmove_void(tmp, 

Re: How to define linear abstract types based on records

2021-12-10 Thread Hongwei Xi
I could not produce the error by using the code snippet you provided.

The error message in your code is likely due to the conflict between
nominal type equality
(in C) and structural type equality (in ATS); postiats_tyrec_7 and
postiats_tyrec_15 are nominally
different in C but they should be based on two types in ATS that are
structurally equal.

I may be able to suggest something if I could produce the error on my side.

--Hongwei


On Fri, Dec 10, 2021 at 8:58 PM d4v3y_5c0n3s  wrote:

> So, I've got the following defined in my ".sats" file:
> absvt@ype mesh = @{v=int, t=int}
>
> In my ".dats" file, I've defined the following:
> assume mesh =
> [v,t:nat | v == t*3]
> @{
>   v=int v, t=int t
> }
> in
> implement mesh_new (  ) = let
> in
>   @{
> v=3, t=1
>   }:mesh
> end
>
>   Where "mesh_new()" is simply a function that returns a new "mesh"
> value.  The code I'm showing is a simplified version of my code that still
> exhibits the issue I was encountering (my original version had arrays,
> hence it being linear.)
>   I've been getting the following cryptic error message when compiling my
> code:
> !patscc -c g_engine.dats
> g_engine_dats.c:47259:1: error: conflicting types for ‘str_043__045_’;
> have ‘postiats_tyrec_15()’
> 47259 | str_043__045_()
>   | ^
> g_engine_dats.c:25134:1: note: previous definition of ‘str_043__045_’ with
> type ‘postiats_tyrec_7(atstype_float,  atstype_float,  atstype_float,
>  atstype_float,  atstype_float,  atstype_float,  atstype_float,
>  atstype_float,  atstype_float,  atstype_float,  atstype_float,
>  atstype_float,  atstype_float,  atstype_float,  atstype_float,
>  atstype_float)’ {aka ‘postiats_tyrec_7(float,  float,  float,  float,
>  float,  float,  float,  float,  float,  float,  float,  float,  float,
>  float,  float,  float)’}
> 25134 | str_043__045_(atstkind_t0ype(atstype_float) arg0,
> atstkind_t0ype(atstype_float) arg1, atstkind_t0ype(atstype_float) arg2,
> atstkind_t0ype(atstype_float) arg3, atstkind_t0ype(atstype_float) arg4,
> atstkind_t0ype(atstype_float) arg5, atstkind_t0ype(atstype_float) arg6,
> atstkind_t0ype(atstype_float) arg7, atstkind_t0ype(atstype_float) arg8,
> atstkind_t0ype(atstype_float) arg9, atstkind_t0ype(atstype_float) arg10,
> atstkind_t0ype(atstype_float) arg11, atstkind_t0ype(atstype_float) arg12,
> atstkind_t0ype(atstype_float) arg13, atstkind_t0ype(atstype_float) arg14,
> atstkind_t0ype(atstype_float) arg15)
>   | ^
> !
> My question is, what am I doing wrong?  Additionally, if you have any
> suggestions for where to look for an answer, that would also be welcomed.
> Also, feel free to request more details, since this is a simplified version
> of my code and I may have accidentally omitted an important detail.  I
> appreciate any and all help that can be provided.
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/5156ff12-80f4-4ce0-af53-9ecf04584964n%40googlegroups.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLp%2BV_LZucJweMp-UP-wHebNGKG-OJ%2BSDcu4DEdjL6No%3Dg%40mail.gmail.com.


Re: Help with Templates, cannot find missing implementation somewhere...

2021-11-30 Thread Hongwei Xi
I don't quite understand.
Templates in ATS2 are supposed to be working with abstract types.

If I could try precisely what you did on your machine, then I may be able
to suggest something.



On Tue, Nov 30, 2021 at 8:27 PM d4v3y_5c0n3s  wrote:

> Update 2:
> After investigating the prelude, I've determined that templates in ATS2
> just conflict with abstract types in some instances.  For this reason, it
> seems that in many parts of the prelude avoided the use of the "assume"
> keyword with template-heavy code.
>
> On Tuesday, November 30, 2021 at 7:08:48 PM UTC-5 d4v3y_5c0n3s wrote:
>
>> Update:
>> I was able to get the code I provided above running by staloading the
>> dict.dats file from the dict_test.dats file using " staload _ =
>> "./dict.dats" ".  Now, my only problem is that if I make the "dict" &
>> bucket types abstract, the templates stop working.
>>
>> On Tuesday, November 30, 2021 at 1:39:39 PM UTC-5 d4v3y_5c0n3s wrote:
>>
>>> You are right, including " share/atspre_staload.hats" causes the code to
>>> compile.  However, I'm still having issues.  You see, the code I provided I
>>> had taken from a static (.sats) and dynamic (.dats) file in order to make
>>> it more presentable when asking for help.  Your fix only fixes the issue in
>>> the single-file version, and when including the external static file it
>>> doesn't work.  Do you know what might be going wrong?  I'll provide the
>>> (simplified) contents of each of these files below.
>>>
>>> *dict.sats*:
>>> #include "share/atspre_staload.hats"
>>>
>>>
>>> datavtype BUCKET (a:vt@ype) =
>>> | bucket_empty of ()
>>> | bucket_filled of (Strptr1, a, BUCKET(a))
>>>
>>> vtypedef bucket(a:vt@ype) = BUCKET(a)
>>>
>>> fn{a:vt@ype} bucket_item$delete ( x: a ): void
>>>
>>> fun{a:vt@ype} bucket_delete_recursive ( b: bucket(a) ) : void
>>>
>>> sortdef dsz = {s:int | s > 0}
>>>
>>> vtypedef dict(a:vt@ype, n:int) =
>>> @{
>>> size=int n,
>>> buckets=arrayptr(bucket(a), n)
>>> }
>>>
>>> fn{a:vt@ype} dict_new {s:dsz} ( int s ) : dict(a, s)
>>> fn{a:t@ype} dict_delete {s:dsz} ( d: dict(a, s) ) : void
>>> fn{a:vt@ype} dict_delete_lin {s:dsz} ( d: dict(a, s) ) : void
>>>
>>>
>>> *dict.dats*:
>>> #include "share/atspre_staload.hats"
>>>
>>> staload "./dict.sats"
>>>
>>> local
>>> in
>>>
>>>
>>> implement{a} dict_new {s} ( size ) = let
>>> val size_st = size_of_int(size)
>>> val bucket_arr = arrayptr_make_uninitized(size_st)
>>> implmnt array_initize$init (i, x) = x := bucket_empty()
>>> val () = arrayptr_initize(bucket_arr, size_st)
>>> in
>>> @{size=size, buckets=bucket_arr}:dict(a, s)
>>> end
>>>
>>> implmnt{a} dict_delete ( d ) = let
>>>   implmnt(a2:t@ype) bucket_item$delete ( x ) = ()
>>> in
>>>   dict_delete_lin(d)
>>> end
>>>
>>> implmnt{a} bucket_delete_recursive ( b ) =
>>> case+ b of
>>> | ~bucket_empty() => ()
>>> | ~bucket_filled(str, x, next_bucket) => let
>>> val () = strptr_free(str)
>>> val () = bucket_item$delete(x)
>>> in
>>> bucket_delete_recursive(next_bucket)
>>> end
>>>
>>> implmnt{a} dict_delete_lin ( d ) = let
>>>   implmnt array_uninitize$clear (i, x) =
>>> bucket_delete_recursive(x)
>>> in
>>>   arrayptr_freelin(d.buckets, size_of_int(d.size))
>>> end
>>> end
>>>
>>> *dict_test.dats*, where main is:
>>> #include "share/atspre_staload.hats"
>>>
>>> staload "./dict.sats"
>>>
>>>
>>> implmnt main0 () = let
>>>   var d = dict_new(13)
>>> in
>>>   dict_delete(d)
>>> end
>>>
>>> *My output*:
>>> $ patscc --gline -DATS_MEMALLOC_LIBC dict_test.dats
>>>
>>> In file included from dict_test_dats.c:15:
>>> /home/tmj90/Goldelish-Engine/source/data/dict_test.dats: In function
>>> ‘mainats_0_void’:
>>> /home/tmj90/Goldelish-Engine/source/data/dict_test.dats:58:21: error:
>>> ‘PMVtmpltcstmat’ undeclared (first use in this function)
>>>58 |   var d = dict_new(13)
>>>   | ^~~
>>>
>>> /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:276:37:
>>> note: in definition of macro ‘ATSINSmove’
>>>   276 | #define ATSINSmove(tmp, val) (tmp = val)
>>>   | ^~~
>>> /home/tmj90/Goldelish-Engine/source/data/dict_test.dats:58:21: note:
>>> each undeclared identifier is reported only once for each function it
>>> appears in
>>>58 |   var d = dict_new(13)
>>>   | ^~~
>>>
>>> /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:276:37:
>>> note: in definition of macro ‘ATSINSmove’
>>>   276 | #define ATSINSmove(tmp, val) (tmp = val)
>>>   | ^~~
>>> /home/tmj90/Goldelish-Engine/source/data/dict_test.dats:58:39: error:
>>> ‘dict_new’ undeclared (first use in this function)
>>>58 |   var d = dict_new(13)
>>>
>>>   |   ^
>>> /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:276:37:
>>> note: in definition of macro ‘ATSINSmove’
>>>   276 | #define 

Re: Help with Templates, cannot find missing implementation somewhere...

2021-11-30 Thread Hongwei Xi
I tried your code and it compiled without any issue.

Did you have the following line at the top:

#include "share/atspre_staload.hats"

The error messages you showed indicate that many template implementations
were not
available to the compiler (patsopt).

--Hongwei


On Tue, Nov 30, 2021 at 10:52 AM d4v3y_5c0n3s  wrote:

> Okay, so I've been struggling with my use of templates for a while
> now, and I'm making this post to get some more eyes on the issue.  I've
> been getting really frustrated, because nothing I've tried seems to work,
> and I have no way to understand what is going wrong whatsoever besides
> becoming familiar with compiler internals (which could take who knows how
> long to learn.)
>
> Here's my code:
> datavtype BUCKET (a:vt@ype) =
> | bucket_empty of ()
> | bucket_filled of (Strptr1, a, BUCKET(a))
>
> vtypedef bucket(a:vt@ype) = BUCKET(a)
>
> sortdef dsz = {s:int | s > 0}
>
> vtypedef dict(a:vt@ype, n:int) =
> @{
> size=int n,
> buckets=arrayptr(bucket(a), n)
> }
>
> extern fn{a:vt@ype} dict_new {s:dsz} ( int s ) : dict(a, s)
> extern fn{a:t@ype} dict_delete {s:dsz} ( d: dict(a, s) ) : void
> extern fn{a:vt@ype} dict_delete_lin {s:dsz} ( d: dict(a, s) ) : void
>
> extern fun{a:vt@ype} bucket_delete_recursive ( b: bucket(a) ) : void
> extern fn{a:vt@ype} bucket_item$delete ( x: a ): void
>
> implement{a} dict_new {s} ( size ) = let
> val size_st = size_of_int(size)
> val bucket_arr = arrayptr_make_uninitized(size_st)
> implmnt array_initize$init (i, x) = x := bucket_empty()
> val () = arrayptr_initize(bucket_arr, size_st)
> in
> @{size=size, buckets=bucket_arr}:dict(a, s)
> end
>
> implmnt{a} dict_delete ( d ) = let
>   implmnt(a2:t@ype) bucket_item$delete ( x ) = ()
> in
>   dict_delete_lin(d)
> end
>
> implmnt{a} bucket_delete_recursive ( b ) =
> case+ b of
> | ~bucket_empty() => ()
> | ~bucket_filled(str, x, next_bucket) => let
> val () = strptr_free(str)
> val () = bucket_item$delete(x)
> in
> bucket_delete_recursive(next_bucket)
> end
>
> implmnt{a} dict_delete_lin ( d ) = let
>   implmnt array_uninitize$clear (i, x) =
> bucket_delete_recursive(x)
> in
>   arrayptr_freelin(d.buckets, size_of_int(d.size))
> end
>
> implmnt main0 () = let
>   var d = dict_new(13)
> in
>   dict_delete(d)
> end
>
>
> Here's the output:
> $ patscc --gline dict_test.dats
> In file included from dict_test_dats.c:15:
> /home/tmj90/Goldelish-Engine/source/data/dict_test.dats: In function
> ‘_057_home_057_tmj90_057_Goldelish_055_Engine_057_source_057_data_057_dict_test_056_dats__dict_new__0__1’:
> /home/tmj90/Goldelish-Engine/source/data/dict_test.dats:24:21: error:
> ‘PMVtmpltcstmat’ undeclared (first use in this function)
>24 | val bucket_arr = arrayptr_make_uninitized(size_st)
>   | ^~
> /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:276:37:
> note: in definition of macro ‘ATSINSmove’
>   276 | #define ATSINSmove(tmp, val) (tmp = val)
>   | ^~~
> /home/tmj90/Goldelish-Engine/source/data/dict_test.dats:24:21: note: each
> undeclared identifier is reported only once for each function it appears in
>24 | val bucket_arr = arrayptr_make_uninitized(size_st)
>   | ^~
> /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:276:37:
> note: in definition of macro ‘ATSINSmove’
>   276 | #define ATSINSmove(tmp, val) (tmp = val)
>   | ^~~
> /home/tmj90/Goldelish-Engine/source/data/dict_test.dats:24:39: error:
> ‘arrayptr_make_uninitized’ undeclared (first use in this function)
>24 | val bucket_arr = arrayptr_make_uninitized(size_st)
>   |   ^~~~
> /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:276:37:
> note: in definition of macro ‘ATSINSmove’
>   276 | #define ATSINSmove(tmp, val) (tmp = val)
>   | ^~~
> /home/tmj90/Goldelish-Engine/source/data/dict_test.dats:24:64: warning:
> implicit declaration of function ‘S2Eapp’ [-Wimplicit-function-declaration]
>24 | val bucket_arr = arrayptr_make_uninitized(size_st)
>   |
> ^~
> /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:276:37:
> note: in definition of macro ‘ATSINSmove’
>   276 | #define ATSINSmove(tmp, val) (tmp = val)
>   | ^~~
> /home/tmj90/Goldelish-Engine/source/data/dict_test.dats:24:71: warning:
> implicit declaration of function ‘S2Ecst’ [-Wimplicit-function-declaration]
>24 | val bucket_arr = arrayptr_make_uninitized(size_st)
>
> |
> ^
> /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:276:37:
> note: in definition of macro ‘ATSINSmove’
>   276 | #define ATSINSmove(tmp, val) (tmp = val)
>   | ^~~
> 

Re: Template Issue

2021-11-29 Thread Hongwei Xi
If you try to compile to JS, then you cannot have 'main0' in your code.
For instance, the following code worked when I tried:







*datavtype maybe(a:vt@ype) =| NAH of ()| YAH of (a)fn{a:vt@ype} maybe_nah
() : maybe(a) = NAH()fn{a:vt@ype} maybe_yah ( x: a ) : maybe(a) = YAH(x)*







*val () = letvar m1 = maybe_nah()var m2 = maybe_yah(6)
val-~NAH() = m1val-~YAH(int) = m2inend*

On Mon, Nov 29, 2021 at 11:03 AM d4v3y_5c0n3s  wrote:

> You need to select the "Patsopt2js" button when using Try-ATS-on-line to
> get the error I posted.  I'll test using my local ATS installation to
> determine whether this is only on the JS version of ATS or not.
> On Monday, November 29, 2021 at 10:23:56 AM UTC-5 gmhwxi wrote:
>
>> Is there a way for me to generate the error you are referring to?
>> The above code works fine on my end.
>>
>> --Hongwei
>>
>>
>> On Mon, Nov 29, 2021 at 10:16 AM d4v3y_5c0n3s  wrote:
>>
>>> I think I've been able to break down a problem I've been having with
>>> ATS' templates into a simple example provided below.  The following code
>>> type-checks, and can easily tested using Try-ATS-on-line.
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> *datavtype maybe(a:vt@ype) =| NAH of ()| YAH of (a)fn{a:vt@ype}
>>> maybe_nah () : maybe(a) = NAH()fn{a:vt@ype} maybe_yah ( x: a ) : maybe(a) =
>>> YAH(x)implement main0 () = letvar m1 = maybe_nah()var m2 =
>>> maybe_yah(6)val-~NAH() = m1val-~YAH(int) = m2inend*
>>>
>>> Running the above sample produces the following error:
>>> ParsingErrors:
>>> /tmp/patsopt_ccats_Ht1nNp: 9732(line=454, offs=1) -- 9735(line=454,
>>> offs=4): error(parsing): the keyword [EOF] is needed.
>>> exit(ATS): uncaught exception at run-time:
>>>
>>> /var/lib/openshift/5419477be0b8cddd09000122/app-root/runtime/repo/ats2-lang/contrib/CATS-parsemit/SATS/catsparse.sats:FatalErrorExn(1024)
>>>
>>> My question is, why is this simple example failing, and how should I fix
>>> it?  I know the problem is related to metaprogramming in some way, but I
>>> don't understand the low-level details enough to get why this isn't
>>> working.  Please let me know if you have any further questions.
>>>
>>> --
>>> 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.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/ats-lang-users/4794ec8f-4b17-4d45-9ffe-60d963756e30n%40googlegroups.com
>>> 
>>> .
>>>
>> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/d58686a2-e910-4ab4-bfe3-e33fd1bc312dn%40googlegroups.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLpRoz_wLBqkMR0Q9CAuCwk4EPHFbPPxFK4R6uQEBZn8-w%40mail.gmail.com.


Re: Template Issue

2021-11-29 Thread Hongwei Xi
You need the flag '-DATS_MEMALLOC_LIBC'.


On Mon, Nov 29, 2021 at 12:00 PM d4v3y_5c0n3s  wrote:

> I tried to compile the above snippet on my local machine, and got the
> following error:
> /usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld:
> /tmp/ccVVVRVe.o:metap_test_dat:(.text+0x12a): undefined reference to
> `atsruntime_mfree_undef'
> /usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld:
> /tmp/ccVVVRVe.o:metap_test_dat:(.text+0x160): undefined reference to
> `atsruntime_malloc_undef'
> collect2: error: ld returned 1 exit status
>
> I have no idea what it means or what caused it.
>
> On Monday, November 29, 2021 at 11:03:29 AM UTC-5 d4v3y_5c0n3s wrote:
>
>> You need to select the "Patsopt2js" button when using Try-ATS-on-line to
>> get the error I posted.  I'll test using my local ATS installation to
>> determine whether this is only on the JS version of ATS or not.
>> On Monday, November 29, 2021 at 10:23:56 AM UTC-5 gmhwxi wrote:
>>
>>> Is there a way for me to generate the error you are referring to?
>>> The above code works fine on my end.
>>>
>>> --Hongwei
>>>
>>>
>>> On Mon, Nov 29, 2021 at 10:16 AM d4v3y_5c0n3s  wrote:
>>>
 I think I've been able to break down a problem I've been having with
 ATS' templates into a simple example provided below.  The following code
 type-checks, and can easily tested using Try-ATS-on-line.














 *datavtype maybe(a:vt@ype) =| NAH of ()| YAH of (a)fn{a:vt@ype}
 maybe_nah () : maybe(a) = NAH()fn{a:vt@ype} maybe_yah ( x: a ) : maybe(a) =
 YAH(x)implement main0 () = letvar m1 = maybe_nah()var m2 =
 maybe_yah(6)val-~NAH() = m1val-~YAH(int) = m2inend*

 Running the above sample produces the following error:
 ParsingErrors:
 /tmp/patsopt_ccats_Ht1nNp: 9732(line=454, offs=1) -- 9735(line=454,
 offs=4): error(parsing): the keyword [EOF] is needed.
 exit(ATS): uncaught exception at run-time:

 /var/lib/openshift/5419477be0b8cddd09000122/app-root/runtime/repo/ats2-lang/contrib/CATS-parsemit/SATS/catsparse.sats:FatalErrorExn(1024)

 My question is, why is this simple example failing, and how should I
 fix it?  I know the problem is related to metaprogramming in some way, but
 I don't understand the low-level details enough to get why this isn't
 working.  Please let me know if you have any further questions.

 --
 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.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/ats-lang-users/4794ec8f-4b17-4d45-9ffe-60d963756e30n%40googlegroups.com
 
 .

>>> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/386c6ed6-d6f1-491d-ac67-d8b39a511439n%40googlegroups.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLqRyVQXM5SRLCyh6AapzeoPZ%2BxFetVBj2NiReyia2nzsw%40mail.gmail.com.


Re: Template Issue

2021-11-29 Thread Hongwei Xi
Is there a way for me to generate the error you are referring to?
The above code works fine on my end.

--Hongwei


On Mon, Nov 29, 2021 at 10:16 AM d4v3y_5c0n3s  wrote:

> I think I've been able to break down a problem I've been having with ATS'
> templates into a simple example provided below.  The following code
> type-checks, and can easily tested using Try-ATS-on-line.
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *datavtype maybe(a:vt@ype) =| NAH of ()| YAH of (a)fn{a:vt@ype} maybe_nah
> () : maybe(a) = NAH()fn{a:vt@ype} maybe_yah ( x: a ) : maybe(a) =
> YAH(x)implement main0 () = letvar m1 = maybe_nah()var m2 =
> maybe_yah(6)val-~NAH() = m1val-~YAH(int) = m2inend*
>
> Running the above sample produces the following error:
> ParsingErrors:
> /tmp/patsopt_ccats_Ht1nNp: 9732(line=454, offs=1) -- 9735(line=454,
> offs=4): error(parsing): the keyword [EOF] is needed.
> exit(ATS): uncaught exception at run-time:
>
> /var/lib/openshift/5419477be0b8cddd09000122/app-root/runtime/repo/ats2-lang/contrib/CATS-parsemit/SATS/catsparse.sats:FatalErrorExn(1024)
>
> My question is, why is this simple example failing, and how should I fix
> it?  I know the problem is related to metaprogramming in some way, but I
> don't understand the low-level details enough to get why this isn't
> working.  Please let me know if you have any further questions.
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/4794ec8f-4b17-4d45-9ffe-60d963756e30n%40googlegroups.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLrFc_YHC92-itPB5X%2B0o%2B3Qm4WHtPoOa2s3mMnmXYz1pQ%40mail.gmail.com.


Re: Trying to get a dependent type working in ATS

2021-06-30 Thread Hongwei Xi
First, tri_test(0) is just:

[un:int | 0 <= un; un+1 <= 0; un == 0; 0 == 0] int(un)

Clearly, no value can be given the above type as 0 <= un and un+1 <= 0
yields a contradiction.


On Wed, Jun 30, 2021 at 10:12 PM d4v3y_5c0n3s  wrote:

> So, I'm trying to get the following code to work:
> *typedef tri_test2(v:int) = [un:int | 0 <= un; un+1 <= v; un == 0; v == 0]
> int(un)*
> *val test2 = (0):tri_test2(0)*
> But I get the following error:
> */tmp/patsopt_tcats_TCES3d: 196(line=6, offs=14) -- 197(line=6, offs=15):
> error(3): unsolved constraint: C3NSTRprop(C3TKmain(); S2Eapp(S2Ecst(<=);
> S2Eapp(S2Ecst(+); S2EVar(0->S2Eintinf(0)), S2Eintinf(1)), S2Eintinf(0)))*
> *typechecking has failed: there are some unsolved constraints: please
> inspect the above reported error message(s) for information.*
> *exit(ATS): uncaught exception:
> _2home_2hwxi_2Research_2ATS_2dPostiats_2src_2pats_error_2esats__FatalErrorExn(1025)*
> I am clueless as to why I keep getting this error.  What is ATS having
> trouble understanding here?
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/3e48e488-e255-46d0-b6b7-3bab7fb538ban%40googlegroups.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLrM4pQ4CrVFgjs4M1m6PAiqJL_XOu%2BwyfY3T%2BNszWyReA%40mail.gmail.com.


Re: -Wincompatible-pointer-type for functions taking a pointer

2021-06-05 Thread Hongwei Xi
Yes, you can.

Please take a look at how 'charptr' is handled in the following simple
example:

https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAMPLE/MISC/mysendmailist.dats

On Sat, Jun 5, 2021 at 3:42 PM David Smith  wrote:

>
> Hey,
> I'm trying to use a C library (libwayland) from ATS (still), and now I
> finally got everything working, but I'm getting a few warnings related to
> function pointers.
>
> I got the following code
>
> typedef
> wl_registry_listener = $extype_struct "struct wl_registry_listener" of
>   {
> global= (ptr, !wl_registry1, uint32, string, uint32) -<1> void,
> global_remove= (ptr, !wl_registry1, uint32) -<1> void
>   }
>
> However it complains about incompatible pointer types, as ATS seems to use
> `void *` for the ptr, the registry and the string.
>
> Is there any way I can get rid of this warning or do I just have to live
> with it?
>
> Thanks in advance!
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/badd3f1d-9c67-4b90-962a-e1207e67c143n%40googlegroups.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLpD6rchn1xjm41_LZSrqPoffr29jt7%2B-CKjk7YwffBMZw%40mail.gmail.com.


Re: "Number is smaller than 0x8000, trust me"

2021-05-23 Thread Hongwei Xi
This kind of guarantee can always be established with a run-time check.

If you want to solve constraints involving 'lor', then you need to use an
external solver like Z3.
But it would require a lot of effort.

I would suggest using a run-time check for now. And you could always come
back to fix it later
if really needed.

On Sun, May 23, 2021 at 6:28 PM David Smith  wrote:

>
> Hey, I have a small convenience function that takes 3 5 bit bit numbers to
> produce a 15 bit color, that's guaranteed to be <0x8000.
>
> Now, apparently the typechecker doesn't know much about `lor`. Is there
> any way I could say "hey trust me, if these three numbers are < 0x20 then
> the result is < 0x8000"?
>
> Thanks in advance.
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/4f5589ed-b80d-4662-918c-ac1fa81d04c9n%40googlegroups.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLqwSYfL-jmkB4%2BiTrKWy2rZDWxwYzsZWb%2BecqqRTkhoyA%40mail.gmail.com.


Re: ATS templates vs. C++ templates

2021-05-21 Thread Hongwei Xi
implement(env_t) ifold_left<$BS.Bytestring1>( env, i, f) = ()

should probably be:

implement(env_t) ifold_left<$BS.Bytestring1>( env, i, f) = ()


On Fri, May 21, 2021 at 6:13 AM Dambaev Alexander 
wrote:

> are there any gotchas with partial specification?
>
> I have such template definition:
>
> 
> fn
>   {env:viewt0ype+}
>   {a:viewt0ype+}
>   {element:viewt0ype+}
>   ifold_left
>   {fe:eff}
>   ( env: !INV(env)
>   , i: !INV(a)
>   , f: (size_t, !INV(env),!INV(element))- bool
>   ):
>   void
> ```
> and this partial implementation:
> ```
> implement(env_t) ifold_left<$BS.Bytestring1>( env, i, f) =
>   ()
> ```
>
> but I have this error on the line of such implementation:
> ```
> /data/devel/ats2/text/src/DATS/text_templates.dats: 1966(line=75, offs=1)
> -- 2033(line=76, offs=6): error(2): the template is expected to be fully
> applied but it is not.
> ```
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "ats-lang-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ats-lang-users/nPH1DNJRkKI/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> ats-lang-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CAHjn2Kx6febCVhJ7fs5GT-nZW2tGOi0x97qdFrCb7GtdeV2zUA%40mail.gmail.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLp2RZ-2q%3DrQDCy9keW362pUeooGDFFGmnOjrNi1u-5H0g%40mail.gmail.com.


Re: Implementing refinement types

2021-05-11 Thread Hongwei Xi
You may want to check out some work by Joshua Dunfield on bidirectional
typechecking.

--Hongwei


On Tue, May 11, 2021 at 10:27 PM Elijah Stone  wrote:

> Not entirely topical, but--does anybody have resources on implementing
> refinement types?
>
> I found this dissertation https://www.cs.cmu.edu/~rwh/theses/davies.pdf,
> but nothing else.
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/cb86856e-fd7b-5e11-1a2d-dec9df07edf%40elronnd.net
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLrtH8sYR-O%3DLgR%2BndXf5XQSe9qOJdPUfOViddnCBGCikg%40mail.gmail.com.


Re: Having Trouble Finding a Constraint Which is Failing

2021-05-08 Thread Hongwei Xi
This is due to a missing type annotation for 'ifcase'
in your code:

val ret_fbc =
(
ifcase
| tr=0 =>
  (FBT_CONS(fbc.0) | fbc.1+1, fbc.2)
| tr=1 =>
  (FBT_CONS(fbc.0) | fbc.1, fbc.2+1)
| _ => (FBT_CONS(fbc.0) | fbc.1+1, fbc.2+1)
) : [f1,b1:nat] fb_count(a, f1, b1)

In general, if-exp, case-exp and ifcase-exp should all be given a type
annotation.


On Sat, May 8, 2021 at 9:39 AM d4v3y_5c0n3s  wrote:

> So, I'm having difficulty understanding a constraint that is failing
> in my code.  The constraint that is failing is "f1 + f1 = 1", which I am
> confused by, because there appears to be no such constraint in my code.
> *Here's what (most of) my code is:*
> dataprop FBT_IN (int, a:addr) =
> | FBT_NIL(0, a)
> | {n:nat} FBT_CONS(n+1, a) of FBT_IN(n, a)
>
> typedef fb_count (a:addr, f:int, b:int) = [c:nat | f >= 0; b >= 0]
> (FBT_IN(c, a) | int f, int b)
> typedef f_ind (a:addr, f:int, i:int) = int i
> typedef b_ind (a:addr, b:int, i:int) = int i
>
> fn tri_fb_test {c:nat}{l:addr}
> (
> pfin: FBT_IN(c, l) | t: ctri, dv: plane
> ): (FBT_IN(c+1, l) | intBtwe(0,2)) =
>   if ctri_inside_plane(t, dv) then (FBT_CONS(pfin) | 0)
>   else if ctri_outside_plane(t, dv) then (FBT_CONS(pfin) | 1)
>   else (FBT_CONS(pfin) | 2)
>
> fun loop1 {i,j:nat | i <= j}{a:addr}{f1,b1:nat}
> ( a: !arrayptr(ctri, a, j), dv: plane,
> fbc: fb_count(a, f1, b1),
> j: int j, i: int i ): [f2,b2:nat] fb_count(a, f2, b2) = (
>   if i < j then let
> val c: ctri = a[i]
> val (pf_tr | tr) = tri_fb_test(fbc.0 | c, dv)
> val ret_fbc = ifcase
>   | tr=0 => (FBT_CONS(fbc.0) | fbc.1+1, fbc.2)
>   | tr=1 => (FBT_CONS(fbc.0) | fbc.1, fbc.2+1)
>   | _ => (FBT_CONS(fbc.0) | fbc.1+1, fbc.2+1)
>   in
> loop1(a, dv, ret_fbc, j, i+1)  // <-- constraint fails on
> this line at "ret_fbc"
>   end else fbc
> *And here's the error produced:*
> $ patscc -tcats cmesh.dats
> /home/tmj90/Goldelish-Engine/source/assets/cmesh.dats: 8604(line=235,
> offs=26) -- 8611(line=235, offs=33): error(3): unsolved constraint:
> C3NSTRprop(C3TKmain(); S2Eeqeq(S2Evar(f1(8784));
> S2Eapp(S2Ecst(add_int_int); S2Evar(f1(8784)), S2Eintinf(1
> typechecking has failed: there are some unsolved constraints: please
> inspect the above reported error message(s) for information.
> exit(ATS): uncaught exception:
> _2tmp_2ATS_2dPostiats_2src_2pats_error_2esats__FatalErrorExn(1025)
>
> I suspect the issue is an implicitly generated constraint of some kind,
> but I have no idea where it's coming from.  *However*, I discovered that
> if I comment out these lines:
> val ret_fbc = ifcase
>   //| tr=0 => (FBT_CONS(fbc.0) | fbc.1+1, fbc.2)
>   //| tr=1 => (FBT_CONS(fbc.0) | fbc.1, fbc.2+1)
>   | _ => (FBT_CONS(fbc.0) | fbc.1+1, fbc.2+1)
> then everything typechecks.  That's the biggest hint I could find, but I
> don't know what going wrong.  Please let me know if you'd like me to
> provide more code, I just didn't want to clutter my initial post.
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/dcf7d7eb-d69f-4746-800b-24c02084ee65n%40googlegroups.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLoFTNS8YzzXBBk61d92neCEKfmGhF2QKQN%3DVaZkb6gWyw%40mail.gmail.com.


Fwd: ATS2 source make issue

2021-04-18 Thread Hongwei Xi
-- Forwarded message -
From: Phil Roc 
Date: Sun, Apr 18, 2021 at 10:50 AM
Subject: Re: ATS2 source make issue
To: ats-lang-users 


Hello,
I've ended up installing ATS2 using Homebrew (
https://formulae.brew.sh/formula/ats2-postiats), instead of compiling it
myself.
Case closed.

Le dimanche 18 avril 2021 à 09:32:45 UTC+2, Phil Roc a écrit :

> By the way, here's the compiler I'm using:
>
> Apple clang version 12.0.0 (clang-1200.0.32.29)
> Target: x86_64-apple-darwin20.2.0
> Thread model: posix
> InstalledDir:
> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
>
> Le dimanche 18 avril 2021 à 09:30:45 UTC+2, Phil Roc a écrit :
>
>> Hello,
>> on MacosX Big Sur,  when I "make"  the ATS2 code, I get the following
>> errors.
>>
>> Can anyone help, please?
>>
>> Many thanks.
>>
>> Phil
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> *gcc -I. -I./ccomp/runtime -c -o prelude_DATS_bool_dats.o
>> prelude/DATS_bool_dats.cprelude/ats_main_prelude_dats.c:72:1: error:
>> implicit declaration of function
>> 'ATS_2d0_2e2_2e12_2prelude_2DATS_2basics_2edats__dynload' is invalid in
>> C99
>> [-Werror,-Wimplicit-function-declaration]ATS_2d0_2e2_2e12_2prelude_2DATS_2basics_2edats__dynload
>> () ;^prelude/ats_main_prelude_dats.c:73:1: error: implicit declaration of
>> function 'ATS_2d0_2e2_2e12_2prelude_2DATS_2integer_2edats__dynload' is
>> invalid in C99
>> [-Werror,-Wimplicit-function-declaration]ATS_2d0_2e2_2e12_2prelude_2DATS_2integer_2edats__dynload
>> () ;^prelude/ats_main_prelude_dats.c:73:1: note: did you mean
>> 'ATS_2d0_2e2_2e12_2prelude_2DATS_2basics_2edats__dynload'?prelude/ats_main_prelude_dats.c:72:1:
>> note: 'ATS_2d0_2e2_2e12_2prelude_2DATS_2basics_2edats__dynload' declared
>> hereATS_2d0_2e2_2e12_2prelude_2DATS_2basics_2edats__dynload ()
>> ;^prelude/ats_main_prelude_dats.c:74:1: error: implicit declaration of
>> function 'ATS_2d0_2e2_2e12_2prelude_2DATS_2sizetype_2edats__dynload' is
>> invalid in C99
>> [-Werror,-Wimplicit-function-declaration]ATS_2d0_2e2_2e12_2prelude_2DATS_2sizetype_2edats__dynload
>> () ;^gcc -I. -I./ccomp/runtime -c -o prelude_DATS_char_dats.o
>> prelude/DATS_char_dats.cprelude/ats_main_prelude_dats.c:74:1: note: did you
>> mean
>> 'ATS_2d0_2e2_2e12_2prelude_2DATS_2integer_2edats__dynload'?prelude/ats_main_prelude_dats.c:73:1:
>> note: 'ATS_2d0_2e2_2e12_2prelude_2DATS_2integer_2edats__dynload' declared
>> hereATS_2d0_2e2_2e12_2prelude_2DATS_2integer_2edats__dynload ()
>> ;^prelude/ats_main_prelude_dats.c:75:1: error: implicit declaration of
>> function 'ATS_2d0_2e2_2e12_2prelude_2DATS_2pointer_2edats__dynload' is
>> invalid in C99
>> [-Werror,-Wimplicit-function-declaration]ATS_2d0_2e2_2e12_2prelude_2DATS_2pointer_2edats__dynload
>> () ;^gcc -I. -I./ccomp/runtime -c -o prelude_DATS_float_dats.o
>> prelude/DATS_float_dats.cgcc -I. -I./ccomp/runtime -c -o
>> prelude_DATS_integer_dats.o
>> prelude/DATS_integer_dats.cprelude/ats_main_prelude_dats.c:75:1: note: did
>> you mean
>> 'ATS_2d0_2e2_2e12_2prelude_2DATS_2integer_2edats__dynload'?prelude/ats_main_prelude_dats.c:73:1:
>> note: 'ATS_2d0_2e2_2e12_2prelude_2DATS_2integer_2edats__dynload' declared
>> hereATS_2d0_2e2_2e12_2prelude_2DATS_2integer_2edats__dynload ()
>> ;^prelude/ats_main_prelude_dats.c:76:1: error: implicit declaration of
>> function 'ATS_2d0_2e2_2e12_2prelude_2DATS_2bool_2edats__dynload' is invalid
>> in C99
>> [-Werror,-Wimplicit-function-declaration]ATS_2d0_2e2_2e12_2prelude_2DATS_2bool_2edats__dynload
>> () ;^prelude/ats_main_prelude_dats.c:76:1: note: did you mean
>> 'ATS_2d0_2e2_2e12_2prelude_2DATS_2basics_2edats__dynload'?prelude/ats_main_prelude_dats.c:72:1:
>> note: 'ATS_2d0_2e2_2e12_2prelude_2DATS_2basics_2edats__dynload' declared
>> hereATS_2d0_2e2_2e12_2prelude_2DATS_2basics_2edats__dynload ()
>> ;^prelude/ats_main_prelude_dats.c:77:1: error: implicit declaration of
>> function 'ATS_2d0_2e2_2e12_2prelude_2DATS_2char_2edats__dynload' is invalid
>> in C99
>> [-Werror,-Wimplicit-function-declaration]ATS_2d0_2e2_2e12_2prelude_2DATS_2char_2edats__dynload
>> () ;^prelude/ats_main_prelude_dats.c:77:1: note: did you mean
>> 'ATS_2d0_2e2_2e12_2prelude_2DATS_2bool_2edats__dynload'?prelude/ats_main_prelude_dats.c:76:1:
>> note: 'ATS_2d0_2e2_2e12_2prelude_2DATS_2bool_2edats__dynload' declared
>> hereATS_2d0_2e2_2e12_2prelude_2DATS_2bool_2edats__dynload ()
>> ;^prelude/ats_main_prelude_dats.c:78:1: error: implicit declaration of
>> function 'ATS_2d0_2e2_2e12_2prelude_2DATS_2float_2edats__dynload' is
>> invalid in C99
>> [-Werror,-Wimplicit-function-declaration]ATS_2d0_2e2_2e12_2prelude_2DATS_2float_2edats__dynload
>> () 

Fwd: ATS on iSh

2021-04-18 Thread Hongwei Xi
FYI.

-- Forwarded message -
From: Philippe de Rochambeau 
Date: Sun, Apr 18, 2021 at 1:18 AM
Subject: ATS on iSh
To: 


Hello,
for your information, the ATS source code compiles in iSh (https://ish.app/)
on an IPad Air 2.
I’ve tried compiling several computer languages on iSh, such as Raku, …,
but ATS is the first one I’ve managed to actually run. And it’s fast.
Furthermore, as far a I know, it’s the only functional programming
languages running on iOS in a x86 emulator. ReasonML is another one (
https://apps.apple.com/us/app/reasonml/id1507769834), but it converts code
to Javascript.
Best regards,
Philippe de Rochambeau

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLqeGcqHFvSFzLgi5a%3DLfzDUsMH7NspXUESogdZXM51fFQ%40mail.gmail.com.


Re: How to use view in vtypedef?

2021-04-06 Thread Hongwei Xi
I see.

It may help if the existential quantifier [l:addr] is moved
out of the record:

vtypedef
rib_cmd_info = [l:addr]
@{
rc_rt = (rtentry @ l | ptr l)
}

But programming using such a type is still quite burdensome.
I do have some designs for low-level programming in ATS3 but
right now my hands are tied with the very task of implementing ATS3.


On Wed, Apr 7, 2021 at 12:50 AM Kiwamu Okabe  wrote:

> On Tue, Apr 6, 2021 at 3:50 PM Hongwei Xi  wrote:
> > vtypedef rib_cmd_info = @{
> >   rc_rt = [l:addr] (rtentry @ l | ptr l)
> > }
> >
> > It seems that you are trying to do C-style programming in ATS directly.
> This would
> > be difficult; it may not even be practical for large scale programming.
>
> But... Another person tried to use the style:
>
> https://github.com/xlq/aos/blob/master/vga-text.dats#L37
>
> Best regards,
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CAEvX6d%3D6TJddME53Y%2BzjdAinb0DhZiyAmhDd4j7gZ8jeL%2BGGfw%40mail.gmail.com
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLqukzL6EzxgN2Zje7PR4hRAMTv9ANUrY_V08LAj7m21MA%40mail.gmail.com.


Re: How to use the datavtype for tagged union?

2021-04-06 Thread Hongwei Xi
Okay. I put some 'topize' functions in basic_dyn.dats.
Changes have been uploaded.

On Tue, Apr 6, 2021 at 3:44 AM Kiwamu Okabe  wrote:

> Dear Hongwei,
>
> On Tue, Apr 6, 2021 at 3:32 PM Hongwei Xi  wrote:
> > >>I feel the uninitize function is not safe...
> >
> > Such a function is always safe as initialized data can always
> > be treated as uninitialized.
>
> I understood.
> If so, could you include the `uninitize` praxi on ATS3 prelude library?
>
> I think this idiom is common for all of ATS programmer.
>
> Best regards,
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CAEvX6d%3DGG%2BiU8%2B_JiK%3D6zrC0WBQyRTM8BcD7FJQ5P0jFLGxaRA%40mail.gmail.com
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLoXZDkaSeX6z5XEhr6RCkPDXPXqJcq9%2BCJ6mnPOD8yyUA%40mail.gmail.com.


Re: How to use view in vtypedef?

2021-04-06 Thread Hongwei Xi
It is difficult to work as the following type as one cannot easily take out
the rc_rt
component:

vtypedef rib_cmd_info = @{
  rc_rt = [l:addr] (rtentry @ l | ptr l)
}

It seems that you are trying to do C-style programming in ATS directly.
This would
be difficult; it may not even be practical for large scale programming.


On Tue, Apr 6, 2021 at 2:11 AM Kiwamu Okabe  wrote:

> Dear all,
>
> I'm trying to write following code:
>
> ```ats
> #include "share/atspre_define.hats"
> #include "share/atspre_staload.hats"
>
> #define RTM_DELETE 0x2
> #define ENOTSUP 45
>
> typedef rtentry = @{
>   member_a = int
> }
>
> typedef nhop_object = @{
>   member_b = int
> }
>
> vtypedef rib_cmd_info = @{
>   rc_rt = [l:addr] (rtentry @ l | ptr l)
> }
>
> fun rtsock_routemsg
> {l1,l2:addr}
> (pfrt: !rtentry@l1, pfnh: !nhop_object@l2 | cmd: int, rt: ptr l1, nh:
> ptr l2, fibnum: int):
> int =
>   cmd + !rt.member_a + !nh.member_b
>
> fun rib_del_route
> {l:addr}
> (pf: !rib_cmd_info? >> rib_cmd_info @ l | rc: ptr l):
> int =
>   undefined()
>
> fun rib_action
> {l:addr}
> (pf: !rib_cmd_info? >> rib_cmd_info @ l | action: int, rc: ptr l):
> int =
>   case+ action of
> | RTM_DELETE => rib_del_route(pf | rc)
> | _ => ENOTSUP
>
> implement main0 () = {
>   var rc: rib_cmd_info
>   prval pfrc = view@rc
>   val error = rib_action(pfrc | RTM_DELETE, addr@rc)
>   prval () = view@rc := pfrc
> }
> ```
>
> But above code causes following error:
>
> ```
> $ patscc -D_GNU_SOURCE -DATS_MEMALLOC_LIBC main.dats -lpthread
>
> /home/kiwamu/src/metasepi-postmortem/PR/FreeBSD-kernel/253800/Resolution/ATS2/fix/main.dats:
> 694(line=36, offs=35) -- 696(line=36, offs=37): error(3): the function
> argument needs to be a left-va
> lue.
>
> /home/kiwamu/src/metasepi-postmortem/PR/FreeBSD-kernel/253800/Resolution/ATS2/fix/main.dats:
> 680(line=36, offs=21) -- 702(line=36, offs=43): error(3): the linear
> dynamic variable [pf$4748(-1)] i
> s preserved but with an incompatible type.
>
> /home/kiwamu/src/metasepi-postmortem/PR/FreeBSD-kernel/253800/Resolution/ATS2/fix/main.dats:
> 680(line=36, offs=21) -- 702(line=36, offs=43): error(3): mismatch of
> static terms (tyleq):
> The actual term is: S2Etyrec(flt0; npf=-1; rc_rt=S2Etop(knd=0;
> S2Eexi(l(8480); ; S2Etyrec(flt0; npf=1; 0=S2Eapp(S2Ecst(@);
> S2Ecst(rtentry), S2Evar(l(8480))), 1=S2Eapp(S2Ecst(ptr);
> S2Evar(l(8480)
> ))
> The needed term is: S2Eat(S2Etyrec(flt0; npf=-1;
> rc_rt=S2Eexi(l$8631(14298); ; S2Etyrec(flt0; npf=1;
> 0=S2Eapp(S2Ecst(@); S2Ecst(rtentry), S2Evar(l$8631(14298))),
> 1=S2Eapp(S2Ecst(ptr); S2Evar(l$8
> 631(14298)); S2Evar(l(8484)))
>
> /home/kiwamu/src/metasepi-postmortem/PR/FreeBSD-kernel/253800/Resolution/ATS2/fix/main.dats:
> 817(line=42, offs=26) -- 821(line=42, offs=30): error(3): the dynamic
> expression cannot be assigned t
> he type [S2Etyrec(flt0; npf=-1; rc_rt=S2Etop(knd=0; S2Eexi(l(8480); ;
> S2Etyrec(flt0; npf=1; 0=S2Eapp(S2Ecst(@); S2Ecst(rtentry),
> S2Evar(l(8480))), 1=S2Eapp(S2Ecst(ptr); S2Evar(l(8480)))].
>
> /home/kiwamu/src/metasepi-postmortem/PR/FreeBSD-kernel/253800/Resolution/ATS2/fix/main.dats:
> 817(line=42, offs=26) -- 821(line=42, offs=30): error(3): mismatch of
> static terms (tyleq):
> The actual term is: S2Eat(S2Etyrec(flt0; npf=-1; rc_rt=S2Etop(knd=0;
> S2Eexi(l(8480); ; S2Etyrec(flt0; npf=1; 0=S2Eapp(S2Ecst(@);
> S2Ecst(rtentry), S2Evar(l(8480))), 1=S2Eapp(S2Ecst(ptr); S2Evar(l
> (8480))); S2Evar(rc(8485)))
> The needed term is: S2Etyrec(flt0; npf=-1; rc_rt=S2Etop(knd=0;
> S2Eexi(l(8480); ; S2Etyrec(flt0; npf=1; 0=S2Eapp(S2Ecst(@);
> S2Ecst(rtentry), S2Evar(l(8480))), 1=S2Eapp(S2Ecst(ptr);
> S2Evar(l(8480)
> ))
>
> /home/kiwamu/src/metasepi-postmortem/PR/FreeBSD-kernel/253800/Resolution/ATS2/fix/main.dats:
> 744(line=39, offs=22) -- 875(line=44, offs=2): error(3): the linear
> dynamic variable [rc$view$5549(-1
> )] is preserved but with an incompatible type.
>
> /home/kiwamu/src/metasepi-postmortem/PR/FreeBSD-kernel/253800/Resolution/ATS2/fix/main.dats:
> 744(line=39, offs=22) -- 875(line=44, offs=2): error(3): mismatch of
> static terms (tyleq):
> The actual term is: S2Etyrec(flt0; npf=1; 0=S2Eapp(S2Ecst(@);
> S2Ecst(rtentry), S2Evar(l$8634$8635(14302))), 1=S2Eapp(S2Ecst(ptr);
> S2Evar(l$8634$8635(14302
> The needed term is: S2Ecst(ptr_type)
>
> /home/kiwamu/src/metasepi-postmortem/PR/FreeBSD-kernel/253800/Resolution/ATS2/fix/main.dats:
> 744(line=39, offs=22) -- 875(line=44, offs=2): error(3): mismatch of
> static terms (tyleq):
> The actual term is: S2Eexi(l$8634(14301); ; S2Etyrec(flt0; npf=1;
> 0=S2Eapp(S2Ecst(@); S2Ecst(rtentry), S2Evar(l$8634(14301))),
> 1=S2Eapp(S2Ecst(ptr); S2Evar(l$8634(14301)
> The needed term is: S2Ecst(ptr_type)
>
> /home/kiwamu/src/metasepi-postmortem/PR/FreeBSD-kernel/253800/Resolution/ATS2/fix/main.dats:
> 744(line=39, offs=22) -- 875(line=44, offs=2): error(3): mismatch of
> static terms (tyleq):
> The actual term is: S2Etyrec(flt0; npf=-1; rc_rt=S2Eexi(l$8634(14301);
> ; 

Re: How to use the datavtype for tagged union?

2021-04-06 Thread Hongwei Xi
>>I feel the uninitize function is not safe...

Such a function is always safe as initialized data can always
be treated as uninitialized.

On Tue, Apr 6, 2021 at 2:08 AM Kiwamu Okabe  wrote:

> Dear Hongwei,
>
> On Tue, Apr 6, 2021 at 3:00 PM Hongwei Xi  wrote:
> > It seems that you need to unintialize 'e' explicitly:
> > --snip--
> >   prval () = uninitize(e)
>
> Umm... We should take care to change uninitize it?
> The wg_input would like to take both:
>
> A. uninitized `e`
> B. initialized `e`
>
> I feel the uninitize function is not safe...
>
> Best regards,
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CAEvX6d%3DFmGs0x4HYEGU%2B2sGKf4cAW_Y_VhJCGwG%2Bb%3DDT4cL_xQ%40mail.gmail.com
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLpF6pAx9%3D3fej-dZ_uyD7W_172Y4QKB1ZaBxCmRAnfmSQ%40mail.gmail.com.


Re: How to use the datavtype for tagged union?

2021-04-06 Thread Hongwei Xi
It seems that you need to unintialize 'e' explicitly:

extern
praxi
uninitize
{a:t0ype}
(x: (a) >> a?): void

implement main0 () = {
  var e: wg_endpoint
  var so: sockaddr = Af_inet @{
sin_port = 1,
sin_addr = 2,
sin_zero = 3
  }
  var so6: sockaddr = Af_inet6 @{
sin6_port = 1,
sin6_flowinfo = 2,
sin6_addr = 3,
sin6_scope_id = 4
  }
//


  prval pre = view@e
  prval prso = view@so
  val () = wg_input(pre, prso | addr@e, addr@so)
  prval () = view@e := pre
  prval () = view@so := prso
//


  prval () = uninitize(e)
//


  prval pre = view@e
  prval prso6 = view@so6
  val () = wg_input(pre, prso6 | addr@e, addr@so6)
  prval () = view@e := pre
  prval () = view@so6 := prso6
}

On Mon, Apr 5, 2021 at 11:39 PM Kiwamu Okabe  wrote:

> But second calling `wg_input` causes error:
>
> ```ats
> #include "share/atspre_define.hats"
> #include "share/atspre_staload.hats"
>
> typedef sockaddr_in = @{
>   sin_port = int,
>   sin_addr = int,
>   sin_zero = int
> }
>
> typedef sockaddr_in6 = @{
>   sin6_port = int,
>   sin6_flowinfo = int,
>   sin6_addr = int,
>   sin6_scope_id = int
> }
>
> datatype sockaddr =
> | Af_inet of sockaddr_in
> | Af_inet6 of sockaddr_in6
>
> vtypedef wg_endpoint = @{
>   e_remote = sockaddr
> }
>
> fun wg_input
> {l1,l2:addr}
> (pfe: !wg_endpoint? @ l1 >> wg_endpoint @ l1, pfso: !sockaddr@l2 | e:
> ptr l1, so: ptr l2):
> void = let
> val () = !e.e_remote := !so
>   in
> ()
>   end
>
> implement main0 () = {
>   var e: wg_endpoint
>   var so: sockaddr = Af_inet @{
> sin_port = 1,
> sin_addr = 2,
> sin_zero = 3
>   }
>   var so6: sockaddr = Af_inet6 @{
> sin6_port = 1,
> sin6_flowinfo = 2,
> sin6_addr = 3,
> sin6_scope_id = 4
>   }
>
>   prval pre = view@e
>   prval prso = view@so
>   val () = wg_input(pre, prso | addr@e, addr@so)
>   prval () = view@e := pre
>   prval () = view@so := prso
>
>   prval pre = view@e
>   prval prso6 = view@so6
>   val () = wg_input(pre, prso6 | addr@e, addr@so6)
>   prval () = view@e := pre
>   prval () = view@so6 := prso6
> }
> ```
>
> ```
> $ patscc -o a.out main.dats -DATS_MEMALLOC_LIBC
> /home/kiwamu/src/practice-ats/tagged_union/main.dats: 1042(line=56,
> offs=21) -- 1045(line=56, offs=24): error(3): the dynamic expression
> cannot be assigned the type [S2Eat(S2Etyrec(flt0; npf=-1;
>  e_remote=S2Etop(knd=0; S2Ecst(sockaddr))), S2EVar(5246))].
> /home/kiwamu/src/practice-ats/tagged_union/main.dats: 1042(line=56,
> offs=21) -- 1045(line=56, offs=24): error(3): mismatch of static terms
> (tyleq):
> The actual term is: S2Ecst(sockaddr)
> The needed term is: S2Ecst(ptr_type)
> /home/kiwamu/src/practice-ats/tagged_union/main.dats: 1042(line=56,
> offs=21) -- 1045(line=56, offs=24): error(3): mismatch of static terms
> (tyleq):
> The actual term is: S2Etyrec(flt0; npf=-1; e_remote=S2Ecst(sockaddr))
> The needed term is: S2Etyrec(flt0; npf=-1; e_remote=S2Etop(knd=0;
> S2Ecst(sockaddr)))
> /home/kiwamu/src/practice-ats/tagged_union/main.dats: 1042(line=56,
> offs=21) -- 1045(line=56, offs=24): error(3): mismatch of static terms
> (tyleq):
> The actual term is: S2Eat(S2Etyrec(flt0; npf=-1;
> e_remote=S2Ecst(sockaddr)); S2Evar(e(8482)))
> The needed term is: S2Eat(S2Etyrec(flt0; npf=-1;
> e_remote=S2Etop(knd=0; S2Ecst(sockaddr)));
> S2EVar(5246->S2Evar(e(8482
> ```
>
> Following patch does fix the error:
>
> ```diff
> --- a/tagged_union/main.dats
> +++ b/tagged_union/main.dats
> @@ -51,6 +51,7 @@ implement main0 () = {
>prval () = view@e := pre
>prval () = view@so := prso
>
> +  var e: wg_endpoint
>prval pre = view@e
>prval prso6 = view@so6
>val () = wg_input(pre, prso6 | addr@e, addr@so6)
> ```
>
> How to re-use initialized argument on `wg_input` function?
>
> Best regards,
> --
> Kiwamu Okabe
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CAEvX6d%3Dzhbz4Oxtu1vTLjRBjov0pnxDKDrF16hoOmrADz0hoQg%40mail.gmail.com
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLpYWpbK6i5MQNnj%2BW2qv_VBaVTxmRfd%3DbLRg2C%2BhsZoDg%40mail.gmail.com.


Re: How to use the datavtype for tagged union?

2021-04-05 Thread Hongwei Xi
>>val () = !e.e_remote := so

The original linear content in !e.e_remote is discarded, resulting in a
leak. Also, 'so' is
a pointer (instead of a sockaddr).



On Sun, Apr 4, 2021 at 1:33 AM Kiwamu Okabe  wrote:

> I think I miss-undertood datavtype.
> In this case, it doesn't need to depend to int.
>
> Following is a more simple version:
>
> ```ats
> #include "share/atspre_define.hats"
> #include "share/atspre_staload.hats"
>
> typedef sockaddr_in = @{
>   sin_port = int,
>   sin_addr = int,
>   sin_zero = int
> }
>
> typedef sockaddr_in6 = @{
>   sin6_port = int,
>   sin6_flowinfo = int,
>   sin6_addr = int,
>   sin6_scope_id = int
> }
>
> datavtype sockaddr =
> | Af_inet of sockaddr_in
> | Af_inet6 of sockaddr_in6
>
> vtypedef wg_endpoint = @{
>   e_remote = sockaddr
> }
>
> fun wg_input
> {l1,l2:addr}
> (pfe: !wg_endpoint@l1, pfso: !sockaddr@l2 | e: ptr l1, so: ptr l2):
> void = let
> val () = !e.e_remote := so
>   in
> ()
>   end
>
> implement main0 () = {
>   var e: wg_endpoint
>   var so: sockaddr
>   prval pre = view@e
>   prval prso = view@so
> //  val () = wg_input(pre, prso | e, so)
>   prval () = view@e := pre
>   prval () = view@so := prso
> }
> ```
>
> But above causes the other errors:
>
> ```
> $ patscc -o a.out main.dats -DATS_MEMALLOC_LIBC
> /home/kiwamu/src/practice-ats/tagged_union/main.dats: 511(line=29,
> offs=14) -- 528(line=29, offs=31): error(3): a linear component of the
> following type is abandoned: [S2Ecst(sockaddr)].
> /home/kiwamu/src/practice-ats/tagged_union/main.dats: 538(line=31,
> offs=5) -- 540(line=31, offs=7): error(3): the linear dynamic variable
> [pfe$4738(-1)] is preserved but with an incompatible typ
> e.
> /home/kiwamu/src/practice-ats/tagged_union/main.dats: 538(line=31,
> offs=5) -- 540(line=31, offs=7): error(3): mismatch of static terms
> (tyleq):
> The actual term is: S2Eapp(S2Ecst(ptr_addr_type); S2Evar(l2(8481)))
> The needed term is: S2Ecst(sockaddr)
> /home/kiwamu/src/practice-ats/tagged_union/main.dats: 538(line=31,
> offs=5) -- 540(line=31, offs=7): error(3): mismatch of static terms
> (tyleq):
> The actual term is: S2Etyrec(flt0; npf=-1;
> e_remote=S2Eapp(S2Ecst(ptr_addr_type); S2Evar(l2(8481
> The needed term is: S2Etyrec(flt0; npf=-1; e_remote=S2Ecst(sockaddr))
> /home/kiwamu/src/practice-ats/tagged_union/main.dats: 538(line=31,
> offs=5) -- 540(line=31, offs=7): error(3): mismatch of static terms
> (tyleq):
> The actual term is: S2Eat(S2Etyrec(flt0; npf=-1;
> e_remote=S2Eapp(S2Ecst(ptr_addr_type); S2Evar(l2(8481;
> S2Evar(l1(8480)))
> The needed term is: S2Eat(S2Etyrec(flt0; npf=-1;
> e_remote=S2Ecst(sockaddr)); S2Evar(l1(8480)))
> ```
>
> Something is wrong?
>
> Best regards,
> --
> Kiwamu Okabe
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CAEvX6dmgZGvdUkVG93ajPVscqD44A8t2P4_ucemqPkR%2BA52mCQ%40mail.gmail.com
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLq9dGuDo-SkoLsX6u4SacUwhhbfuSSEupOqCq0wBoo-5g%40mail.gmail.com.


Re: How to avoid an unsolved constraint error on `if pagesizes > 0UL then pagesizes else 1UL`

2021-03-31 Thread Hongwei Xi
For such a use, you need a type annotation:

fun concat_exec_imgact {i:int} (pagesizes: ulint i): ulint = let
val
psize =
(
if
pagesizes > 0UL
then pagesizes else 1UL
) : [i:pos] ulint(i)
in
  concat_rnd_base(psize)
end

On Wed, Mar 31, 2021 at 8:31 AM Kiwamu Okabe  wrote:

> Dear all,
>
> I wrote following ATS code:
>
> ```ats
> #include "share/atspre_define.hats"
> #include "share/atspre_staload.hats"
>
> fun concat_rnd_base {i:int | i > 0}  (align: ulint i): ulint =
>   undefined()
>
> fun concat_exec_imgact {i:int} (pagesizes: ulint i): ulint = let
> val psize = if pagesizes > 0UL then pagesizes else 1UL
>   in
> concat_rnd_base(psize)
>   end
>
> implement main0 () = {
> }
> ```
>
> but above code causes following error:
>
> ```
> $ patscc main.dats
> .../main.dats: 302(line=10, offs=21) -- 307(line=10, offs=26):
> error(3): unsolved constraint: C3NSTRprop(C3TKmain();
> S2Eeqeq(S2Evar(i(8481)); S2Eintinf
> (1)))
> ```
>
> I belive the `psize` depends on `{i:int | i > 0}`.
> How to avoid the unsolved constraint error?
>
> Best regards,
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CAEvX6dnue3oRHsd0oFR9R1Y0WjsGfOu2YfYJ2pvpOm8mBHQBPQ%40mail.gmail.com
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLrrAa7sxyhFQgDySRrL6gDd7vdQRdf%2BBjPdnzapckDPBg%40mail.gmail.com.


Re: Constraint solving (integer inequalities)

2021-02-10 Thread Hongwei Xi
The implementation of FM in ATS/Postiats is largely standard.

One small improvement lies in its handling of an inequality of the
following kind:

2x + 2y >= 1

This inequality is first changed to 2x + 2y >= 2 and then simplified to x +
y >= 1.

The implementation uses linear types to ensure efficient memory management,
which
is quite important as FM often needs to use a large amount of memory.




On Wed, Feb 10, 2021 at 7:48 PM Vanessa McHale  wrote:

> Hi all,
>
> I've read that ATS uses the Fourier-Mitzkin method to handle
> constraints/inequalities but what I've read has been light on details.
>
> Does ATS do anything interesting for integer constraints?
>
> (Also: where in the ATS compiler is the constraint-solving code? I've only
> looked a bit but I didn't find it at first glance).
>
> Cheers,
> Vanessa McHale
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/9592166f-877e-43aa-bd9d-2cf0b178c286n%40googlegroups.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLqLjyceWVmtr1QzdvOo6-1Wyu_m9XPRhbhchy%2BYGzXb-g%40mail.gmail.com.


Re: Having Trouble Using Call-By-Reference

2021-01-22 Thread Hongwei Xi
(x:   >> _) means that the argument is call-by-reference; the integer
in it may be updated.

BTW, (x: ) means that the argument is read-only call-by-reference, but
it is not enforced in ATS2

Note that ( >> _) is just a shorthand for ( >> T).



On Fri, Jan 22, 2021 at 8:24 AM d4v3y_5c0n3s  wrote:

> Thanks, this works perfectly!  By the way, what does the " >>  _"
> syntax mean in this case?
>
> On Friday, January 22, 2021 at 1:46:15 AM UTC-5 gmhwxi wrote:
>
>> There are a couple of issues. Maybe the following code is what
>> you wanted:
>>
>> fn chng_int_test ( i:  >> _ ) : void = i := i + 1
>>
>>
>> fn test_chnge () : int = let
>>   var i: int = 0
>>
>>   val () = chng_int_test(i)
>> in
>>   i
>> end
>> On Fri, Jan 22, 2021 at 12:51 AM d4v3y_5c0n3s  wrote:
>>
>>> I'm trying to use call by reference in the following example, but I'm
>>> running into issues trying to get it to compile.  It's late, so I'll
>>> explain more tomorrow, but any help is appreciated.
>>>
>>> fn chng_int_test ( i: ? >> _ ) : void = i + 1
>>>
>>> fn test_chnge () : int = let
>>> var i = 0
>>> val () = chng_int_test(i)
>>> in
>>> i
>>> end
>>>
>>> /tmp/patsopt_tcats_SwYDb2: 46(line=2, offs=45) -- 47(line=2, offs=46):
>>> error(3): the dynamic expression cannot be assigned the type
>>> [S2Eapp(S2Ecst(g1uint_int_t0ype); S2Eextkind(atstype_size), S2EVar(0))].
>>> /tmp/patsopt_tcats_SwYDb2: 46(line=2, offs=45) -- 47(line=2, offs=46):
>>> error(3): mismatch of static terms (tyleq):
>>> The actual term is: S2Etop(knd=0; S2Eapp(S2Ecst(g0int_t0ype);
>>> S2Eextkind(atstype_int)))
>>> The needed term is: S2Eapp(S2Ecst(g1uint_int_t0ype);
>>> S2Eextkind(atstype_size), S2EVar(0))
>>> /tmp/patsopt_tcats_SwYDb2: 46(line=2, offs=45) -- 51(line=2, offs=50):
>>> error(3): the linear dynamic variable [i$view$74(-1)] is preserved but with
>>> an incompatible type.
>>> /tmp/patsopt_tcats_SwYDb2: 46(line=2, offs=45) -- 51(line=2, offs=50):
>>> error(3): mismatch of static terms (tyleq):
>>> The actual term is: S2Etop(knd=0; S2Eapp(S2Ecst(g0int_t0ype);
>>> S2Eextkind(atstype_int)))
>>> The needed term is: S2Eapp(S2Ecst(g0int_t0ype); S2Eextkind(atstype_int))
>>> /tmp/patsopt_tcats_SwYDb2: 46(line=2, offs=45) -- 51(line=2, offs=50):
>>> error(3): mismatch of static terms (tyleq):
>>> The actual term is: S2Eat(S2Etop(knd=0; S2Eapp(S2Ecst(g0int_t0ype);
>>> S2Eextkind(atstype_int))); S2Evar(i(4314)))
>>> The needed term is: S2Eat(S2Eapp(S2Ecst(g0int_t0ype);
>>> S2Eextkind(atstype_int)); S2Evar(i(4314)))
>>> /tmp/patsopt_tcats_SwYDb2: 46(line=2, offs=45) -- 51(line=2, offs=50):
>>> error(3): the dynamic expression cannot be assigned the type
>>> [S2Ecst(atsvoid_t0ype)].
>>> /tmp/patsopt_tcats_SwYDb2: 46(line=2, offs=45) -- 51(line=2, offs=50):
>>> error(3): mismatch of static terms (tyleq):
>>> The actual term is: S2Eapp(S2Ecst(g1uint_int_t0ype);
>>> S2Eextkind(atstype_size), S2Eapp(S2Ecst(add_int_int); S2EVar(0),
>>> S2Eintinf(1)))
>>> The needed term is: S2Ecst(atsvoid_t0ype)
>>> /tmp/patsopt_tcats_SwYDb2: 78(line=4, offs=26) -- 138(line=9, offs=4):
>>> error(3): the linear dynamic variable [i$view$75(-1)] is preserved but with
>>> an incompatible type.
>>> /tmp/patsopt_tcats_SwYDb2: 78(line=4, offs=26) -- 138(line=9, offs=4):
>>> error(3): mismatch of static terms (tyleq):
>>> The actual term is: S2Eapp(S2Ecst(g0int_t0ype); S2Eextkind(atstype_int))
>>> The needed term is: S2Eapp(S2Ecst(g1int_int_t0ype);
>>> S2Eextkind(atstype_int), S2Eintinf(0))
>>> /tmp/patsopt_tcats_SwYDb2: 78(line=4, offs=26) -- 138(line=9, offs=4):
>>> error(3): mismatch of static terms (tyleq):
>>> The actual term is: S2Etop(knd=0; S2Eapp(S2Ecst(g0int_t0ype);
>>> S2Eextkind(atstype_int)))
>>> The needed term is: S2Etop(knd=0; S2Eapp(S2Ecst(g1int_int_t0ype);
>>> S2Eextkind(atstype_int), S2Eintinf(0)))
>>> /tmp/patsopt_tcats_SwYDb2: 78(line=4, offs=26) -- 138(line=9, offs=4):
>>> error(3): mismatch of static terms (tyleq):
>>> The actual term is: S2Eat(S2Etop(knd=0; S2Eapp(S2Ecst(g0int_t0ype);
>>> S2Eextkind(atstype_int))); S2Evar(i(4313)))
>>> The needed term is: S2Eat(S2Etop(knd=0; S2Eapp(S2Ecst(g1int_int_t0ype);
>>> S2Eextkind(atstype_int), S2Eintinf(0))); S2Evar(i(4313)))
>>> patsopt(TRANS3): there are [4] errors in total.
>>> exit(ATS): uncaught exception:
>>> _2home_2hwxi_2Research_2ATS_2dPostiats_2src_2pats_error_2esats__FatalErrorExn(1025)
>>>
>>> --
>>> 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.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/ats-lang-users/b7580da8-275c-4d17-b796-90e81404ee5dn%40googlegroups.com
>>> 
>>> .
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> 

Re: Having Trouble Using Call-By-Reference

2021-01-21 Thread Hongwei Xi
There are a couple of issues. Maybe the following code is what
you wanted:

fn chng_int_test ( i:  >> _ ) : void = i := i + 1

fn test_chnge () : int = let
  var i: int = 0
  val () = chng_int_test(i)
in
  i
end


On Fri, Jan 22, 2021 at 12:51 AM d4v3y_5c0n3s  wrote:

> I'm trying to use call by reference in the following example, but I'm
> running into issues trying to get it to compile.  It's late, so I'll
> explain more tomorrow, but any help is appreciated.
>
> fn chng_int_test ( i: ? >> _ ) : void = i + 1
>
> fn test_chnge () : int = let
> var i = 0
> val () = chng_int_test(i)
> in
> i
> end
>
> /tmp/patsopt_tcats_SwYDb2: 46(line=2, offs=45) -- 47(line=2, offs=46):
> error(3): the dynamic expression cannot be assigned the type
> [S2Eapp(S2Ecst(g1uint_int_t0ype); S2Eextkind(atstype_size), S2EVar(0))].
> /tmp/patsopt_tcats_SwYDb2: 46(line=2, offs=45) -- 47(line=2, offs=46):
> error(3): mismatch of static terms (tyleq):
> The actual term is: S2Etop(knd=0; S2Eapp(S2Ecst(g0int_t0ype);
> S2Eextkind(atstype_int)))
> The needed term is: S2Eapp(S2Ecst(g1uint_int_t0ype);
> S2Eextkind(atstype_size), S2EVar(0))
> /tmp/patsopt_tcats_SwYDb2: 46(line=2, offs=45) -- 51(line=2, offs=50):
> error(3): the linear dynamic variable [i$view$74(-1)] is preserved but with
> an incompatible type.
> /tmp/patsopt_tcats_SwYDb2: 46(line=2, offs=45) -- 51(line=2, offs=50):
> error(3): mismatch of static terms (tyleq):
> The actual term is: S2Etop(knd=0; S2Eapp(S2Ecst(g0int_t0ype);
> S2Eextkind(atstype_int)))
> The needed term is: S2Eapp(S2Ecst(g0int_t0ype); S2Eextkind(atstype_int))
> /tmp/patsopt_tcats_SwYDb2: 46(line=2, offs=45) -- 51(line=2, offs=50):
> error(3): mismatch of static terms (tyleq):
> The actual term is: S2Eat(S2Etop(knd=0; S2Eapp(S2Ecst(g0int_t0ype);
> S2Eextkind(atstype_int))); S2Evar(i(4314)))
> The needed term is: S2Eat(S2Eapp(S2Ecst(g0int_t0ype);
> S2Eextkind(atstype_int)); S2Evar(i(4314)))
> /tmp/patsopt_tcats_SwYDb2: 46(line=2, offs=45) -- 51(line=2, offs=50):
> error(3): the dynamic expression cannot be assigned the type
> [S2Ecst(atsvoid_t0ype)].
> /tmp/patsopt_tcats_SwYDb2: 46(line=2, offs=45) -- 51(line=2, offs=50):
> error(3): mismatch of static terms (tyleq):
> The actual term is: S2Eapp(S2Ecst(g1uint_int_t0ype);
> S2Eextkind(atstype_size), S2Eapp(S2Ecst(add_int_int); S2EVar(0),
> S2Eintinf(1)))
> The needed term is: S2Ecst(atsvoid_t0ype)
> /tmp/patsopt_tcats_SwYDb2: 78(line=4, offs=26) -- 138(line=9, offs=4):
> error(3): the linear dynamic variable [i$view$75(-1)] is preserved but with
> an incompatible type.
> /tmp/patsopt_tcats_SwYDb2: 78(line=4, offs=26) -- 138(line=9, offs=4):
> error(3): mismatch of static terms (tyleq):
> The actual term is: S2Eapp(S2Ecst(g0int_t0ype); S2Eextkind(atstype_int))
> The needed term is: S2Eapp(S2Ecst(g1int_int_t0ype);
> S2Eextkind(atstype_int), S2Eintinf(0))
> /tmp/patsopt_tcats_SwYDb2: 78(line=4, offs=26) -- 138(line=9, offs=4):
> error(3): mismatch of static terms (tyleq):
> The actual term is: S2Etop(knd=0; S2Eapp(S2Ecst(g0int_t0ype);
> S2Eextkind(atstype_int)))
> The needed term is: S2Etop(knd=0; S2Eapp(S2Ecst(g1int_int_t0ype);
> S2Eextkind(atstype_int), S2Eintinf(0)))
> /tmp/patsopt_tcats_SwYDb2: 78(line=4, offs=26) -- 138(line=9, offs=4):
> error(3): mismatch of static terms (tyleq):
> The actual term is: S2Eat(S2Etop(knd=0; S2Eapp(S2Ecst(g0int_t0ype);
> S2Eextkind(atstype_int))); S2Evar(i(4313)))
> The needed term is: S2Eat(S2Etop(knd=0; S2Eapp(S2Ecst(g1int_int_t0ype);
> S2Eextkind(atstype_int), S2Eintinf(0))); S2Evar(i(4313)))
> patsopt(TRANS3): there are [4] errors in total.
> exit(ATS): uncaught exception:
> _2home_2hwxi_2Research_2ATS_2dPostiats_2src_2pats_error_2esats__FatalErrorExn(1025)
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/b7580da8-275c-4d17-b796-90e81404ee5dn%40googlegroups.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLreL%3DOzDipN%3DKh4EYZPpRFHRebS4aeJURfGw6TSvaR45Q%40mail.gmail.com.


Re: Support for OOP in some ATS3 extension (2)

2021-01-21 Thread Hongwei Xi
I think I misunderstood your earlier message.

If I understand you correctly this time, then what you mentioned in this
message
can already be done in ATS2 (you need ats2cpp for using g++ on the generated
code):

https://github.com/githwxi/ATS-Postiats/tree/master/contrib/ats2cpp
https://github.com/githwxi/ATS-Postiats/tree/master/contrib/ats2cpp/STL

The code in STL shows a way to wrap linear and dependent types around
various
STL functions (stack, deque, etc.).

By the way, this is also what is planned for xats2cc, which aims at
compiling XATSCML to C/C++.


On Thu, Jan 21, 2021 at 5:36 PM Dambaev Alexander 
wrote:

> And that is why I dream about an ability to be able to render classes to
> Java/C++: as soon as we might have a XATSCML->Java / XATSCML->C++ translator
> Ie, to be able to render something like this:
>
>
> ```
>
> UCLASS()class AMyActor : public AActor{
> GENERATED_BODY()public:
>
> UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Damage")
> int32 TotalDamage;
>
> UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Damage")
> float DamageTimeInSeconds;
>
> UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Transient, 
> Category="Damage")
> float DamagePerSecond;
>
> ...};
> ```
> https://docs.unrealengine.com/en-US/ProgrammingAndScripting/ProgrammingWithCPP/IntroductionToCPP/index.html
>
> Such that we should able to inject things like `UCLASS` into output or 
> `UPROPERTY`.
>
> At the same time, this means, that we can have a part of program, that is 
> written on a C++ and part, which had been rendered to C++ by ATS, such that 
> to use rendered parts borderlessly, we need to be able to describe 
> host-languages types in ATS, like:
> ```
>
> typedef std_vector(a:t0ype, n:int) = $extype_struct"std::vector"
>
> ```
>
> and then we should be able to use, say `push_back` either by using $extfcall 
> or being able to describe it in statics:
>
> ```
>
> extern fn {a:t0ype} push_back{n:nat} ( v: !std_vector(a, n) >> std_vector(a, 
> n+1), value: a): void
>
> ```
>
> but this means, that ATS should be able to render
> ```
>
>   val vec = (* some constructor *)
>
>   val () = push_back( vec, 1)
>
> ```
>
> into
> ```
>
>std::vector v;
>
>v. push_back( 1)
>
> ```
>
> Otherwise, ATS should render structures into host language and either make it 
> easy to use from target or we will have to marshall the data between target 
> language and ATS, but why do we need a translator into a target language
> if we still have to spent development time and CPU cycles to marshal data 
> from/to ATS? :)
>
>
> So what I mean is that there are a lot of 'mainstream' OOP languages, which 
> are being used for production, say Java and C++ and currently, in order to 
> write, say, non-C++ for Unreal Engine development, or non C# for Unity3D or
> non-Java for Android development, you sign for a pain of marshalling data and 
> writing a lot of bindings (for both sides: target language and higher level 
> language), ie, loosing the time in fighting against the platform in pursuit 
> of using
>  something more, that platform is not able to provide.
>
> So for me, it is clear, that ATS2 does the great job to eliminate the 
> fighting against C to a some extent: ie, ATS requires no marshalling and we 
> have $extfcall(), so in the case of 'I need to finish this today', we can use 
> a bunch of $extfcall()s for C libraries and it will
> not be a fighting against the C target.
> But, no matter how sad it is, I see a trend, where C API becomes obsolete. 
> Even GCC is now using C++ as a language of implementation. Many sources say 
> 'use Golang instead of C for most of your tasks' and C slowly becomes 
> 'language for kernel API
> or embedded' development, which means, that very few projects now provide C 
> libraries, which I can use a an ATS developer. For example: I know, that only 
> Godot engine provides C library, but neither Unity nor Unreal Engine. (or 
> maybe I'm wrong?)
> But if we imagine that someone had developed a translator to C++/Java/C#/Go - 
> will ATS-developer still be fighting against the platform? I think he will 
> fight against OOP platforms at least, as it will still require to manually 
> create classes at least, from which
>
> he will be able to call functions, rendered by ATS. And things like 
> std::vector, std::string and etc may require marshalling to/from ATS, even if 
> ATS itself renders into a target language...
>
>
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CAHjn2KzpLfvckjhsWqyOxEVTPy1avB_B0znx8YDz_4Obz_xD%3Dw%40mail.gmail.com
> 

Re: Support for OOP in some ATS3 extension (2)

2021-01-21 Thread Hongwei Xi
I simply meant 'don't-write-non-portable-code`.

Clearly, one can always write hard-to-port code in ATS.

I think that the real question is what kind of code one really wants to
port in the first place.

An executable ATS program looks like this: ATS-generic-stuff +
Target-language-runtime.
The first part is 100% portable, and the second part can be chosen
according to the target
language.

On Thu, Jan 21, 2021 at 1:01 PM Raoul Duke  wrote:

> How can that be when the methods for any given type in the host language
> are different across languages, sdks?
>
> On Thu, Jan 21, 2021 at 9:58 AM Hongwei Xi  wrote:
>
>> 100%, I suppose :)
>>
>>
>> On Thu, Jan 21, 2021 at 12:57 PM Raoul Duke  wrote:
>>
>>> To what degree are programs written in ATS expected to be portable
>>> across host languages?
>>>
>>> On Thu, Jan 21, 2021 at 9:54 AM Hongwei Xi  wrote:
>>>
>>>> Strictly speaking, ATS is an "abstract" language; the language itself
>>>> does not have primitive data types. When compiled to C, it uses the
>>>> data types defined by C; when to JS, it uses the data types defined
>>>> by JS; etc.
>>>>
>>>> On Thu, Jan 21, 2021 at 11:50 AM Raoul Duke  wrote:
>>>>
>>>>> $0.02
>>>>>
>>>>> In my limited/humble experience with FFI's the thing is not just being
>>>>> able to call out from the guest language to the host language, it is
>>>>> the return paths and the full round tripping and the overall semantics
>>>>> and the inevitable impedance mismatches that all sum up to make it an
>>>>> exercise in uselessness. Worst case things are like when the host
>>>>> string type != the guest string type, etc., etc, all the way up of
>>>>> course to bigger concepts like the host class implementation != the
>>>>> guest class implementation. Either there's a lot of extra cpu cycles
>>>>> spent on transmogriphying back and forth, or maybe things are worse
>>>>> and there ends up being 2 parallel things in the guest language and i
>>>>> have to manually convert.
>>>>>
>>>>> I do wish there were a master's thesis that studied the levels of
>>>>> integration among languages, both historically and in terms of
>>>>> technical possibilities, and specifically examined the end-developer
>>>>> UI and UX implications thereof, as well as the *ity issues like
>>>>> performance, security, et. al.
>>>>
>>>>
>>>>>
>>>>> --
>>>>> 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-users+unsubscr...@googlegroups.com.
>>>>> To view this discussion on the web visit
>>>>> https://groups.google.com/d/msgid/ats-lang-users/CAJ7XQb6j28exxf1t%3D%3DceCLJFxDKf237R618ZkX2H0BxKmo4ZEQ%40mail.gmail.com
>>>>> .
>>>>>
>>>> --
>>>> 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-users+unsubscr...@googlegroups.com.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLoK34G7g3RSnKf5JXH3z8NewA_ZVaeXRxrqo3A5KGu7KQ%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLoK34G7g3RSnKf5JXH3z8NewA_ZVaeXRxrqo3A5KGu7KQ%40mail.gmail.com?utm_medium=email_source=footer>
>>>> .
>>>>
>>> --
>>>
>> You received this message because you are subscribed to a topic in the
>>> Google Groups "ats-lang-users" group.
>>> To unsubscribe from this topic, visit
>>> https://groups.google.com/d/topic/ats-lang-users/snZWQK2YePY/unsubscribe
>>> .
>>> To unsubscribe from this group and all its topics, send an email to
>>> ats-lang-users+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/ats-lang-users/CAJ7XQb4Fvt%2BjPWa2%3D%2BKsL_TKZ9dV4vVwyodW8KD8gi9Qkp9F7w%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/ats-lang-users/CAJ7XQb4Fvt%2BjPWa2%3D%2BKsL_TKZ9dV4vVwyodW8KD8gi9Qkp9F7w%40mail.gmail.com?utm_medium=email_source=footer>
>>> .
>>&g

Re: Support for OOP in some ATS3 extension (2)

2021-01-21 Thread Hongwei Xi
100%, I suppose :)


On Thu, Jan 21, 2021 at 12:57 PM Raoul Duke  wrote:

> To what degree are programs written in ATS expected to be portable across
> host languages?
>
> On Thu, Jan 21, 2021 at 9:54 AM Hongwei Xi  wrote:
>
>> Strictly speaking, ATS is an "abstract" language; the language itself
>> does not have primitive data types. When compiled to C, it uses the
>> data types defined by C; when to JS, it uses the data types defined
>> by JS; etc.
>>
>> On Thu, Jan 21, 2021 at 11:50 AM Raoul Duke  wrote:
>>
>>> $0.02
>>>
>>> In my limited/humble experience with FFI's the thing is not just being
>>> able to call out from the guest language to the host language, it is
>>> the return paths and the full round tripping and the overall semantics
>>> and the inevitable impedance mismatches that all sum up to make it an
>>> exercise in uselessness. Worst case things are like when the host
>>> string type != the guest string type, etc., etc, all the way up of
>>> course to bigger concepts like the host class implementation != the
>>> guest class implementation. Either there's a lot of extra cpu cycles
>>> spent on transmogriphying back and forth, or maybe things are worse
>>> and there ends up being 2 parallel things in the guest language and i
>>> have to manually convert.
>>>
>>> I do wish there were a master's thesis that studied the levels of
>>> integration among languages, both historically and in terms of
>>> technical possibilities, and specifically examined the end-developer
>>> UI and UX implications thereof, as well as the *ity issues like
>>> performance, security, et. al.
>>
>>
>>>
>>> --
>>> 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-users+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/ats-lang-users/CAJ7XQb6j28exxf1t%3D%3DceCLJFxDKf237R618ZkX2H0BxKmo4ZEQ%40mail.gmail.com
>>> .
>>>
>> --
>> 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-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLoK34G7g3RSnKf5JXH3z8NewA_ZVaeXRxrqo3A5KGu7KQ%40mail.gmail.com
>> <https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLoK34G7g3RSnKf5JXH3z8NewA_ZVaeXRxrqo3A5KGu7KQ%40mail.gmail.com?utm_medium=email_source=footer>
>> .
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "ats-lang-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ats-lang-users/snZWQK2YePY/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> ats-lang-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CAJ7XQb4Fvt%2BjPWa2%3D%2BKsL_TKZ9dV4vVwyodW8KD8gi9Qkp9F7w%40mail.gmail.com
> <https://groups.google.com/d/msgid/ats-lang-users/CAJ7XQb4Fvt%2BjPWa2%3D%2BKsL_TKZ9dV4vVwyodW8KD8gi9Qkp9F7w%40mail.gmail.com?utm_medium=email_source=footer>
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLo_QPzjfX3YUkqpJ13O2dNJ-3s5LUarSPXdUFs6vGpGTQ%40mail.gmail.com.


Re: Support for OOP in some ATS3 extension (2)

2021-01-21 Thread Hongwei Xi
Strictly speaking, ATS is an "abstract" language; the language itself
does not have primitive data types. When compiled to C, it uses the
data types defined by C; when to JS, it uses the data types defined
by JS; etc.

On Thu, Jan 21, 2021 at 11:50 AM Raoul Duke  wrote:

> $0.02
>
> In my limited/humble experience with FFI's the thing is not just being
> able to call out from the guest language to the host language, it is
> the return paths and the full round tripping and the overall semantics
> and the inevitable impedance mismatches that all sum up to make it an
> exercise in uselessness. Worst case things are like when the host
> string type != the guest string type, etc., etc, all the way up of
> course to bigger concepts like the host class implementation != the
> guest class implementation. Either there's a lot of extra cpu cycles
> spent on transmogriphying back and forth, or maybe things are worse
> and there ends up being 2 parallel things in the guest language and i
> have to manually convert.
>
> I do wish there were a master's thesis that studied the levels of
> integration among languages, both historically and in terms of
> technical possibilities, and specifically examined the end-developer
> UI and UX implications thereof, as well as the *ity issues like
> performance, security, et. al.
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CAJ7XQb6j28exxf1t%3D%3DceCLJFxDKf237R618ZkX2H0BxKmo4ZEQ%40mail.gmail.com
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLoK34G7g3RSnKf5JXH3z8NewA_ZVaeXRxrqo3A5KGu7KQ%40mail.gmail.com.


Re: Support for OOP in some ATS3 extension (2)

2021-01-18 Thread Hongwei Xi
> > This time I would like to do something a bit more interesting:
> >
> > class
> >  > , b:type>
> > mygpair(a, b)
> > *snip*
>
> Do we need to say both  and (a,b)?  It seems redundant,
> since we already know the class is parametrized according to a and b, but
> maybe I'm missing something?
>

Again this is an issue with the OOP syntax. We have the following
possibilities
for the interface of mygpair_copy:

fun mypair_copy{a:type,b:type}(obj: !mypair(a, b)): mypair(a, b)
fun mypair_copy(obj: !mypair(a, b)): mypair(a, b)

Given that OOP syntax is quite restrictive anyway, we could decide to always
choose the second possibility. If so, we can just write:

class mypair(a:type, b:type) {
   ...
}

--Hongwei

On Mon, Jan 18, 2021 at 3:51 AM Elijah Stone  wrote:

> On Sun, 17 Jan 2021, gmhwxi wrote:
>
> > This time I would like to do something a bit more interesting:
> >
> > class
> >  > , b:type>
> > mygpair(a, b)
> > *snip*
>
> Do we need to say both  and (a,b)?  It seems redundant,
> since we already know the class is parametrized according to a and b, but
> maybe I'm missing something?
>
>
> > The mygpair(T1, T2) is a so-called generic class parameterized over
> > types T1 and T2. For an object of the type mygpair(T, T), a method for
> > swapping the fst and snd components of the object can be supported. But
> > this is difficult to do with the OOP syntax. BTW, how would be done in
> > Java? Such a method can be readily implemented with the following
> > syntax:
> >
> > fun
> > 
> > swap(pp: mygpair(a, a)): void =
> > let
> > val tmp = pp.fst in pp.fst := pp.snd; pp.snd := tmp
> > end
>
> Hmmm.  In a language like c++ where templates are not checked until
> they're instantiated, you would be able to just make that a template
> method.  That doesn't work so well in practice, however...
>
> One possible solution is subtyping.  As in:
>
> class  mypair(a, b) {
> var fst: a
> var snd: b
> //...
> }
>
> class  mysamepair(a): mypair(a, a) {
> method swap(): void = ...
> }
>
>   -E
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "ats-lang-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ats-lang-users/snZWQK2YePY/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> ats-lang-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/7e9a72f0-b2ee-af5f-b297-57f929179ebd%40elronnd.net
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLpW_mO6tV1CqmBpYppL8Z558P5jKYk4aV%2By%2BPmuJU5h7w%40mail.gmail.com.


Re: Support for OOP in some ATS3 extension (2)

2021-01-18 Thread Hongwei Xi
> class  mysamepair(a): mypair(a, a) {
> method swap(): void = ...
> }
>

I feel that this is a serious problem with typed OOP. Let me
give another example which I think no current OOP syntax can
handle.

Say we have an object of the type myrectangle(x, y), where
x and y are of the sort int (for width and height). Imagine a method
for doubling the width:

fun
double_width
(obj: !myrectangle(x, y) >> myrectangle(2*x, y)): void

This cannot be handled with OOP syntax because OOP syntax all
implicitly assumes that the type of 'this' cannot be changed by a method
call.

Also, one cannot introduce mysquare(x) as a subclass of myrectangle(x, x)
because double_with turns a square (of non-zero length)  into a non-square
rectangle.

--Hongwei


On Mon, Jan 18, 2021 at 3:51 AM Elijah Stone  wrote:

> On Sun, 17 Jan 2021, gmhwxi wrote:
>
> > This time I would like to do something a bit more interesting:
> >
> > class
> >  > , b:type>
> > mygpair(a, b)
> > *snip*
>
> Do we need to say both  and (a,b)?  It seems redundant,
> since we already know the class is parametrized according to a and b, but
> maybe I'm missing something?
>
>
> > The mygpair(T1, T2) is a so-called generic class parameterized over
> > types T1 and T2. For an object of the type mygpair(T, T), a method for
> > swapping the fst and snd components of the object can be supported. But
> > this is difficult to do with the OOP syntax. BTW, how would be done in
> > Java? Such a method can be readily implemented with the following
> > syntax:
> >
> > fun
> > 
> > swap(pp: mygpair(a, a)): void =
> > let
> > val tmp = pp.fst in pp.fst := pp.snd; pp.snd := tmp
> > end
>
> Hmmm.  In a language like c++ where templates are not checked until
> they're instantiated, you would be able to just make that a template
> method.  That doesn't work so well in practice, however...
>
> One possible solution is subtyping.  As in:
>
> class  mypair(a, b) {
> var fst: a
> var snd: b
> //...
> }
>
> class  mysamepair(a): mypair(a, a) {
> method swap(): void = ...
> }
>
>   -E
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "ats-lang-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ats-lang-users/snZWQK2YePY/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> ats-lang-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/7e9a72f0-b2ee-af5f-b297-57f929179ebd%40elronnd.net
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLqCwvGL_2Um%2B45tZSW8HNA%3D4Rir2kTah-1oZNqRHz_Lbw%40mail.gmail.com.


Re: Learn ATS in Y minutes -- request for documentation review

2021-01-17 Thread Hongwei Xi
Thanks, Mark!

I took a quick read.

Your description of various ATS2 features is accurate.

To be honest, I myself often forget how certain things are done in ATS2 and
have to use 'grep' to find code examples helping me figure out. For example,
I find the information in Part 5 particularly helpful!

Given the scarcity of ATS2 documentation, I am also quite amazed by your
being
able to figure out some very intricate features of ATS2 on your own.

Cheers!

--Hongwei

On Sun, Jan 17, 2021 at 1:30 AM mark.l@gmail.com <
mark.l.barb...@gmail.com> wrote:

> Hi all,
>
> Learn X in Y Minutes  has community-made
> documentation for programming languages and tools, as example-driven
> "whirlwind tours" of each languages' features.  I made one for ATS, since
> none existed and I think it's a great documentation format to have.  Here's 
> the
> rendered markdown
> ,
> and the associated PR
> .  It's
> about 500 lines of well-commented ATS, and introduces language features as
> you read it.
>
> I'm still relatively inexperienced in ATS, so I'd appreciate reviews to
> make sure all the explanations are sound and to make the code more
> idiomatic.  Reviews from less experienced ATS users would also be
> particularly welcome, to make sure it addresses the confusions you had when
> first using ATS.
>
> Learn X in Y Minutes has been really helpful to me in the past learning
> other languages, since reading good code can be a great way to learn.  I
> hope we can make this equally helpful to new ATS programmers.
>
> Thanks,
>
> -Mark Barbone
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/2f2cad00-f229-491a-bf7d-a064d5ec452en%40googlegroups.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLpWWB0qZ2o6-Tf44-i%2BNkOTO6vwF8PJV%3DPPr%3DOqVEdhXw%40mail.gmail.com.


Re: Is It Possible to Pass a Function Template as a Parameter?

2021-01-02 Thread Hongwei Xi
Yes, I would like to see an example of this kind.


On Sat, Jan 2, 2021 at 9:19 PM d4v3y_5c0n3s  wrote:

> So, I know that  it's possible to pass a function to another function as a
> parameter, but what if I want to pass a function template specifically?  If
> anyone would like some clarification, I can try to provide some examples of
> what I'm trying to achieve.
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/96fc4ec0-8355-4b32-883a-30f2293b4861n%40googlegroups.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLoc7cF_sAjb0a%2Bkz6UJyW8NLzkVFpm_N4HiRG0EHxyvUw%40mail.gmail.com.


Re: Building ATS2 from Github head.

2020-12-31 Thread Hongwei Xi
This is an issue of the ATS2/Postiats compiler because it uses the absolute
path of a file
to create a name during compilation for the package stored in the file.
This is not a reliable
approach. Hopefully, something better can be used for ATS3. One possibility
is to just follow
what Java does.


On Thu, Dec 31, 2020 at 7:50 PM Steinway Wu  wrote:

> It is so weird, turns out that
>
> ATSHOME=/some/path/with/../../in/it make -f Makefile_devl all
>
> will fail, but
>
> ATSHOME=/some/absolute/path/with/no/dot make -f Makefile_devl all
>
> works.
>
> Any idea what could have caused that? Is it a Make issue or is it an ATS
> compiler issue?
>
>
>
> *Steinway Wu*
>
> *吴翰文*
>
> *Google Cloud*
>
> *I'm not a coder.*
> *I'm an artist of life.*
>
>
> On Dec 31, 2020 at 1:31:10 PM, gmhwxi  wrote:
>
>>
>> Maybe this has something to do with where the ATS2 package is stored on
>> your computer.
>> Could you try something like:
>>
>> cd /tmp
>> wget
>> http://downloads.sourceforge.net/project/ats-lang/ats-lang/anairiats-0.2.12/ats-lang-anairiats-0.2.12.tgz
>> tar xf ats-lang-anairiats-0.2.12.tgz
>> cd ats-lang-anairiats-0.2.12/
>> export ATSHOME=${PWD}
>> export ATSHOMERELOC=ATS-0.2.12
>> ./configure && make all
>>
>> Just tried. This script works for me.
>>
>> On Thursday, December 31, 2020 at 12:18:22 PM UTC-5 stein...@gmail.com
>> wrote:
>>
>>> Hi,
>>>
>>> It seems the documentation at
>>> https://github.com/githwxi/ATS-Postiats/wiki/Building-and-installing as
>>> well as scripts at
>>> https://github.com/ats-lang/ats-lang.github.io/blob/master/SCRIPT/C9-ATS2-install-latest.sh
>>> are outdated. I’m trying both and encountered link errors.
>>>
>>> Here’s what I did.
>>>
>>> # installing ats1
>>> wget …
>>> ./configure —prefix=…
>>> make all_ngc
>>> make install
>>>
>>> # installing ats2
>>> git clone …
>>> export ATSHOME=…
>>> export ATSHOMERELOC=ATS-0.2.12
>>> make -f Makefile_devl
>>>
>>> The errors I see is undefined reference to symbols like
>>> _2root_2parts_2ats1_2build_2libatsdoc_... Using nm to view the symbols
>>> of libatsdoc.a, I can see they are named like
>>> ATS_2d0_2e2_2e12_2libatsdoc_... instead.
>>>
>>> There was a post
>>> https://groups.google.com/g/ats-lang-users/c/uKlIX4jcL0Y/m/nKf8oezDBAAJ with
>>> the same error, but I believe I correctly set ATSHOMERELOC
>>>
>>> Any idea what I’m missing?
>>>
>>>
>>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "ats-lang-users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/ats-lang-users/W62cWGzt0AI/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> ats-lang-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ats-lang-users/87cbe011-5997-4d96-a439-2522ced8e8adn%40googlegroups.com
>> 
>> .
>>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CAL-Unv9pvBNQtcQwK_wJ-wVdzmS-2HmnmZzKLr_SoTKonBVPmA%40mail.gmail.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLpQkrw%3DdNn6miFquKPG4wqfXAObVsw8tEPOeSN9LZ7-RA%40mail.gmail.com.


Re: ignoring the datavtype

2020-12-30 Thread Hongwei Xi
Yes, if a linear value matches the wildcard pattern '_', it is leaked.
It is not a bug, though; it is by design.

This is probably a poor design of mine. It is already abandoned in ATS3.

--Hongwei

On Wed, Dec 30, 2020 at 7:34 AM Dambaev Alexander 
wrote:

> here is the repo of the minimum example where such issue is being
> reproduced: https://github.com/dambaev/ats-datavtype-leak
>
> and in particular test3:
> https://github.com/dambaev/ats-datavtype-leak/blob/master/src/TEST/test3.dats#L46-L53
> which is compilable and leaking resource
>
> ср, 30 дек. 2020 г. в 16:31, Dambaev Alexander :
>
>> Hi,
>>
>> milis is a datavtype `Bytestring_vtype`described at
>> https://github.com/dambaev/ats-bytestring/blob/master/SATS/bytestring.sats#L8
>> and in this particular case, being instantiated by `pack_int64' from
>> https://github.com/dambaev/ats-bytestring/blob/master/SATS/bytestring.sats#L184-L190
>>
>> ср, 30 дек. 2020 г. в 16:21, Artyom Shalkhakov <
>> artyom.shalkha...@gmail.com>:
>>
>>> Hi Alex,
>>>
>>> What's the type of [millis]?
>>>
>>> ср, 30 дек. 2020 г. в 10:04, Dambaev Alexander :
>>>
 Hi all,

 today I spotted an error in my code. Here is the snippet:
 ```
 val millis = $BS.pack( msecs_i64 + ($UN.cast{int64}
 msecs) ) // + $UN.cast{int32} msecs )
 val env = ( hws, millis)
 val () = list_vt_foreach_funenv0< ( $BS.BytestringNSH1,
 $BS.BytestringNSH1) ><($BS.BytestringNSH1,$BS.BytestringNSH1)>{void}( () |
 kvs, env, print_json) where {
   fn
 print_json
 ( pf: !void
 | x: &(@($BS.BytestringNSH1, $BS.BytestringNSH1))
 , env: !($BS.BytestringNSH1, $BS.BytestringNSH1)
 ): void = {
   val (hws, millis) = env
   val bs = $BS.pack "{ \"tenant\": \"demo\",
 \"buildingId\": \"demo\", "
 + $BS.pack "\"metadata\": { \"name\": \"" +!
 x.0 + $BS.pack "\"}, "
 + $BS.pack "\"value\": " +! x.1 + $BS.pack ", "
 + $BS.pack "\"timestamp\": " +! millis +
 $BS.pack ", "
 + $BS.pack "\"deviceId\": \"" +! hws + $BS.pack
 "\""
 + $BS.pack "}"
   val () = $BS.printlnC( bs)
   prval () = env := (hws, millis)
 }
 }
 *val (hws1, _) = env (* here I can just ignore the
 'millis'  and cause a memory leak *)*
 prval () = hws := hws1
 val () = list_vt_freelin_fun<@($BS.BytestringNSH1,
 $BS.BytestringNSH1)> (kvs, cleaner) where {
   fn cleaner( x: &($BS.BytestringNSH1,
 $BS.BytestringNSH1) >> ($BS.BytestringNSH1, $BS.BytestringNSH1)?):void = {
 val () = $BS.free x.0
 val () = $BS.free x.1
   }
 }
 val () = $BS.free( time)
 val () = $BS.free( rawpayload)
 val () = $BS.free( hws)
 ```
 and the compiler hasn't bite my hands with this: it has typechecked and
 compiled this code without issues. Only valgrind had.
 And here is the correct snippet, which is compiling without issues as
 well.

 ```
 val millis = $BS.pack( msecs_i64 + ($UN.cast{int64}
 msecs) ) // + $UN.cast{int32} msecs )
 val env = ( hws, millis)
 val () = list_vt_foreach_funenv0< ( $BS.BytestringNSH1,
 $BS.BytestringNSH1) ><($BS.BytestringNSH1,$BS.BytestringNSH1)>{void}( () |
 kvs, env, print_json) where {
   fn
 print_json
 ( pf: !void
 | x: &(@($BS.BytestringNSH1, $BS.BytestringNSH1))
 , env: !($BS.BytestringNSH1, $BS.BytestringNSH1)
 ): void = {
   val (hws, millis) = env
   val bs = $BS.pack "{ \"tenant\": \"demo\",
 \"buildingId\": \"demo\", "
 + $BS.pack "\"metadata\": { \"name\": \"" +!
 x.0 + $BS.pack "\"}, "
 + $BS.pack "\"value\": " +! x.1 + $BS.pack ", "
 + $BS.pack "\"timestamp\": " +! millis +
 $BS.pack ", "
 + $BS.pack "\"deviceId\": \"" +! hws + $BS.pack
 "\""
 + $BS.pack "}"
   val () = $BS.printlnC( bs)
   prval () = env := (hws, millis)
 }
 }
 *val (hws1, millis1) = env*
 prval () = hws := hws1
 *prval () = millis := 

Re: Can arrayptr_freelin() cause a memory leak?

2020-12-15 Thread Hongwei Xi
>>Okay, so what you are saying is that in order for the code to compile, I
will need to implement the template for the given type.

That's right.

Hopefully, such a template can be automatically generated in ATS3 based on
the given (or inferred) type
information. There should be a substantial component in ATS3 to support
this kind of type-based meta-programming.

On Tue, Dec 15, 2020 at 11:43 AM d4v3y_5c0n3s  wrote:

> Okay, so what you are saying is that in order for the code to compile, I
> will need to implement the template for the given type.  That makes sense,
> thanks for the explanation! :)
>
> On Tuesday, December 15, 2020 at 10:57:09 AM UTC-5 gmhwxi wrote:
>
>> It should not as arrayptr_freelin calls array_uninitize$clear to free all
>> the stored elements.
>> It is your obligation to implement the latter.
>>
>>
>> On Tue, Dec 15, 2020 at 9:54 AM d4v3y_5c0n3s  wrote:
>>
>>> I just have a question about using arrayptr_freelin() (which frees
>>> an arrayptr that contains a vt@ype.)  I have an arrayptr which contains
>>> datavtypes, and these datavtypes act like a list in that they can contain a
>>> reference to another of the same datavtype.  The typechecker lets me simply
>>> call arrayptr_freelin() on the arrayptr, but does this cause a memory
>>> leak?  Do I need to free the individual datavtypes first?
>>> I can provide a code example if anyone reading this doesn't
>>> understand what I am talking about.  The types and functions that I am
>>> using are all in the prelude.
>>>
>>> --
>>> 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.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/ats-lang-users/84121c93-a043-405c-be86-e7cc74903f68n%40googlegroups.com
>>> 
>>> .
>>>
>> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/b6d0bb1a-cfa2-4c1d-aca5-3d669d827016n%40googlegroups.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLr23TN7MhK3nyGczRpJw%2B-WQM%3Dwz%2Bpp-jEG2Dvf-UVGHQ%40mail.gmail.com.


Re: Can arrayptr_freelin() cause a memory leak?

2020-12-15 Thread Hongwei Xi
It should not as arrayptr_freelin calls array_uninitize$clear to free all
the stored elements.
It is your obligation to implement the latter.


On Tue, Dec 15, 2020 at 9:54 AM d4v3y_5c0n3s  wrote:

> I just have a question about using arrayptr_freelin() (which frees an
> arrayptr that contains a vt@ype.)  I have an arrayptr which contains
> datavtypes, and these datavtypes act like a list in that they can contain a
> reference to another of the same datavtype.  The typechecker lets me simply
> call arrayptr_freelin() on the arrayptr, but does this cause a memory
> leak?  Do I need to free the individual datavtypes first?
> I can provide a code example if anyone reading this doesn't understand
> what I am talking about.  The types and functions that I am using are all
> in the prelude.
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/84121c93-a043-405c-be86-e7cc74903f68n%40googlegroups.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLphUMfuFkR2UVPCTFYycDtTA4%2BXyySA2iuQm3ytButYQA%40mail.gmail.com.


Re: symintr and staload

2020-11-28 Thread Hongwei Xi
This behavior is intended.

In ATS, a fixity declaration like the following one has no effect
outside the module (that is, file) where it is declared:

infixl (+) +++

By the way, symintr is no longer needed in ATS2; it is not even
supported in ATS3.


On Sat, Nov 28, 2020 at 8:47 AM Dambaev Alexander 
wrote:

> Hi,
> I have noticed, that I am not able to introduce new symbol inside sats
> file and use it in dats file, like this:
> file1.sats
> ```
>
> fn operator( a: int, b: int): int
>
> symintr +++
> infixl (+) +++
> overload +++ with operator
> ```
> main.dats:
>
> ```
> #include "share/atspre_staload.hats"
>
> #define ATS_DYNLOADFLAG 0
>
> (* if I uncomment those lines before staload, then main.dats will be
> compiled as expected. Otherwise, patscc will say, that it is unable to
> resolve +++
> symintr +++
> infixl (+) +++
> *)
> staload "file1.sats"
>
> implement main0() = println!( "1 +++ 2 = ", 1 +++ 2)
> ```
>
> I found a walkaround by introducing symbol and it's precedence before
> staload, but it seems like a bug for me
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CAHjn2KzsVTfFbMm_VX9vzvE-aPGem1eqVyDR2DCkXh-AAypF%2Bw%40mail.gmail.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLp2NFK5DyJ5DALefCec5Z6gpdoB3TM_T5Ep4mJLgoZgkw%40mail.gmail.com.


Re: Read IO and Write IO

2020-11-24 Thread Hongwei Xi
>>Would it still be better to include the effects in the source file,

If we look at a bigger picture, it may not even be practical to require
that this kind of information be stored
in the source. Today it is effect-tracking, and tomorrow it will surely be
something else. And there is only so
much that you can put in the source file without causing conflicts.

On Tue, Nov 24, 2020 at 2:23 PM Brandon Barker 
wrote:

> Would it still be better to include the effects in the source file, and
> then pass to the compiler (or 3rd party tool) which effects are to be
> tracked, and possibly how they are tracked?
>
> Advantages of this approach to me seem that:
>  - Easily viewable from the source (as was already mentioned)
>  - If an effect isn't being used, though it is listed in the source, the
> effect checker could emit a warning or error (configurable).
>  - Encourages use of effects: I worry that without effect tracking, we
> gain less confidence in the rest of the ATS3 ecosystem. This is similar to
> the state of play with Mypy and Python's gradual typing (and I'll note that
> there, types are annotated in the code as one would expect), except we're
> only talking about effect types and not types in general: most python
> libraries don't use typings, so even if you are vigilant in your own code,
> it is much harder to sometimes understand what effects are happening in
> libraries. Of course, ultimately much of what we do is built on FFIs of
> some sort, and a certain degree of trust has to be exercised at that level,
> but I feel like without some degree of standardization with regard to a
> basic set of effects, and encouraging their use, it could result in them
> not being very useful due to fractured use within the ATS3 ecosystem.
>
> On Tuesday, November 24, 2020 at 1:24:10 AM UTC-5 gmhwxi wrote:
>
>> Thanks for the message!
>>
>> What I said is not in conflict with what you described in the message.
>>
>> An external tool for tracking effects can be quite useful in large scale
>> programming.
>> Deciding what effects should be tracked is often open-ended; what is
>> decided today
>> may not be what is wanted tomorrow.
>>
>> The type-based approach you described becomes quite burdensome once
>> higher-order
>> functions are present. A big difficulty in effect-tracking lies precisely
>> in handling higher-order
>> functions.
>>
>> On Monday, November 23, 2020 at 10:57:41 PM UTC-5 ice.r...@gmail.com
>> wrote:
>>
>>> Maintaining some external file seems to me as something, which is easy
>>> to ignore or easy to forget about and without some scatch of of example of
>>> usage, I can't see how it will be helpful at all.
>>>
>>> For example:
>>> ```
>>> fn foo(): void = println!("hello")
>>> implement main0() = foo()
>>> ```
>>> and the external file contains:
>>> ```
>>> console: println
>>> ```
>>> Do you mean, that such external tool should require foo and main0 to be
>>> listed in such file?
>>> In this case, it will still be absent in types so it will be hard to
>>> answer a questions like: "what effects contains foo?" or main0 as well.
>>>
>>> In contrast, by using proof arguments you will actually see, that in
>>> order to use foo you need to pass IO:
>>> so it is clearer to understand, but more verbose as well, as main0 will
>>> be probably a source of all kind of effects, like:
>>> ```
>>> extern prfn use_console( !IO): Console
>>> fn
>>>   foo
>>>   ( console: !Console
>>>   |
>>>   ): void = println!( console, "hello")
>>> implement main0(io | ) = {
>>>   prval console = use_console( io)
>>>   val () = foo( console | )
>>> }
>>> ```
>>>
>>> another interesting approach will be to wrap the exceptions (ie, the
>>> goal is to see in types which exceptions are possible to be thrown from
>>> function), so $raise should have type like:
>>> ```
>>> extern fn
>>>   $raise
>>>   {a:type}{b:type| // is there an exception sort?
>>>   ( !Throws(a)
>>>   | a
>>>   ): b
>>> ```
>>> then `try` should require `!IO` and bring `Throws(a)` for all branches
>>> in `with`, like:
>>> ```
>>> fn
>>>foo
>>>   ( Throws( DivisionByZero)
>>>   , Throws(FileNotFound)
>>>   | a: int
>>>   , b :int
>>>   ): int = a / b
>>>
>>> implement main0() =
>>> try
>>>   ( try foo() with // I am not sure if foo() will be able to use
>>> Throws(..) implicitely
>>>   | ~DivisionByZero() => ... // this brings Throws(DivisionByZero) into
>>> the scope and only within this block of try ... with
>>>   ) with
>>>   | ~FileNotFound() => ... // this brings Throws(FileNotFound) into the
>>> scope
>>> ```
>>> but of course, this looks like Haskell's typeclasses from
>>> https://www.well-typed.com/blog/2015/07/checked-exceptions/
>>>
>> --
> You received this message because you are subscribed to a topic in the
> Google Groups "ats-lang-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ats-lang-users/HtsSq9thpk8/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> 

Re: Current Status of ATS3 (2020-11-22)

2020-11-23 Thread Hongwei Xi
>>Can I guess that XATSCL0 is basically the same as the C-file that we have
now during compilation with patscc? Otherwise, what is the purpose of it?

Patscc generates code that contains goto statements. This time I would
exclude goto's in XATSCL0. In this way, compilers for ATS3 targeting other
languages can also benefit from using XATSCL0.

>>Does this mean that currently ATS3 just ignores code related to
linear/dependent types?

Yes, it ignores completely.

-- 

On Sun, Nov 22, 2020 at 11:47 PM Dambaev Alexander 
wrote:

> Glad to hear news about ATS3 implementation!
>
>
> XATSOPT:
>>
>> Xatsopt is a functioning compiler implemented in ATS2 for translating
>> ATS3 into a typed intermediate language of the name XATSCML, which is
>> both C-like and ML-like. It is planned for xatsopt to further
>> translate XATSCML into XATSCL0, a low-level C-like language. I now
>> primarily see xatsopt as a library (libxatsopt) for implementing tools
>> to support programming with ATS3.
>>
> Can I guess that XATSCL0 is basically the same as the C-file that we have
> now during compilation with patscc? Otherwise, what is the purpose of it?
>
>
>>
>> Documenting Xatsopt:
>>
>> This has been assigned a high priority. It is hoped that other
>> people interested in ATS3 can start developing tools for ATS3 after
>> a minimal amount of documentation on xatsopt is made available.
>>
> The more documentation - the better :)
>
>
>> Advanced Type-Checking:
>>
>> While one can specify with linear types and dependent types in ATS3,
>> there is no type-checking for such advanced types in xatsopt. I plan
>> to concentrate on implementing support for such type-checking in the
>> next phase of ATS3 development.
>>
>
> Does this mean that currently ATS3 just ignores code related to
> linear/dependent types?
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CAHjn2Kxekq4Phu1%3DEFWxTVgjRm2pczK5ZsLeAy7DN%2BGzuuyA8A%40mail.gmail.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLqmUjH7eLeO8iaAp0DE_Hp6RHadu%2BuKyTcLu2TPc_rq7Q%40mail.gmail.com.


Re: Current Status of ATS3 (2020-11-22)

2020-11-22 Thread Hongwei Xi
>>What is the final vision for XATSCL0?  Will it be compiled into c?  Or
directly into native code (via custom backend, or llvm/similar)?

XATSCL0 should most likely be a subset of C.

To get into native code, one needs to remove function calls of C-style in
XATSCL0.

>>What is the effect on compilation speed of having (at least) two full
intermediate languages?

Right now, it is not a big concern as xatsopt does not do time-consuming
optimizations. I suspect that
more time is likely spent on the phase of compiling XATSCL0 to native code.

>>JS doesn't have integers.  So how will code that uses integers be
compiled?  Is code compiled to js is limited to 32-bit integers, since they
can fit into the range of a double?

When compiled to JS, the int type in ATS is interpreted by some JS
functions in a small library dabbed 'runtime'.
For instance, integer division is given the following implementation:

function
XATS2JS_gint_div_sint_sint
  (x1, x2)
{
//
  let q0 = x1 / x2;
//
  if
  (q0 >= 0)
  {
return Math.floor(q0);
  }
  else
  {
return Math.ceil( q0 );
  }
}

On Sun, Nov 22, 2020 at 6:31 PM Elronnd _  wrote:

> On Sun, 22 Nov 2020, gmhwxi
> wrote:
>
>
>
> > As of today, I am pleased to announce that ATS3 has reached a stage
> where it can be realistically used in software construction. This is
> achieved after slightly more than two and one-half years of continual
> development by yours truly
> :)
>
>
>
> Great to
> hear!
>
>
>
>
>
> > Xatsopt is a functioning compiler implemented in ATS2 for translating
> ATS3 into a typed intermediate language of the name XATSCML, which is both
> C-like and ML-like. It is planned for xatsopt to further translate XATSCML
> into XATSCL0, a low-level C-like
> language.
>
>
>
> What is the final vision for XATSCL0?  Will it be compiled into c?  Or
> directly into native code (via custom backend, or
> llvm/similar)?
>
>
>
> What is the effect on compilation speed of having (at least) two full
> intermediate
> languages?
>
>
>
>
>
> > Xats2js is a functioning compiler implemented in ATS2 for translating
> XATSCML into
> JavaScript
>
>
>
> JS doesn't have integers.  So how will code that uses integers be
> compiled?  Is code compiled to js is limited to 32-bit integers, since they
> can fit into the range of a
> double?
>
>
>
>  -E
>
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/ca34ad8d-77db-4e91-b548-400c3111c8c9n%40googlegroups.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLq6bS2tuU-WF3-TBjen36hfydPZ-4HHu%2BMfiZMeukRQDw%40mail.gmail.com.


Re: Current Status of ATS3 (2020-11-22)

2020-11-22 Thread Hongwei Xi
I could only manage one write-up so far:

https://github.com/xanadu-lang/xats2js/tree/master/docgen/CodeBook/Hello

I plan to implement some word games to showcase this style of
co-programming.

Cheers!


On Sun, Nov 22, 2020 at 1:30 PM Hongwei Xi  wrote:

> I will do a few examples today of co-programming with ATS3 and JS.
>
> Conceptually, it is straightforward: ATS code is compiled to JS via xats2js
> and the generated JS code can be directly combined with other JS code.
> There is a very small library of JS code needed for running the generated
> JS code.
>
> In practice, it is equally straightforward :)
>
> By the way, I would like to emphasize that xats2js is NOT meant to be an
> optimizing compiler; it is more like a reference implementation of some
> sort.
> The JS code generated by xats2js is currently not of high quality in terms
> of
> efficiency (time-wise or memory-wise).
>
> On Sun, Nov 22, 2020 at 12:38 PM Brandon Barker 
> wrote:
>
>> Hi Hongwei,
>>
>> That's exciting to hear. If and when they are available, could you point
>> to any FFI examples or documentation for JavaScript? Perhaps, but not
>> necessarily, related to DOM APIs in the browser (just as a common example)?
>> On Sunday, November 22, 2020 at 9:31:16 AM UTC-5 gmhwxi wrote:
>>
>>>
>>>
>>> Hi, there,
>>>
>>> HX-2020-11-22:
>>>
>>> (*
>>> HX-2018-04-07: Let us get started!!!
>>> *)
>>>
>>> As of today, I am pleased to announce that ATS3 has reached a stage
>>> where it can be realistically used in software construction. This is
>>> achieved after slightly more than two and one-half years of continual
>>> development by yours truly :)
>>>
>>> ##
>>> #
>>> # The current status
>>> #
>>> ##
>>>
>>> XATSOPT:
>>>
>>> Xatsopt is a functioning compiler implemented in ATS2 for translating
>>> ATS3 into a typed intermediate language of the name XATSCML, which is
>>> both C-like and ML-like. It is planned for xatsopt to further
>>> translate XATSCML into XATSCL0, a low-level C-like language. I now
>>> primarily see xatsopt as a library (libxatsopt) for implementing tools
>>> to support programming with ATS3.
>>>
>>> XATS2JS:
>>>
>>> Xats2js is a functioning compiler implemented in ATS2 for translating
>>> XATSCML into JavaScript (or JS for short). It should be noted that
>>> xats2js can compile tail-recursive calls into local jumps, effectively
>>> supporting the common practice in functional programming of writing
>>> loops as tail-recursive functions.
>>>
>>> I will give detailed explanation elsewhere on using xats2js. Generally
>>> speaking, one can now practice a form of co-programming with ATS3 and
>>> JS. The JS code generated by xats2js from compiling ATS3 source can be
>>> directly combined with other JS code (as if the generated code were
>>> manually written in JS)
>>>
>>> ##
>>> #
>>> # Future Development
>>> #
>>> ##
>>>
>>> Documenting Xatsopt:
>>>
>>> This has been assigned a high priority. It is hoped that other
>>> people interested in ATS3 can start developing tools for ATS3 after
>>> a minimal amount of documentation on xatsopt is made available.
>>>
>>> Advanced Type-Checking:
>>>
>>> While one can specify with linear types and dependent types in ATS3,
>>> there is no type-checking for such advanced types in xatsopt. I plan
>>> to concentrate on implementing support for such type-checking in the
>>> next phase of ATS3 development.
>>>
>>> ##
>>> #
>>> # A little history of ATS3
>>> #
>>> ##
>>>
>>> Essentially, ATS3 refers to the third edition of ATS, and ATS/Xanadu
>>> is currently the only implementation of ATS3. Note that the names ATS3
>>> and ATS/Xanadu are often used interchangeably.
>>>
>>> In the ATS family of languages, the first implementation is named
>>> ATS/Proto (2004) and the language it implements is referred to as
>>> ATS0. Please note that the implementation of ATS/Proto is written in
>>> OCaml. The next implementation is ATS/Geizella (2007), which is also
>>> written in OCaml. And the language implemented by ATS/Geizella is
>>> referred to as ATS1. ATS/Anairiats (2008) is an implementation of ATS1
>>> in itself; the implementation is first compiled by ATS/Geizella and
>

Re: Current Status of ATS3 (2020-11-22)

2020-11-22 Thread Hongwei Xi
I will do a few examples today of co-programming with ATS3 and JS.

Conceptually, it is straightforward: ATS code is compiled to JS via xats2js
and the generated JS code can be directly combined with other JS code.
There is a very small library of JS code needed for running the generated
JS code.

In practice, it is equally straightforward :)

By the way, I would like to emphasize that xats2js is NOT meant to be an
optimizing compiler; it is more like a reference implementation of some
sort.
The JS code generated by xats2js is currently not of high quality in terms
of
efficiency (time-wise or memory-wise).

On Sun, Nov 22, 2020 at 12:38 PM Brandon Barker 
wrote:

> Hi Hongwei,
>
> That's exciting to hear. If and when they are available, could you point
> to any FFI examples or documentation for JavaScript? Perhaps, but not
> necessarily, related to DOM APIs in the browser (just as a common example)?
> On Sunday, November 22, 2020 at 9:31:16 AM UTC-5 gmhwxi wrote:
>
>>
>>
>> Hi, there,
>>
>> HX-2020-11-22:
>>
>> (*
>> HX-2018-04-07: Let us get started!!!
>> *)
>>
>> As of today, I am pleased to announce that ATS3 has reached a stage
>> where it can be realistically used in software construction. This is
>> achieved after slightly more than two and one-half years of continual
>> development by yours truly :)
>>
>> ##
>> #
>> # The current status
>> #
>> ##
>>
>> XATSOPT:
>>
>> Xatsopt is a functioning compiler implemented in ATS2 for translating
>> ATS3 into a typed intermediate language of the name XATSCML, which is
>> both C-like and ML-like. It is planned for xatsopt to further
>> translate XATSCML into XATSCL0, a low-level C-like language. I now
>> primarily see xatsopt as a library (libxatsopt) for implementing tools
>> to support programming with ATS3.
>>
>> XATS2JS:
>>
>> Xats2js is a functioning compiler implemented in ATS2 for translating
>> XATSCML into JavaScript (or JS for short). It should be noted that
>> xats2js can compile tail-recursive calls into local jumps, effectively
>> supporting the common practice in functional programming of writing
>> loops as tail-recursive functions.
>>
>> I will give detailed explanation elsewhere on using xats2js. Generally
>> speaking, one can now practice a form of co-programming with ATS3 and
>> JS. The JS code generated by xats2js from compiling ATS3 source can be
>> directly combined with other JS code (as if the generated code were
>> manually written in JS)
>>
>> ##
>> #
>> # Future Development
>> #
>> ##
>>
>> Documenting Xatsopt:
>>
>> This has been assigned a high priority. It is hoped that other
>> people interested in ATS3 can start developing tools for ATS3 after
>> a minimal amount of documentation on xatsopt is made available.
>>
>> Advanced Type-Checking:
>>
>> While one can specify with linear types and dependent types in ATS3,
>> there is no type-checking for such advanced types in xatsopt. I plan
>> to concentrate on implementing support for such type-checking in the
>> next phase of ATS3 development.
>>
>> ##
>> #
>> # A little history of ATS3
>> #
>> ##
>>
>> Essentially, ATS3 refers to the third edition of ATS, and ATS/Xanadu
>> is currently the only implementation of ATS3. Note that the names ATS3
>> and ATS/Xanadu are often used interchangeably.
>>
>> In the ATS family of languages, the first implementation is named
>> ATS/Proto (2004) and the language it implements is referred to as
>> ATS0. Please note that the implementation of ATS/Proto is written in
>> OCaml. The next implementation is ATS/Geizella (2007), which is also
>> written in OCaml. And the language implemented by ATS/Geizella is
>> referred to as ATS1. ATS/Anairiats (2008) is an implementation of ATS1
>> in itself; the implementation is first compiled by ATS/Geizella and
>> then by itself, succeeding in so-called bootstrapping. The next
>> edition of ATS is ATS2, which is given an implementation of the name
>> ATS/Postiats (2013) written in ATS1.
>>
>> ATS/Xanadu implements ATS3 and the implementation is written in ATS2.
>> While there is currently no plan to bootstrap ATS3 by implementing it
>> in itself, it is perceivable that ATS/Xanadu can be readily translated
>> (manually) into such an implementation since the difference between
>> ATS2 and ATS3 in terms of both syntax and semantics is fairly minor
>> (for the part being used in compiler implementation).
>>
>> ##
>>
>> Cheers!
>>
>> --Hongwei
>>
>> ##
>>
>> For previously post messages:
>>
>> https://github.com/githwxi/ATS-Xanadu/tree/master/docgen/NOTES
>> ##
>>
>>
>> --
> You received this message because you are subscribed to a topic in the
> Google Groups "ats-lang-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ats-lang-users/4Pb6GAuBiY4/unsubscribe.
> To 

Fwd: [ats-lang-users] ATS2-0.4.2 released

2020-11-14 Thread Hongwei Xi
FYI.

-- Forwarded message -

Hi,

It is my pleasure to announce the release
of ATS2-0.4.2. Note that this is the version
currently needed for compiling the ongoing
implementation of ATS3 (ATS/Xanadu).


ATS-Postiats-0.4.2.tgz:
The same as ATS-Postiats-int-0.4.2.tgz
MD5:
900c43b69f544ddff738ebf864f98b06
SHA1:
76b7c817c3439858e42c4ff74edc226578e0ea1b
--
ATS2-Postiats-gmp-0.4.2.tgz:
MD5:
e2f0f6c38868bb6b85f77fd1d9222b23
SHA1:
a869ba92d673082cd30fc6c2368d3948eef772fa
--
ATS2-Postiats-int-0.4.2.tgz:
MD5:
900c43b69f544ddff738ebf864f98b06
SHA1:
76b7c817c3439858e42c4ff74edc226578e0ea1b


This is the 53rd release of ATS2, the successor of the
ATS programming language. The compiler for ATS2 is given
the name ATS/Positats, ATS2/Postiats or simply Postiats.

The official website for ATS is:

http://www.ats-lang.org

ATS-Postiats is hosted at github:

https://github.com/githwxi/ATS-Postiats

Major releases of ATS2 are available at:

https://sourceforge.net/projects/ats2-lang/

Major releases of external packages for ATS2 are available at:

https://sourceforge.net/projects/ats2-lang-contrib/

Here is a list of major additions and changes since the last release:

There are only a few minor modifications, which are primarily
needed for compiling the current (2020-11-01) implementation of ATS3.

1. Fixing the handling of an issue causing the compiler crash:
the proof of the at-view of a local variable is not restored
at the end of its scope.
Please visit the following link for more details:
https://groups.google.com/g/ats-lang-users/c/f9QVilhHMEM

2. Fixing bug-2020-10-14
(for the omission of handling records when the exhaustiveness of
pattern matching is tested)
Kudos to Alex Dambaev for reporting it!

Please note that in this release, there are two variants of
the package released: The "gmp" variant depends on the GMP library and
the "int" variant does not depend on the GMP library. In this release
ATS2-Postiats-0.4.2.tgz is just the same as
ATS2-Postiats-int-0.4.2.tgz.

##

Cheers,

--Hongwei

Computer Science Department
Boston University
111 Cummington Street
Boston, MA 02215

Url: http://www.cs.bu.edu/~hwxi
Tel: +1 617 358 2511 (office)
Fax: +1 617 353 6457 (department)

___
ats-lang-users mailing list
ats-lang-us...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ats-lang-users

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLqqh46i7_UjVSqv1iGG5ejwj5m-X%2BAk-2613RSJt7Jncg%40mail.gmail.com.


Re: Building ATS that uses uint8

2020-10-23 Thread Hongwei Xi
The error message says that gint2uint is not implemented for the type uint8.
Of course, you can just implement it. Or you can just use the following
unsafe
approach to circumvent the issue:

#include "share/atspre_staload.hats"
#include "share/atspre_define.hats"

val
twelve =
$UNSAFE.cast(12): uint8(12)

implement main0 () = print!("twelve is ", twelve, "\n")


On Fri, Oct 23, 2020 at 5:36 PM Mark Barbone 
wrote:

>
> Hi all,
>
> I'm new to ATS, and trying to use the uint8 type.  However, when I do, I
> get long errors from GCC, involving PMVtmpltcstmat and friends:
> https://gist.github.com/mb64/eb9d194f3dedffd06d5cd075db316899
>
> The command I'm using to compile is:
> patscc -DATS_MEMALLOC_LIBC -o uint8_test uint8_test.dats
>
> How should I compile such a file using uint8?  Are there other files to
> #include, staload, or pass as command-line arguments?
> Or is my ATS installation completely borked?
>
> Thanks!
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/339ebe1e-8cd0-4192-a1ab-a66f24da36d1n%40googlegroups.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLoDYbKZ2h3RNE4uiEHzCNhjziJG7Lq_COP1n0Ya6h1ZGg%40mail.gmail.com.


Re: feature request: showing location of failed constraint

2020-10-17 Thread Hongwei Xi
Have already kept a note of this request.


On Fri, Oct 2, 2020 at 9:13 AM Dambaev Alexander 
wrote:

> Hi,
>
> I found, that it is difficult to locate constraint, that had been failed
> to be solved.
> For example, I got error message like this:
> ```
> /data/devel/ats2/bytestring/DATS/bytestring_flat.dats: 12395(line=442,
> offs=49) -- 12409(line=442, offs=63): error(3): unsolved constraint:
> C3NSTRprop(C3TKmain(); S2Eapp(S2Ecst(>=); S2EVar(5829), S2Eintinf(0)))
> ```
>
> which shows me where the constraint failed to be satisfied, but does not
> shows which constraint I need to debug.
> In this particular case, there are 11 lines of constraints for me and I
> required to be very careful to found which one had issue.
>
> I hope, that at least ATS3 will be able to provide location of constraint
> definition to debug
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CAHjn2KzZuP5E3yiaoaTVFSN9Wng-QGrWOMJjt_w0pf_eKePJLw%40mail.gmail.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLqdLxkjFYxAtKDx4705Ek4yV5Wj1rdTM3gZ5RZKDhjV_w%40mail.gmail.com.


Re: non-exhaustive pattern match in case+ expression

2020-10-17 Thread Hongwei Xi
Thanks for reporting it.

Finally got some time fixing this issue. Basically, records were not
handled. They are now handled.
The changes should go into the next release.

On Wed, Oct 14, 2020 at 5:48 AM Dambaev Alexander 
wrote:

> Hi,
> I have the following example:
> ```
> #include "share/atspre_define.hats"
> #include "share/atspre_staload.hats"
>
> #define ATS_DYNLOADFLAG 0
>
> implement main0() = {
>   val a = (Some_vt(0), None_vt())
>   val b =
> case+ a:(Option_vt(int), Option_vt(int)) of (* *9* *)
> | @( ~Some_vt(_), ~Some_vt(_)):(Option_vt(int), Option_vt(int)) => 0
> | @( ~Some_vt(_), ~None_vt()):(Option_vt(int), Option_vt(int)) => 1
> | @( ~None_vt(), ~Some_vt(_)):(Option_vt(int), Option_vt(int)) => 2
> | @( ~None_vt(), ~None_vt()):(Option_vt(int), Option_vt(int)) => 3 (*
> *13* *)
> }
> ```
> which produces the following error
> ```
> /data/devel/ats2/issue/main.dats: 172(line=9, offs=5) -- 503(line=13,
> offs=71): error(3): pattern match is nonexhaustive:
> @{0= Some_vt(_), 1= None_vt()}
> /data/devel/ats2/issue/main.dats: 172(line=9, offs=5) -- 503(line=13,
> offs=71): error(3): pattern match is nonexhaustive:
> @{0= None_vt()}
> typechecking has failed: there are some unsolved constraints: please
> inspect the above reported error message(s) for information.
> exit(ATS): uncaught exception:
> _2tmp_2ATS_2dPostiats_2src_2pats_error_2esats__FatalErrorExn(1025)
> ```
> I guess it is related to the same "weak type inference" thing, but type
> annotations are not helpful here. Replacing with '*case-*' helps, of
> course, but I would like to know how can I use case+ instead
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CAHjn2KzL02cZTA7CP_aWMet_Hk%2BtYkMxAAZgejcTjC3%2B36Y8ZA%40mail.gmail.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLrmyUxpzbuwsKF1b%3DCZN_kELm1iqxLenVN9R%2ByjhptX3Q%40mail.gmail.com.


Re: case expressions in let binding and dataviewtypes

2020-10-13 Thread Hongwei Xi
The support for type inference in ATS2 is weak.
Often you need a type annotation for a case-expression
(or an if-expression):

implement main0() = {
  val a = 0
  val b =
(
case+ a of
| 0 => Some_vt(0) *(* 9 *)*
| _ => None_vt()  *(* 10 *)*
) : Option_vt(int)
  val () =
case+ b of
| ~None_vt() => ()
| ~Some_vt(_) => ()
}

On Tue, Oct 13, 2020 at 10:09 AM Dambaev Alexander 
wrote:

> Hi,
>
> In this example, I am trying to define a binding of type Option_vt(int),
>
> ```
> #include "share/atspre_staload.hats"
>
> #define ATS_DYNLOADFLAG 0
>
> implement main0() = {
>   val a = 0
>   val b =
> case+ a of
> | 0 => Some_vt(0) *(* 9 *)*
> | _ => None_vt()  *(* 10 *)*
>   val () =
> case+ b of
> | ~None_vt() => ()
> | ~Some_vt(_) => ()
> }
> ```
> but I get the following error from the compiler:
> ```
> patscc -O2 -DATS_MEMALLOC_LIBC -I"../libs/" -o issue   main.dats
> /data/devel/ats2/issue/main.dats: 136(line=9, offs=12) -- 146(line=9,
> offs=22): error(3): the dynamic expression cannot be assigned the type
> [S2EVar(5243)].
> /data/devel/ats2/issue/main.dats: 136(line=9, offs=12) -- 146(line=9,
> offs=22): error(3): mismatch of sorts in unification:
> The sort of variable is: S2RTbas(S2RTBASimp(1; t@ype))
> The sort of solution is: S2RTbas(S2RTBASimp(2; viewtype))
> /data/devel/ats2/issue/main.dats: 136(line=9, offs=12) -- 146(line=9,
> offs=22): error(3): mismatch of static terms (tyleq):
> The actual term is: S2Eapp(S2Ecst(option_vt0ype_bool_vtype);
> S2Eapp(S2Ecst(g1int_int_t0ype); S2Eextkind(atstype_int), S2Eintinf(0)),
> S2Ecst(true_bool))
> The needed term is: S2EVar(5243)
> /data/devel/ats2/issue/main.dats: 158(line=10, offs=12) -- 167(line=10,
> offs=21): error(3): the dynamic expression cannot be assigned the type
> [S2EVar(5243)].
> /data/devel/ats2/issue/main.dats: 158(line=10, offs=12) -- 167(line=10,
> offs=21): error(3): mismatch of sorts in unification:
> The sort of variable is: S2RTbas(S2RTBASimp(1; t@ype))
> The sort of solution is: S2RTbas(S2RTBASimp(2; viewtype))
> /data/devel/ats2/issue/main.dats: 158(line=10, offs=12) -- 167(line=10,
> offs=21): error(3): mismatch of static terms (tyleq):
> The actual term is: S2Eapp(S2Ecst(option_vt0ype_bool_vtype); S2EVar(5245),
> S2Ecst(false_bool))
> The needed term is: S2EVar(5243)
> /data/devel/ats2/issue/main.dats: 200(line=13, offs=7) -- 210(line=13,
> offs=17): error(3): the constructor pattern cannot be assigned the type
> [S2EVar(5243)].
> /data/devel/ats2/issue/main.dats: 223(line=14, offs=7) -- 234(line=14,
> offs=18): error(3): the constructor pattern cannot be assigned the type
> [S2EVar(5243)].
> ```
> what is wrong with this example?
>
> Instead, this example is working:
> ```
> #include "share/atspre_staload.hats"
>
> #define ATS_DYNLOADFLAG 0
>
> implement main0() = {
>   val a = 0
>   val b =
> * f(a) where {fn f(a:int):<> Option_vt(int) =*
> case+ a of
> | 0 => Some_vt(0)
> | _ => None_vt()
>   }
>   val () =
> case+ b of
> | ~None_vt() => ()
> | ~Some_vt(_) => ()
> ```
> I have tried to reread the tutorial, but haven't found something related
> to this behavior
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CAHjn2KxcKRHMZxWkZZTqy7yQLLbx3LQ_FeTGrSn76xvXWh4%2BeQ%40mail.gmail.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLot_wFq%2BbqZT4PAUoUM8EEgv_N_uc1FMYb%3Dbn9fhDs%2BEg%40mail.gmail.com.


Re: performance considerations of patsopt

2020-10-04 Thread Hongwei Xi
In this case, the long time compilation of your ATS code is most likely
caused
by constraint-solving. You may try to use the following flag to skip
constraint-solving:

--constraint-ignore

This will tell you if constraint-solving is indeed the culprit here.

Using an external constraint-solver like Z3 may improve. However,
constraint-solving
is inherently of exponential-time.



On Sun, Oct 4, 2020 at 8:15 AM Dambaev Alexander 
wrote:

> Hi,
> I have noticed, that patsopt takes huge amount of time, to compile
> relatively small library https://github.com/dambaev/ats-bytestring
>
> ``
> [nix-shell:/data/devel/ats2/bytestring]$ $(which time) make test1
> patscc -O2 -DATS_MEMALLOC_LIBC -I"../libs/" -c -o SATS/bytestring_sats.o
> SATS/bytestring.sats
> patscc -O2 -DATS_MEMALLOC_LIBC -I"../libs/" -c -o
> DATS/bytestring_flat_dats.o DATS/bytestring_flat.dats
> patscc -O2 -DATS_MEMALLOC_LIBC -I"../libs/" -o test1
> SATS/bytestring_sats.o DATS/bytestring_flat_dats.o TEST/test1.dats
> 39.00user 0.43system *0:39.44*elapsed 99%CPU (0avgtext+0avgdata *215060*
> maxresident)k
> 0inputs+1024outputs (0major+140589minor)pagefaults 0swaps
> ```
>
> and one project, that uses this library take forever to compile:
>
> ```
> $ $(which time) make
> make -C src
> make[1]: Entering directory '/data/devel/smartplants/lora2mqtt/src'
> patscc -O2 -DATS_MEMALLOC_LIBC
> -I"/nix/store/cqynqsas6nwk3gbn8m2pi9lx4m0shr0y-ats2-0.3.13/lib/ats2-postiats-0.3.13/contrib/atscntrb/"
> -I"../libs/" -c -o DATS/logging_dats.o DATS/logging.dats
> /data/devel/smartplants/lora2mqtt/src/DATS/logging.dats: 3255(line=92,
> offs=24) -- 3255(line=92, offs=24): error(3): unsolved constraint:
> C3NSTRprop(C3TKmain(); S2Eapp(S2Ecst(>);
> S2EVar(5345->S2Evar(refcnt$8767$8777$8786$8794$8801$8807$8812$8816$8819(14823))),
> S2Eintinf(0)))
> ^Cmake[1]: *** [Makefile:71: DATS/logging_dats.o] Error 1
> make: *** [Makefile:2: all] Interrupt
> Command terminated by signal 2
> 202.80user 0.28system *3:23.13*elapsed 99%CPU (0avgtext+0avgdata *384768*
> maxresident)k
> 0inputs+0outputs (0major+97710minor)pagefaults 0swaps
>
> $ cat src/DATS/logging.dats | wc -l
> 120
> ```
> I had interrupted when the first error had been reported.
>
> What are the best practice to get reasonable performance of patsopt?
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CAHjn2KwdMZNSdJhtypDjpZyLDfqR2zZpca8LH-81UYyrk4UMzQ%40mail.gmail.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLoy0jdo884-_JD%3DmHLdad7ytsSiWg%2BMsGjp5iH9BM2Yng%40mail.gmail.com.


Re: changing the value of vtype

2020-10-03 Thread Hongwei Xi
By the way, if 'i' is call-by-value, then it cannot be updated. If it needs
to be updated,
then it cannot be call-by-value.


On Sun, Oct 4, 2020 at 1:01 AM Hongwei Xi  wrote:

> The following line caused the issue:
>
> val () = i := build( () | (len, offset, cap, i2sz 0, refcnt + i2sz 1,
> dynamic, p)) // restore i
>
> It should be changed to
>
> prval () = i := build( () | (len, offset, cap, i2sz 0, refcnt + i2sz 1,
> dynamic, p)) // restore i
>
> Only a linear proof call-by-value argument can be a left-value. So 'i' is
> treated as a proof,
> and its erasure is of the type 'void'.
>
>
> On Sat, Oct 3, 2020 at 11:32 PM Dambaev Alexander 
> wrote:
>
>> Hi,
>>
>> I have a viewtype, defined like this:
>> ```
>> absvt0ype
>>   Bytestring_vtype
>>   ( len:int (* size in bytes, which occupied by data *)
>>   , offset: int (* the offset from base pointer at which data of length
>> len starts *)
>>   , cap: int (* capacity of the buffer *)
>>   , ucap: int (* how much unused bytes of buffer available after this
>> bytestring *)
>>   , refcnt:int (* how many other bytestrings refer to this bytestring *)
>>   , dynamically_allocated: bool (* if false, then base pointer is
>> statically allocated *)
>>   , base: addr (* base pointer *)
>>   ) =
>>   ( void
>>   | ( size_t (* len *)
>> , size_t (* offset *)
>> , size_t (* capacity *)
>> , size_t (* available capacity *)
>> , size_t (* refcnt *)
>> , bool (* is dynamically allocated *)
>> , ptr
>> )
>>   )
>>
>> (* bytestring, which backend memory is not shared with other bytestrings
>> *)
>> vtypedef
>>   BytestringNSH0 =
>>   [len: nat][offset,cap,ucap:nat][dynamically_allocated:bool][l:agz]
>>   Bytestring_vtype( len, offset, cap, ucap, 0, dynamically_allocated,l)
>>
>> ```
>>
>> In many functions, I would like to modify argument's type and value in
>> order to modify reference count, the simplified example of usage is:
>> ```
>> fn
>>   test1(): $BS.BytestringNSH0 = bs1 where {
>>   val bs = $BS.pack "hello world"
>>   val bs1 = $BS.incref_bs bs
>>   // do some stuff like val bs2 = $BS.take( i2sz 2, bs1)...
>>   val () = $BS.decref_bs( bs, bs1) // consume bs and decref for bs1
>> }
>> ```
>> where incref_bs and decref_bs defined like this:
>> ```
>> fn
>>   decref_bs
>>   {c_len, c_offset, cap, c_ucap: nat}{dynamic:bool}{l:addr}
>>   {p_len, p_offset, p_ucap, p_refcnt: nat | *p_refcnt > 0*}
>>   ( consume: Bytestring_vtype( c_len, c_offset, cap, c_ucap, *1*,
>> dynamic, l) // consume bytestring with refcounter = 1
>>   , preserve: !Bytestring_vtype( p_len, p_offset, cap, p_ucap, *p_refcnt*,
>> dynamic, l) >> Bytestring_vtype( p_len, p_offset, cap, p_ucap, *p_refcnt
>> - 1*, dynamic, l) // and decrease refcounter for one, that should be
>> preserved
>>   ):
>>   void
>> fn
>>   incref_bs
>>   {len, offset, cap, ucap, refcnt: nat}{dynamic:bool}{l:addr}
>>   ( i: !Bytestring_vtype( len, offset, cap, ucap, *refcnt*, dynamic, l)
>> >> Bytestring_vtype( len, offset, cap, 0, *refcnt + 1*, dynamic, l) //
>> increase reference counter on original bytestring
>>   ):
>>   Bytestring_vtype( len, offset, cap, ucap, *1*, dynamic, l) // produce
>> the same string with refcount == 1
>> ```
>> and the implementation of incref_bs is (decref_bs is similar to it):
>> ```
>> implement incref_bs( i) = res where {
>>   extern castfn
>> explode
>> { len, offset, cap, ucap, refcnt:nat}{dynamic:bool}{l:addr}
>> ( i: Bytestring_vtype( len, offset, cap, ucap, refcnt, dynamic, l)
>> ):<> ( size_t(len), size_t(offset), size_t(cap), size_t(ucap),
>> size_t(refcnt), bool(dynamic) ptr(l))
>>   extern castfn
>> build
>> { len, offset, cap, ucap, refcnt:nat}{dynamic:bool}{l:addr}
>> ( void
>> | ( size_t(len), size_t(offset), size_t(cap), size_t(ucap),
>> size_t(refcnt), bool(dynamic), ptr(l) )
>> ):<> Bytestring_vtype( len, offset, cap, ucap, refcnt, dynamic, l)
>>   val (len, offset, cap, ucap, refcnt, dynamic, p) = explode(i) //
>> consume i
>>   val res = build( () | (len, offset, cap, ucap, i2sz 1, dynamic, p))
>>   val () = i := build( () | (len, offset, cap, i2sz 0, refcnt + i2sz 1,
>> dynamic, p)) // restore i
>> }
>> ```
>> this implementation typechecks, but C's generated code can't be compiled
>> with error:
>> ```
>>
>> /nix/store/

Re: changing the value of vtype

2020-10-03 Thread Hongwei Xi
The following line caused the issue:

val () = i := build( () | (len, offset, cap, i2sz 0, refcnt + i2sz 1,
dynamic, p)) // restore i

It should be changed to

prval () = i := build( () | (len, offset, cap, i2sz 0, refcnt + i2sz 1,
dynamic, p)) // restore i

Only a linear proof call-by-value argument can be a left-value. So 'i' is
treated as a proof,
and its erasure is of the type 'void'.


On Sat, Oct 3, 2020 at 11:32 PM Dambaev Alexander 
wrote:

> Hi,
>
> I have a viewtype, defined like this:
> ```
> absvt0ype
>   Bytestring_vtype
>   ( len:int (* size in bytes, which occupied by data *)
>   , offset: int (* the offset from base pointer at which data of length
> len starts *)
>   , cap: int (* capacity of the buffer *)
>   , ucap: int (* how much unused bytes of buffer available after this
> bytestring *)
>   , refcnt:int (* how many other bytestrings refer to this bytestring *)
>   , dynamically_allocated: bool (* if false, then base pointer is
> statically allocated *)
>   , base: addr (* base pointer *)
>   ) =
>   ( void
>   | ( size_t (* len *)
> , size_t (* offset *)
> , size_t (* capacity *)
> , size_t (* available capacity *)
> , size_t (* refcnt *)
> , bool (* is dynamically allocated *)
> , ptr
> )
>   )
>
> (* bytestring, which backend memory is not shared with other bytestrings *)
> vtypedef
>   BytestringNSH0 =
>   [len: nat][offset,cap,ucap:nat][dynamically_allocated:bool][l:agz]
>   Bytestring_vtype( len, offset, cap, ucap, 0, dynamically_allocated,l)
>
> ```
>
> In many functions, I would like to modify argument's type and value in
> order to modify reference count, the simplified example of usage is:
> ```
> fn
>   test1(): $BS.BytestringNSH0 = bs1 where {
>   val bs = $BS.pack "hello world"
>   val bs1 = $BS.incref_bs bs
>   // do some stuff like val bs2 = $BS.take( i2sz 2, bs1)...
>   val () = $BS.decref_bs( bs, bs1) // consume bs and decref for bs1
> }
> ```
> where incref_bs and decref_bs defined like this:
> ```
> fn
>   decref_bs
>   {c_len, c_offset, cap, c_ucap: nat}{dynamic:bool}{l:addr}
>   {p_len, p_offset, p_ucap, p_refcnt: nat | *p_refcnt > 0*}
>   ( consume: Bytestring_vtype( c_len, c_offset, cap, c_ucap, *1*,
> dynamic, l) // consume bytestring with refcounter = 1
>   , preserve: !Bytestring_vtype( p_len, p_offset, cap, p_ucap, *p_refcnt*,
> dynamic, l) >> Bytestring_vtype( p_len, p_offset, cap, p_ucap, *p_refcnt
> - 1*, dynamic, l) // and decrease refcounter for one, that should be
> preserved
>   ):
>   void
> fn
>   incref_bs
>   {len, offset, cap, ucap, refcnt: nat}{dynamic:bool}{l:addr}
>   ( i: !Bytestring_vtype( len, offset, cap, ucap, *refcnt*, dynamic, l)
> >> Bytestring_vtype( len, offset, cap, 0, *refcnt + 1*, dynamic, l) //
> increase reference counter on original bytestring
>   ):
>   Bytestring_vtype( len, offset, cap, ucap, *1*, dynamic, l) // produce
> the same string with refcount == 1
> ```
> and the implementation of incref_bs is (decref_bs is similar to it):
> ```
> implement incref_bs( i) = res where {
>   extern castfn
> explode
> { len, offset, cap, ucap, refcnt:nat}{dynamic:bool}{l:addr}
> ( i: Bytestring_vtype( len, offset, cap, ucap, refcnt, dynamic, l)
> ):<> ( size_t(len), size_t(offset), size_t(cap), size_t(ucap),
> size_t(refcnt), bool(dynamic) ptr(l))
>   extern castfn
> build
> { len, offset, cap, ucap, refcnt:nat}{dynamic:bool}{l:addr}
> ( void
> | ( size_t(len), size_t(offset), size_t(cap), size_t(ucap),
> size_t(refcnt), bool(dynamic), ptr(l) )
> ):<> Bytestring_vtype( len, offset, cap, ucap, refcnt, dynamic, l)
>   val (len, offset, cap, ucap, refcnt, dynamic, p) = explode(i) // consume
> i
>   val res = build( () | (len, offset, cap, ucap, i2sz 1, dynamic, p))
>   val () = i := build( () | (len, offset, cap, i2sz 0, refcnt + i2sz 1,
> dynamic, p)) // restore i
> }
> ```
> this implementation typechecks, but C's generated code can't be compiled
> with error:
> ```
>
> /nix/store/cqynqsas6nwk3gbn8m2pi9lx4m0shr0y-ats2-0.3.13/lib/ats2-postiats-0.3.13/ccomp/runtime/pats_ccomp_instrset.h:339:39:*
> error: invalid use of void expression*
>  #define ATSINSstore(pmv1, pmv2) (pmv1 = pmv2)
>^
> bytestring_flat_dats.c:5417:1: note: in expansion of macro ‘ATSINSstore’
>  ATSINSstore(ATSderef(arg0, atsvoid_t0ype), ATSPMVcastfn(build,
> postiats_tyrec_0, tmp311)) ;
> ```
> and the generated code for incref_bs is:
> ```
> /*
> local:
> global: incref_bs$80$0(level=0)
> local:
> global:
> */
> ATSextern()
> postiats_tyrec_0
> bytestring__incref_bs(*atsrefarg0_type*(postiats_tyrec_0) arg0)
> {
> /* tmpvardeclst(beg) */
> ATStmpdec(tmpret301, postiats_tyrec_0) ;
> ATStmpdec(tmp302, atstkind_t0ype(atstype_size)) ;
> ATStmpdec(tmp303, atstkind_t0ype(atstype_size)) ;
> ATStmpdec(tmp304, atstkind_t0ype(atstype_size)) ;
> ATStmpdec(tmp305, atstkind_t0ype(atstype_size)) ;
> ATStmpdec(tmp306, atstkind_t0ype(atstype_size)) ;
> ATStmpdec(tmp307, 

Re: Freestanding ATS

2020-10-03 Thread Hongwei Xi
In the past, I did use ATS2 to experiment with a kernel implementation:

https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/KernelBuilding

Basically, you can just use some compile-time flags to get rid of various
includes in the generated
C code. The following Makefile should be telling:

https://github.com/githwxi/ATS-Postiats-contrib/blob/master/projects/MEDIUM/KernelBuilding/singpolyma-kernel/Part1/Makefile

As for ATS3, I plan to support a scripting language for this kind of
configuration. Will do this very soon.


On Fri, Oct 2, 2020 at 9:10 PM Elronnd _  wrote:

> I'm trying to use ATS for OS development.  This means: no dependence on
> any feature of the host environment; nothing from libc.
>
> It looks like the parts of the prelude that implement basic types and
> language features are the same as the parts that interface with the host
> libc (for e.g. exit, malloc, etc.).  Is there something I'm missing?  If
> not, is there any chance official, integrated support can be added for a
> freestanding mode?  Happy to contribute on that count, FWIW; just want to
> gauge interest.
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/9bf84c7c-c99d-4c72-8cca-392e41106576o%40googlegroups.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLrQP-byQrkRvR9Sz6%2Bkx4xz2znr%3Dzr34P-cXtb9Zvd0iw%40mail.gmail.com.


Re: using #[] only for changing type of the argument's vtype

2020-09-28 Thread Hongwei Xi
I believe that #[...] must be at the leading position. Please try to change
each [...] to #[...].

On Mon, Sep 28, 2020 at 11:16 PM Dambaev Alexander 
wrote:

> Hi.
>
> I want to write a spec for a function 'append', which purpose is to append
> content of the second argument into the end of the content of the first one.
> I came to this:
> ```
> (* creates new bytestring with content of r appended to l. does not
> consumes l and r
>   in case if 'l' has enough unused capacity to fit 'r', it will copy
> content of 'r' into this unused space, incrementing reference counter of l
> and result
> *)
> fn
>   append
>   {l_len, l_offset, l_cap, l_ucap, l_refcnt: nat}{l_dynamic:bool}{l_p:addr}
>   {r_len, r_offset, r_cap, r_ucap, r_refcnt: nat}{r_dynamic:bool}{r_p:addr}
>   ( l: !Bytestring_vtype(l_len, l_offset, l_cap, l_ucap, l_refcnt,
> l_dynamic, l_p) >> Bytestring_vtype( l_len, l_offset, l_cap, *rl_ucap*,
> *rl_refcnt*, l_dynamic, l_p)
>   , r: !Bytestring_vtype(r_len, r_offset, r_cap, r_ucap, r_refcnt,
> r_dynamic, r_p)
>   ):
>   [reused_l: bool | (l_ucap >= r_len && reused_l == true) || reused_l ==
> false]
>   [offset:nat | (reused_l && offset == l_offset) || (reused_l == false &&
> offset == 0)]
>   [cap:nat | (reused_l && cap == l_cap) || (reused_l == false && cap ==
> l_len + r_len)]
>   [ucap:nat | (reused_l && ucap == l_ucap - r_len) || (reused_l == false
> && ucap == 0)]
>   *#[rl_ucap: nat | (reused_l && rl_ucap == 0) || (reused_l == false &&
> rl_ucap == l_ucap)]*
>   [refcnt:nat | (reused_l && refcnt == l_refcnt + 1) || (reused_l == false
> && refcnt == 0)]
>
> *#[rl_refcnt:nat | (reused_l && rl_refcnt == l_refcnt + 1) || (reused_l ==
> false && rl_refcnt == l_refcnt)]*  [dynamic:bool | (reused_l && dynamic
> == l_dynamic) || (reused_l == false && dynamic == true) ]
>   [l:addr | (reused_l && l == l_p) || (reused_l == false && l != l_p) ]
>   Bytestring_vtype( l_len+r_len, offset, cap, ucap, refcnt, dynamic, l)
> ```
> but compiler says, that I can't do it:
>
> ```
> /data/devel/ats2/bytestring/SATS/bytestring.sats: 6235(line=195, offs=3)
> -- 6765(line=200, offs=72): error(2): incorrect use of the existential
> quantifier #[...]
> /data/devel/ats2/bytestring/SATS/bytestring.sats: 6418(line=197, offs=3)
> -- 6765(line=200, offs=72): error(2): incorrect use of the existential
> quantifier #[...]
> /data/devel/ats2/bytestring/SATS/bytestring.sats: 5764(line=188, offs=129)
> -- 5771(line=188, offs=136): error(2): the static identifier [rl_ucap] is
> unrecognized.
> /data/devel/ats2/bytestring/SATS/bytestring.sats: 5773(line=188, offs=138)
> -- 5782(line=188, offs=147): error(2): the static identifier [rl_refcnt] is
> unrecognized.
> ```
> I guess, that rl_ucap and rl_refcnt have to be actually used in the type
> of the result, right?
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CAHjn2KwK0mE2DnApk9vMPkPZHGn3T0ELSyMr9pt4qDYc4hgiAw%40mail.gmail.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLr70JeoTC6fmesLpgYH1kfPyLA95p36p_XtecVbEijsGQ%40mail.gmail.com.


Re: spotted compiler assert failure

2020-09-28 Thread Hongwei Xi
I just modified the code base to issue an error message in this case
(instead of just reporting a line number of with a compiler crash).

On Mon, Sep 28, 2020 at 7:36 AM Hongwei Xi  wrote:

> >>I expected, that there will be typechecking error, saying, that  buf_pf
> is being preserved with wrong type, forcing me to restore it, but instead I
> got error above.
>
> I have seen this issue before.
>
> Basically. for each stack-allocated variable ('buf' in this case), there
> should be a proof of
> some at-view associated with the variable at the end of its life. In this
> case, the proof associated
> with 'buf' is turned into a proof of the view Bytestring_v, which is not
> an at-view (of the form T@l).
>
>
> On Mon, Sep 28, 2020 at 4:13 AM Dambaev Alexander 
> wrote:
>
>> Hi,
>> I got assert failure:
>> ```
>> exit(ATS): [assert] failed:
>> /tmp/ATS-Postiats/src/pats_trans3_env_dvar.dats: 14625(line=619, offs=20)
>> -- 14641(line=619, offs=36)
>> ```
>> from this code
>> SATS file:
>> ```
>> (* abstract viewtype, that describes Bytestring with capacity and size *)
>> absvt0ype
>>   Bytestring_vtype
>>   ( len:int (* size in bytes, which occupied by data *)
>>   , offset: int (* the offset from base pointer at which data of length
>> len starts *)
>>   , cap: int (* capacity of the buffer *)
>>   , ucap: int (* how much unused bytes of buffer available after this
>> bytestring *)
>>   , refcnt:int (* how many other bytestrings refer to this bytestring *)
>>   , dynamically_allocated: bool (* if false, then base pointer is
>> statically allocated *)
>>   , base: addr (* base pointer *)
>>   ) =
>>   ( void
>>   | ( size_t (* len *)
>> , size_t (* offset *)
>> , size_t (* capacity *)
>> , size_t (* available capacity *)
>> , size_t (* refcnt *)
>> , bool (* is dynamically allocated *)
>> , ptr
>> )
>>   )
>> (* abstract viewtype, that describes Bytestring with capacity and size *)
>> absvt0ype
>>   Bytestring_vtype
>>   ( len:int (* size in bytes, which occupied by data *)
>>   , offset: int (* the offset from base pointer at which data of length
>> len starts *)
>>   , cap: int (* capacity of the buffer *)
>>   , ucap: int (* how much unused bytes of buffer available after this
>> bytestring *)
>>   , refcnt:int (* how many other bytestrings refer to this bytestring *)
>>   , dynamically_allocated: bool (* if false, then base pointer is
>> statically allocated *)
>>   , base: addr (* base pointer *)
>>   ) =
>>   ( void
>>   | ( size_t (* len *)
>> , size_t (* offset *)
>> , size_t (* capacity *)
>> , size_t (* available capacity *)
>> , size_t (* refcnt *)
>> , bool (* is dynamically allocated *)
>> , ptr
>> )
>>   )
>> vtypedef
>>   Bytestring(len) =
>>   {len:
>> nat}[offset,cap,ucap,refcnt:nat][dynamically_allocated:bool][l:agz]
>>   Bytestring_vtype( len, offset, cap, ucap, refcnt,
>> dynamically_allocated,l)
>>
>> absview
>>   Bytestring_v(a:t0ype, len:int, offset:int, cap: int, ucap: int,
>> refcnt:int, dynamically_allocated:bool, l:addr)
>>
>> (* non-empty bytestring *)
>> vtypedef
>>   Bytestring1 =
>>   [len:
>> pos][offset,cap,ucap,refcnt:nat][dynamically_allocated:bool][l:agz]
>>   Bytestring_vtype( len, offset, cap, ucap, refcnt,
>> dynamically_allocated,l)
>>
>> fn
>>   pack_chars_static
>>   {n:nat}{l:agz}{a:t0ype}
>>   ( !array_v( a, l, n) >> Bytestring_v(a, n, 0, n, 0, 0, false, l)
>>   | i: ptr l
>>   , sz: size_t n
>>   ):
>>   Bytestring_vtype( n, 0, n, 0, 0, false, l)
>>
>> overload pack with pack_chars_static
>> ```
>> DATS file:
>> ```
>> #include "share/atspre_staload.hats"
>>
>> #define ATS_DYNLOADFLAG 0
>>
>> staload BS="SATS/bytestring.sats"
>> staload "DATS/bytestring_flat.dats"
>>
>> implement pack_chars_static{n}{l}{a}(pf | p, sz) =
>> let
>>   extern castfn
>> believeme
>> {n,offset,cap,ucap,refcnt:nat}{dynamic:bool}{l:agz}
>> ( !array_v( a, l, cap) >> Bytestring_v(a, n, offset, cap, ucap,
>> refcnt, dynamic, l)
>> | ( size_t(n)
>>   , size_t(offset)
>>   , size_t(cap)
>>   , size_t(ucap)
>>   , size_t(refcnt)
>>   , bool(dynamic)
>>   , ptr(l)
>>   )
>> ):<>
>> Bytestring_vtype(n, offset, cap, u

Re: symbol overloading resolution and statics

2020-09-27 Thread Hongwei Xi
Yes, that is correct. Overloading resolution
only uses type erasures (that is, types without indices) and arity
information.

BTW.

In ATS2, template resolution uses dependent types (that is, types with
indices)
to select template implementation. This caused a nightmare in terms of
usability :(
In ATS3, template resolution only uses type erasures.

--Hongwei


On Sun, Sep 27, 2020 at 4:32 AM Dambaev Alexander 
wrote:

> Hi,
>
> I have 2 functions:
> ```
> fn
>   free_static
>   {len, offset, cap: nat}{l:addr}
>   ( v: Bytestring_vtype(len, offset, cap, 0, *false*, l)
>   ): void
> fn
>   free_dynamic
>   {len, offset, cap: nat}{l:addr}
>   ( v: Bytestring_vtype(len, offset, cap, 0, *true*, l)
>   ): void
> ```
> where false means "not dynamic" and true - dynamic
> I was hoping, that this difference will be enough to differentiate those
> functions for overloading like this:
> ```
> symintr free
> overload free with free_static
> overload free with free_dynamic
> ```
> but compiler complains with:
> ```
> /data/devel/ats2/bytestring/TEST/test9.dats: 418(line=19, offs=12) --
> 428(line=19, offs=22): error(3): the symbol [$BS.free] cannot be resolved
> due to too many matches:
> D2ITMcst(free_dynamic) of 0
> D2ITMcst(free_static) of 0
> ```
> am I correct to assume, that in this case compiler is only looking on a
> type of arguments and arity of given alternatives to choose which function
> to resolve to?
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CAHjn2KyVjgjoXbX97ALw8R5HhaVhMyimrBqpuRBKgNGFSLH_Eg%40mail.gmail.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLrktgMRPTMoZo9am4BLe92Td6nk78e9oT3Hae56Q2UoZQ%40mail.gmail.com.


Re: resolving overloaded operators and staload

2020-09-24 Thread Hongwei Xi
Yes, you are correct.

An overload declaration in a package is available only when the package is
opened.

>>is it ok to have such 2 staloads or are there any other good practice to
staload only overloaded symbols? Maybe, there is a way to staload only some
of symbols (like in haskell's 'import' command like this:

Staloading is idempotent. It is totally okay to overload it multiple times.

I often just add the following line in the file where appendC is used:

overload + with $BS.appendC

Supporting haskell-like imports should be straightforward. Let me postpone
this until ATS3 is ready.

--Hongwei



On Thu, Sep 24, 2020 at 12:11 AM Dambaev Alexander 
wrote:

> Hi,
> I want to confirm what I see in practice:
> 1. I had defined abstract vtype Bytesting and overloaded '+' operator for
> it like this:
> ```
> (* the same as append, but consumes arguments in order to make caller's
> code clear from bunch of val's and free()
>  *)
> fn
>   appendC
>   {l_n, r_n, l_cap, r_cap: nat}
>   ( l: Bytestring(l_n, l_cap)
>   , r: Bytestring(r_n, r_cap)
>   ):
>   [res_cap: nat | res_cap >= l_n + r_n]
>   Bytestring( l_n+r_n, res_cap)
>
> overload + with appendC
> ```
> in the SATS file
>
> 2. I want to have an alias for symbols from this SATS file, so I am
> staloading it like this:
> ```
> staload BS="{$LIBS}/ats-bytestring/SATS/bytestring.sats"
> ```
> 3. but this is not enough to bring overloading of '+' into the scope and I
> have to add another staload:
> ```
> staload "{$LIBS}/ats-bytestring/SATS/bytestring.sats" (* for operator
> overloading in scope *)
> ```
>
> am I correct to assume, that I need the second staload to add overloading
> info into the global scope?
> Because without second staload, I can't write:
> ```
> val one = $BS.pack "one"
> val two = $BS.pack "two"
> val three = one + two (* failes to resolve + here without second staload *)
> ```
>
> is it ok to have such 2 staloads or are there any other good practice to
> staload only overloaded symbols? Maybe, there is a way to staload only some
> of symbols (like in haskell's 'import' command like this:
> ```
> import Data.ByteString (ByteString) -- imports only ByteString type into
> global scope
> import qualified Data.ByteString as BS -- the rest are being accessed only
> through alias BS
> ```
> )
>
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CAHjn2KyUefdSgSMyunE_QYDHCp1L6uUdRt-sbBKjWgWNKxHZJg%40mail.gmail.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLpn6PjWcoP49opMnwzL2q0BMT%2BHz3NWwFqfEtuO-pZSAw%40mail.gmail.com.


Re: How to avoid to return uninitialized value on ATS2?

2020-09-16 Thread Hongwei Xi
It works because the type for sbuf_bcat allows it:

val () = sbuf_bcat{elf_thrmisc_t}(pf_thrmisc | addr_thrmisc) // fails
val () = sbuf_bcat{elf_thrmisc_t?}(pf_thrmisc | addr_thrmisc) // succeeds


On Wed, Sep 16, 2020 at 3:10 AM Kiwamu Okabe  wrote:

> Dear all,
>
> I try to avoid following issue using ATS2:
>
> * Security Advisory:
> https://www.freebsd.org/security/advisories/FreeBSD-SA-20:03.thrmisc.asc
> * Patch
> https://github.com/freebsd/freebsd/commit/685a165c4c0b975cb2819b7042e1ddbc6eb79c5d
>
> This issue is caused by returning uninitialized value into user space
> from FreeBSD kernel.
> Then I wrote following pseudo code:
>
>
> https://github.com/metasepi/postmortem/blob/master/Security-Advisory/FreeBSD-kernel/FreeBSD-SA-20:03.thrmisc/Resolution/ATS2/error/main.dats
>
> Above code can't avoid this issue with at-view.
>
> * `!a? @ l >> a @ l` means to initialize uninitialized value
> * `!a @ l` means to take and keep initialized or uninitialized value
>
> How to explain to take "uninitialized value" as type?
>
> Best regards,
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CAEvX6d%3Dkyay10uEqkyzgJoWOYe-ToHGtLv08m2QREbp%2BbWLt-w%40mail.gmail.com
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLo2t6VD_-pTnzZXV0j18zmsP3gGc0z%3D5bcRdtfgA_TpHw%40mail.gmail.com.


Re: What is the difference between the two ways of declaring parameters?

2020-09-14 Thread Hongwei Xi
 >> fn add2 (x, y: int): int = x * x + y * y

ATS2 does very little of type-inference. Every argument of
a function needs to be given a type in principle.


On Mon, Sep 14, 2020 at 11:54 AM Timmy Jose  wrote:

>
> Suppose I have this simple function:
>
> fn add1 (x: int, y: int): int = x * x + y * y
>
> This works as expected.
>
> However, if I define the parameters so:
>
> fn add2 (x, y: int): int = x * x + y * y
>
> where I bunch up the parameters together, I get the following error (not a
> syntax error):
>
> 6| fn add2 (x, y: int): int = x * x + y * y
>   ^
>error: the symbol [*] cannot be resolved due to too many matches:
>   D2ITMcst(mul_size1_int1) of 22
>   D2ITMcst(mul_int1_size1) of 22
>
> 6| fn add2 (x, y: int): int = x * x + y * y
>   ^
>error: the symbol [+] cannot be resolved due to too many matches:
>   D2ITMcst(add_double_int) of 0
>   D2ITMcst(add_float_int) of 0
>
>error: the dynamic expression cannot be assigned the type
>   [g0int(# atstype_int)]
>
>error: mismatch of static terms (tyleq):
>   actual:  errexp
>   needed:  g0int(# atstype_int)
>
> patsopt(TRANS3): there are [3] errors in total.
>   exit(ATS): (1025)
>
> So what exactly is going on in this case? Is this not legal, or does this
> mean something else from what I'm using it as? Is this a  bug?
>
> Thanks!
>
> Timmy
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/7fbabd9c-fd3d-4cef-8a14-8e8a23f81257n%40googlegroups.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLqLgHf37qjnAYuX2%2BRzEw1fHd3bjckL-0HCkAP-hnwo9g%40mail.gmail.com.


Re: How to Free a Pointer to a viewt@ype

2020-09-02 Thread Hongwei Xi
The type-checker has quite a few limitations in handling existential
quantifiers.
Here is a way to circumvent the problem:

  implement
  mesh_delete( mpf, mpff | m ) =
  let
val m1 = !m
  in
arrayptr_free(m1.vap);
arrayptr_free(m1.tap);
ptr_free(mpff, mpf | m)
  end


  implement
  mesh_delete( mpf, mpff | m ) =
  let
val m1 = !m
  in
arrayptr_free(m1.vap);
arrayptr_free(m1.tap);
ptr_free(mpff, mpf | m)
  end



On Wed, Sep 2, 2020 at 11:04 PM d4v3y_5c0n3s  wrote:

> So, I've got the following code:
> absvt@ype mesh
>
> assume mesh =
> [v,t:int]
> [vl,tl:addr]
> @{
>   v=int v, t=int t, vap=arrayptr(vertex, vl, v), tap=arrayptr(uint32, tl,
> t)
> }
>
> fun mesh_delete {l:addr} ( mpf: mesh @ l, mpff: mfree_gc_v(l) | m: ptr l )
> : void = "sta#%"
>
> implement mesh_delete ( mpf, mpff | m ) =
> (
>   arrayptr_free(!m.vap);
>   arrayptr_free(!m.tap);
>   ptr_free(mpff, mpf | m)
> )
>
> However, I'm getting the following error:
> patscc -tcats /home/tmj90/Goldelish-Engine/source/g_engine.dats
> /home/tmj90/Goldelish-Engine/source/g_engine.dats: 69182(line=2426,
> offs=18) -- 69185(line=2426, offs=21): error(3): the dynamic expression
> cannot be assigned the type [S2Eat(S2EVar(7167), S2Evar(l$3392(8793)))].
> /home/tmj90/Goldelish-Engine/source/g_engine.dats: 69182(line=2426,
> offs=18) -- 69185(line=2426, offs=21): error(3): mismatch of sorts in
> unification:
> The sort of variable is: S2RTbas(S2RTBASimp(1; t@ype))
> The sort of solution is: S2RTbas(S2RTBASimp(3; viewt0ype))
> /home/tmj90/Goldelish-Engine/source/g_engine.dats: 69182(line=2426,
> offs=18) -- 69185(line=2426, offs=21): error(3): mismatch of static terms
> (tyleq):
> The actual term is: S2Etyrec(flt0; npf=-1; v=S2Eapp(S2Ecst(int);
> S2Evar(v$10840(16813))), t=S2Eapp(S2Ecst(int); S2Evar(t$10841(16814))),
> vap=S2Ecst(ptr_type), tap=S2Ecst(ptr_type))
> The needed term is: S2EVar(7167)
>
> I can allocate a pointer to mesh using ptr_alloc just fine, so why is
> ptr_free not working?  Do I need to get rid of the view to deallocate,
> perhaps using unsafe casting/functions?  Any help is appreciated, and if
> you'd like to see more of the code then please, ask me,
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/3a5cd9b9-2ef3-4d32-8513-a4e952c09d26n%40googlegroups.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLqLgv-Dbez04yHHyd1bH5HdTJTE%3Dt%2BXdUvQVQTThL9cuA%40mail.gmail.com.


Re: Solving compiler error

2020-08-31 Thread Hongwei Xi
*'#include' means copy/paste. It is not meant to be used*

*in the following manner:*

*```glib-ext.sats*


*#include "contrib/glib/SATS/glib.sats"#include
"contrib/glib/SATS/glib-object.sats" (* staloads glib.sats *)*
*```*

*You can create glib-ext.hats containing the following lines:*


*#staload "contrib/glib/SATS/glib.sats"#staload
"contrib/glib/SATS/glib-object.sats" (* staloads glib.sats *)*

*Then add the following line*


*#include "glib-ext.hats"*

*This allows you to staload both glib.sats and glib-object.sats*

*Here is a real example:*

*https://github.com/githwxi/ATS-Postiats/blob/master/share/HATS/atspre_staload_prelude.hats
*


*By the way, '#staload' is idempotent. Staloading a file multiple times
causes NO problems:*

*#staload "contrib/glib/SATS/glib.sats"*
*#staload "contrib/glib/SATS/glib.sats"*



On Mon, Aug 31, 2020 at 5:30 AM Dambaev Alexander 
wrote:

> *Kiwamu: *wow, thanks for your trust, but after my quick view of your
> wiki page
> http://jats-ug.metasepi.org/doc/ATS2/ATS_Foundations/showtype.html and at
> the moment, I don't think, that I can add much more to it
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *Hongwei: thanks, you are right. glib's bindings provide 2 separate SATS
> files: glib.sats and glib-object.sats, so I created a sats file, in which I
> had included those 2 SATS files with '#include' pragma and used this one
> sats file for staloading. I wanted to get this:```main.datsstaload
> GLIB="glib-ext.sats"(* $GLIB.glib1 available here *)(* $GLIB.glib2
> available here *)``glib-ext.sats#include
> "contrib/glib/SATS/glib.sats"#include "contrib/glib/SATS/glib-object.sats"
> (* staloads glib.sats *)``contrib/glib/SATS/glib.satsfn
> glib1():void``contrib/glib/SATS/glib-object.satsfn glib2():void``` So
> for now I have to staload them both in all modules, in which I need to use
> declarations from both. As far as I understand, there is no other way to
> achieve the same case without using #include pragma, am I right?Other than
> that, is it ok for compiler to not to throw an error of multiple
> declarations of gpointer?*
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CAHjn2KxAnsELa38_HvB49_YY2LmUOj6RVhbkc8oC3LXSJ6ubBg%40mail.gmail.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLr8RT%3DV5ocOuBd%2BVdGA9sXtNT73n4trGnce2G9WR6ckKw%40mail.gmail.com.


Re: Solving compiler error

2020-08-30 Thread Hongwei Xi
This means that gpointer is declared more than once in your code.
You need to check various 'staload' declarations in your code.

On Sun, Aug 30, 2020 at 9:47 PM Dambaev Alexander 
wrote:

> Hi
> Usually, I am able to parse and solve compiler errors, but now I need help:
>
> ```
>   macdef GSIGNAL_CANCELLED = $extval( $GLIB.gsignal, "cancelled")
>   fn foo( p: $GLIB.gpointer): void = ()
>   val p = $GLIB.gpointer the_null_ptr
>   prval _ = $showtype p
>   val _ = $GLIB.g_signal_connect( cancellable, GSIGNAL_CANCELLED,
> $GLIB.G_CALLBACK(foo), p)
> }
> ```
>
> I get:
>
> ```
> **SHOWTYPE[UP]**(/data/devel/cacaoweb/folders/libfm/base/DATS/folders.dats:
> 664(line=31, offs=23) -- 665(line=31, offs=24)): S2Ecst(gpointer):
> S2RTbas(S2RTBASimp(0; type))
> /data/devel/cacaoweb/folders/libfm/base/DATS/folders.dats: 755(line=32,
> offs=90) -- 756(line=32, offs=91): error(3): the dynamic expression cannot
> be assigned the type [S2Ecst(gpointer)].
> /data/devel/cacaoweb/folders/libfm/base/DATS/folders.dats: 755(line=32,
> offs=90) -- 756(line=32, offs=91): error(3): mismatch of static terms
> (tyleq):
> The actual term is: S2Ecst(gpointer)
> The needed term is: S2Ecst(gpointer)
> ```
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CAHjn2KxgmRqw9vsZKdTAh6ygegsEKb8mQhPgN9zXepGAR8QJOg%40mail.gmail.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLpwni%3DNDOgJRVio6iq8QmCooy%2B5PYicacRGPdVWPraxJw%40mail.gmail.com.


Re: How to assign a `shared` value onto a member of vtype?

2020-08-29 Thread Hongwei Xi
Well, you did not prove that the one returned is the same as the one
borrowed :)


On Sat, Aug 29, 2020 at 9:05 PM Kiwamu Okabe  wrote:

> Dear Hongwei,
> thank you for your reply.
>
> On Sat, Aug 29, 2020 at 11:05 PM Hongwei Xi  wrote:
> > In the following code, the proof of the view associated with opts is
> > stored in inp.sh. This proof needs to be taken out and put back into
> view@opts
> > before the function main0 can exit.
> >
> > implement main0 () = let
> > var opts: ip6_pktopts
> > var inp: inpcb
> > val () = inp.in6p_outputopts := addr@opts
> > val () = inp.sh := shared_make(view@opts | addr@opts)
> >   in
> > ignoret(usleep(1000u))
> >   end
>
> So I think I miss-understanded `ignoret`.
> Then I tried to use `shared_unref` to return `view@opts`.
> But the code causes the other error:
>
>
> https://github.com/metasepi/postmortem/commit/cb97cf86f5cdb766b7b6123db674f58b95ed793c
>
> ```ats
> implement main0 () = let
> var opts: ip6_pktopts
> var inp: inpcb
> val () = inp.in6p_outputopts := addr@opts
> val () = inp.sh := shared_make(view@opts | addr@opts)
> val (pf_oopts | x, count) = shared_unref(inp.sh)
> val () = assertloc(count <= 1)
> prval Some_v(pf_opts) = pf_oopts
> prval () = view@opts := pf_opts
>   in
> ignoret(usleep(1000u))
>   end
> ```
>
> ```
> $ patscc -D_GNU_SOURCE -DATS_MEMALLOC_LIBC main.dats -lpthread
> ../main.dats: 2867(line=106, offs=16) -- 2887(line=106, offs=36):
> error(3): viewat-restoration cannot be performed: mismatch of bef/aft
> locations of atviews:
> bef: [S2Evar(opts(8626))]
> aft: [S2Evar(l$8797$8799(14588))]
> ```
>
> Are `view@opts` and return from `shared_unref` not the same?
>
> Best regards,
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CAEvX6d%3DGfoVn7yJveTeiKpmOd0Kz%2Bkn_nCHQf3kfQJ-JkRtprw%40mail.gmail.com
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLp5dtGpg%3DdkML6ZjVcKp91hCAGKBDNFd5aDtCXHi%3Dbm%3Dw%40mail.gmail.com.


Re: How to assign a `shared` value onto a member of vtype?

2020-08-29 Thread Hongwei Xi
In the following code, the proof of the view associated with opts is
stored in inp.sh. This proof needs to be taken out and put back into
view@opts
before the function main0 can exit.

implement main0 () = let
var opts: ip6_pktopts
var inp: inpcb
val () = inp.in6p_outputopts := addr@opts
val () = inp.sh := shared_make(view@opts | addr@opts)
  in
ignoret(usleep(1000u))
  end

On Sat, Aug 29, 2020 at 4:31 AM Kiwamu Okabe  wrote:

> Dear all,
>
> There is a security issue on FreeBSD:
>
> * Security Advisory:
> https://www.freebsd.org/security/advisories/FreeBSD-SA-20:20.ipv6.asc
> * The patch:
> https://github.com/freebsd/freebsd/commit/5707de0ed806712f53752acd433313a39f63f15c
>
> I'm writing following ATS code to try to avoid the issue:
>
>
> https://github.com/metasepi/postmortem/blob/master/Security-Advisory/FreeBSD-kernel/FreeBSD-SA-20:20.ipv6/Resolution/ATS2/error/main.dats
>
> But the code causes following error:
>
> ```
> $ patscc -D_GNU_SOURCE -DATS_MEMALLOC_LIBC main.dats -lpthread
> .../FreeBSD-SA-20:20.ipv6/Resolution/ATS2/error/main.dats:
> 2574(line=98, offs=22) -- 2764(line=105, offs=6):
> error(3): the linear dynamic variable [opts$view$5659(-1)] is
> preserved but with an incompatible type.
> ```
>
> How to assign a `shared` value onto a member of vtype?
>
> Best regards,
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CAEvX6d%3DDxDQ4hNty%3DXA6t12Ge2LDuMQpv7C_wRLNsXUY_-t78w%40mail.gmail.com
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLogy7PexTYTuNpYsyzPxAP0UuGy19HHeRRw9oYOWC_CmA%40mail.gmail.com.


Re: Segmentation fault in Braun Tree example (modified)

2020-08-20 Thread Hongwei Xi
When I encounter a segfault, it is usually caused by recursion depth being
over some kind of limit.

In your code, the 'aux' function is defined but never called. Here is a
fixed version:

fun
{a: t@ype}
brauntest1 (t0: tree a): bool =
  let exception Negative of ()
  fun aux (t0: tree a): bool =
case+ t0 of
  | tree_nil () => true
  | tree_cons (tl, _, tr) =>
  let val szl = size (tl)
  val szr = size (tr)
  in
if abs (szl - szr) > 1 then $raise Negative ()
  else aux(tl) andalso aux(tr)
  end
  in
try aux(t0) with ~Negative () => false
  end

On Thu, Aug 20, 2020 at 6:46 AM Timmy Jose  wrote:

>
>
> Hi,
>
> I have a variation of the Braun Tree test (where the size of the left and
> right subtrees differ by at most 1 at every level) from the tutorials, and
> this one, for some reason gives a segmentation fault.
>
> Here is the snippet:
>
> fun
> {a: t@ype}
> brauntest1 (t0: tree a): bool =
>   let exception Negative of ()
>   fun aux (t0: tree a): bool =
> case+ t0 of
>   | tree_nil () => true
>   | tree_cons (tl, _, tr) =>
>   let val szl = size (tl)
>   val szr = size (tr)
>   in
> if abs (szl - szr) > 1 then $raise Negative ()
>   else brauntest1 (tl) andalso brauntest1 (tr)
>   end
>   in
> try brauntest1 (t0) with ~Negative () => false
>   end
>
> And here is the output from `lldb` (gdb has some code-signing issues on
> macOS).
>
> $ lldb braun
> (lldb) target create "braun"
> Current executable set to 'braun' (x86_64).
> (lldb) r
> Process 28137 launched: '/braun' (x86_64)
> Process 28137 stopped
> * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS
> (code=2, address=0x7ffeef3fff68)
> frame #0: 0x00011577 braun`brauntest1_3__3__1 + 39
> braun`brauntest1_3__3__1:
> ->  0x11577 <+39>: callq  0x11c3a   ; symbol stub for:
> setjmp
> 0x1157c <+44>: testl  %eax, %eax
> 0x1157e <+46>: je 0x115de   ; <+142>
> 0x11580 <+48>: movq   0xb31(%rip), %rcx ;
> my_atsexnframe_getref.my_atsexnframe
> Target 0: (braun) stopped.
> (lldb)
>
> Anybody seen this before, or have an idea what might be going wrong?
>
> Thanks!
>
> Timmy
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/ad557181-8986-4784-a724-2f2bba9cd5d9n%40googlegroups.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLqhKexD7BhuSSGF9EUZ9cqz%2BZJ-nWg-2s1Tz7JeZWFwMA%40mail.gmail.com.


Re: A small query about closures

2020-08-11 Thread Hongwei Xi
The following header:

fn
linum (): void - void =

should be changed to

fn
linum (): () - void =

But this does not give what you expected.

You could use a reference:

fn
linum (): () - void=
let
val
line = ref(0)
in
lam () =>
let
val () = !line := !line + 1
in
println! ("Current line number = ", !line);
end
end

implement
main0() =
{
val f0 = linum()
val () = f0()
val () = f0()
val f1 = linum()
val () = f1()
val () = f1()
}


On Tue, Aug 11, 2020 at 10:10 AM Timmy Jose  wrote:

> Hello,
>
> I have a small closure implementation in Rust which looks like so:
>
> fn linum() -> impl FnMut() {
> let mut line = 0;
>
> Box::new(move || {
> line = line + 1;
> println!("Current line number is {}", line);
> })
> }
>
> fn main() {
> let mut l = linum();
> for _ in 0..5 {
> l();
> }
>
> l = linum();
> for _ in 0..5 {
> l();
> }
> }
>
> Basically, I simply want to capture the line variable in my closure.
> Running it:
>
> $ rustc linum.rs && ./linum
> Current line number is 1
> Current line number is 2
> Current line number is 3
> Current line number is 4
> Current line number is 5
> Current line number is 1
> Current line number is 2
> Current line number is 3
> Current line number is 4
> Current line number is 5
>
> as expected. Now, I was trying to replicate this behaviour in ATS (please
> note that I am totally new to ATS) using the chapter on functions, and this
> was my attempt:
>
> fn
> linum (): void - void=
>   let val line = 0
>   in
>lam () =>
>   let val line = line + 1
>   in
>println! ("Current line number = ", line);
>   end
>   end
>
> which gives the following errors:
>
> $ make
> acc pc -DATS_MEMALLOC_LIBC -O3 -o closures closures.dats
>
> /Users/z0ltan/dev/study/ats/introduction_to_programming_in_ats/revision/chapter3/closures.dats:
> 12:4-16:10
>
>error(3): dynamic arity mismatch: more arguments are expected.
>
> patsopt(TRANS3): there are [1] errors in total.
>   exit(ATS): (1025)
> make: *** [closures] Error 1
>
> Can someone help me understand what the problem is? I'm pretty sure my
> knowledge of ATS is not enough right now to maybe fully implement this the
> way I want it, but I would like some pointers on this error message and
> maybe a nudge in the right direction to be able to implement this!
>
> Thanks!
>
> Best Regards,
>
> Timmy
>
> (P.S: I hope it's all right if I keep posting questions every so often? I
> tried the IRC channel, but it appears to be inactive. Please let me know
> otherwise, in which case I'll bunch up my questions after having finished
> the basic tutorials!).
>
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/92bd27f3-5d34-48dc-ac71-b9924ec58b4dn%40googlegroups.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLrBOjAAEjptkwTu5o0UXVhMhdHkf%2B7jQGfWPDB%2Bj6b06w%40mail.gmail.com.


Re: Structural typing in ATS?

2020-08-08 Thread Hongwei Xi
Yes. But datatypes are nominal.

Often one uses abstract types to hide information. For example,

abst@ype Point2D

#extern
fun Point2D_get_x(Point2D): double

local

absimpl
Point2D = @{x=double,y=double}

in

implement Point2D_get_x(p) = p.x

end


On Sat, Aug 8, 2020 at 11:33 AM Timmy Jose  wrote:

>
> Hello,
>
> I was trying out some experiments as part of my learning process. The
> small program below typechecks and runs correctly:
>
> typedef
> point2D = @{ x = double, y = double }
>
> typedef
> coord = @{ x = double, y = double }
>
> fn
> display_point (name: string, p: point2D): void =
>   (println! ("[", name , "] x = ", p.x, "y = ", p.y))
>
> implement main0 () = {
>   val origin = @{ x = 0.0, y = 0.0 }: point2D
>   val () = display_point ("origin", origin)
>   val () = println! ("x = ", origin.x, ", y = ", origin.y)
>
>   val coord0 = @{ x = 0.0, y = 0.0 }: coord
>   val () = display_point ("coord0", coord0)
> }
>
> So I'm assuming that typing in ATS is structural instead of nominative
> since the `display_point` functions works for both `point2D` and `coord`
> values?
>
> Just wanted to confirm this. Thanks!
>
> Best,
>
> Timmy
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/0d2e897a-5693-40f8-b268-60da5b71ac26n%40googlegroups.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLrn_hDuaYvnWygByVgdBodvy-_qd8J6V-KHpBCdLOR9KQ%40mail.gmail.com.


Re: The current status of ATS3

2020-08-05 Thread Hongwei Xi
  >>1. Will ATS3 syntax and semantics diverge significantly from ATS2? (It
looks like it's mostly going to be similar, but please correct me if I'm
wrong), and

The syntax of ATS3 is very similar to that of ATS2.

Here is some code in ATS3:

https://github.com/xanadu-lang/xinterp/tree/master/srcgen/TEST

I would say that ATS2 and ATS3 share 95% of the syntax or more.

  2. Will there be an added focus on making ATS a production-capable
language with ATS3? (Again, looks to be the case from what I could figure
out, but please correct me again!)

Certainly. To program is to program productively. If we just talk about
using ATS with emacs (or other editors) to produce C (or JS) code of
quality, it won't take too
long. If we talk about an IDE of some sort, I don't feel I have the energy
and/or the expertise. But hopefully others may.

When compared to C, ATS2 and ATS3 use the same data representation (for
values of datatypes). As a consequence, the C code generated by ATS2 is
compatible with the C code generated by ATS3. Not only your learnings but
also your code can be carried forward :)

Cheers!

--Hongwei


On Wed, Aug 5, 2020 at 9:56 AM Timmy Jose  wrote:

> Hello all,
>
> I am learning the ATS language right now, and have a couple of questions:
>
>   1. Will ATS3 syntax and semantics diverge significantly from ATS2? (It
> looks like it's mostly going to be similar, but please correct me if I'm
> wrong), and
>   2. Will there be an added focus on making ATS a production-capable
> language with ATS3? (Again, looks to be the case from what I could figure
> out, but please correct me again!)
>
> I have a vested interest in asking these questions - as you yourselves
> acknowledge, the learning curve is not very smooth, but I'm enjoying it so
> far, and have hopes of using it as a production language in the near
> future, or at least for some serious projects. I just want to make sure
> than my learnings from
> ATS2 will carry forward as much as possible! :-)
>
> Best Regards,
>
> Timmy
>
> On Thursday, July 9, 2020 at 10:11:23 PM UTC+5:30 zuercher...@outlook.com
> wrote:
>
>>
>>
>> On Friday, July 3, 2020 at 8:03:08 AM UTC-5, Matthias Wolff wrote:
>>>
>>> C++ templates restricted to functions show only one half oft the truth.
>>>
>>> template
>>> struct function;
>>>
>>> struct XXX;
>>>
>>> template<>
>>> struct function {
>>>
>>> template
>>> void operator()(std::ostream& s, const A&... a) {
>>>(s  << ... << a);
>>> }
>>> };
>>>
>>> struct YYY;
>>>
>>> template<>
>>> struct function {
>>>
>>> template
>>> void operator()(const A&... a) {
>>>(s td::cout << ... << a
>>> );
>>> }
>>> };
>>>
>>> int main()
>>> {
>>>
>>> //using function object - additional constructor parenthesis
>>> function()(std::cout,"a",1);
>>>
>>> function()(1,"a");
>>>
>>> return 0;
>>>
>>> }
>>>
>>> Template power in c++ starts with structs or classes and templated
>>> normal functions
>>> are often used to redirect the call to templated structs and their
>>> specializations. Where
>>> structs/classes may have many also templated methods and many inner
>>> classes and
>>> yes a function - I think - can have inner structs:
>>>
>>> void my_function()
>>> {
>>> struct abc { void print() { std::cout << "ok" << std::endl; } };
>>>
>>> abc().print();
>>> }
>>> Variadic templates are really powerful "template struct
>>> mystruct" and next
>>> template type deduction.
>>>
>>> Template are not a weak point in C++. But if you look in direction of
>>> category theory, one can
>>> very quickly recognize, that this topic is a black hole. C++ has no
>>> mathematical inspiration
>>>
>>
>> Prior to Stroustrup's work on concept maps in concepts, C++ templates'
>> inspiration was almost entirely a proper subset of Ada generics (but
>> without Ada's option of shared implementation of machine code among all
>> expansions/type-instantiations).  C++ concepts without concept-maps has no
>> feature of which I am aware that Ada generics have not already had for
>> since either 1983 or 1995 editions of the Ada language.  The history of C++
>> prior to C++11 is almost entirely a multidecade critique of Ada:  C++ as
>> Ada done right was the mantra (which might be factually correct if
>> restricting* Ada to only Ada83 which was rather half-baked, because Ada95,
>> Ada2005, and especially Ada2012 are better examples of the Ada school of
>> thought done right—and they differ quite substantially in their definition
>> of “Ada done right” that C++'s definition of “Ada done right”).
>>
>> * The vast majority of DoD & aerospace usage of Ada in 2020 (i.e., what
>> remains extant in production, not transliterated into either Java or C++
>> with the historic Ada implementation abandoned) is strictly limited to
>> Ada83, prohibiting all later features, which is why AdaCore and other Ada
>> compiler vendors charge a premium for 

Re: error messages

2020-08-03 Thread Hongwei Xi
By the way, an ifcase-expression should be used in place of the
case-expression
in your code. Also, I would like to point out that templates are a shining
feature of ATS :)

##

datatype
bstree(a:t@ype) =
| E of ()
| B of (bstree(a), a, bstree(a))

fun
{a:t@ype}
bstree_search
(
 t0: bstree(a),
 k0: a
) : bool =
case+ t0 of
| E () => false
| B (t1, k, t2) =>
  let
  val sgn =
  gcompare_val_val(k0, k)
  in
  ifcase
  | sgn < 0 => bstree_search (t1, k0)
  | sgn > 0 => bstree_search (t2, k0)
  | _ (* else *) => true
  end


On Mon, Aug 3, 2020 at 10:43 AM Hongwei Xi  wrote:

> There is a COMMA following 'false' that should be removed.
>
> BTW, the syntax of ATS is heavily influenced by Standard ML.
>
> On Mon, Aug 3, 2020 at 10:21 AM Timmy Jose  wrote:
>
>>
>> Hello,
>>
>> I've been trying to learn ATS from the official tutorials, and while I
>> like the language so far, and think that it is quite logical (if different
>> from many other languages in the same categories),  one thing that keeps
>> annoying me is getting some strange error messages.
>>
>> For instance, why is this a problem:
>>
>> fun
>> bstree_search (
>>   t0: bstree,
>>   k0: string
>> ): bool =
>> case+ t0 of
>>   | E () => false,
>>   | B (t1, k, t2) =>
>> let val sgn = compare (k0, k)
>> in case+ 0 of
>>   | _ when sgn < 0 => bstree_search (t1, k0)
>>   | _ when sgn > 0 => bstree_search (t2, k0)
>>   | _ => true
>> end
>>
>> I would expect that the return types of all sub-expressions are `void`
>> anyway, so why does the compiler complain:
>>
>> $ patscc -DATS_MEMALLOC_LIBC -o bst bst.dats && ./bst
>> /Users/z0ltan/dev/study/ats/introduction_to_programming_in_ats/chapter4/bst.dats:
>> 1022(line=53, offs=22) -- 1023(line=53, offs=23): error(parsing): the token
>> is discarded.
>> /Users/z0ltan/dev/study/ats/introduction_to_programming_in_ats/chapter4/bst.dats:
>> 1096(line=56, offs=9) -- 1098(line=56, offs=11): error(parsing): the token
>> is discarded.
>> exit(ATS): uncaught exception:
>> _2home_2hwxi_2Research_2ATS_2dPostiats_2src_2pats_error_2esats__FatalErrorExn(1025)
>>
>> The ATS FAQ recommends wrapping expressions with parentheses for such
>> errors, but doing so in this case does not get rid of the errors, and
>> secondly why is that even needed?
>>
>> Right now, this is the biggest thing that keeps tripping me up -
>> seemingly random "token discarded" error messages as well as some strange
>> "} keyword needed" error message etc. Experimenting randomly seems to fix
>> them most times, but is there any reason to this madness?
>>
>> Can anyone give me general guidelines to avoid seeing these sort of
>> trivial errors?
>>
>> Best,
>>
>> Timmy
>>
>> --
>> 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-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ats-lang-users/71b5daaa-c80b-42d6-983a-72d8ab59b0ean%40googlegroups.com
>> <https://groups.google.com/d/msgid/ats-lang-users/71b5daaa-c80b-42d6-983a-72d8ab59b0ean%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLp869w2YMiaheMAranfUTk2s4ei9sdC_Y9zDvaRN1374Q%40mail.gmail.com.


Re: error messages

2020-08-03 Thread Hongwei Xi
There is a COMMA following 'false' that should be removed.

BTW, the syntax of ATS is heavily influenced by Standard ML.

On Mon, Aug 3, 2020 at 10:21 AM Timmy Jose  wrote:

>
> Hello,
>
> I've been trying to learn ATS from the official tutorials, and while I
> like the language so far, and think that it is quite logical (if different
> from many other languages in the same categories),  one thing that keeps
> annoying me is getting some strange error messages.
>
> For instance, why is this a problem:
>
> fun
> bstree_search (
>   t0: bstree,
>   k0: string
> ): bool =
> case+ t0 of
>   | E () => false,
>   | B (t1, k, t2) =>
> let val sgn = compare (k0, k)
> in case+ 0 of
>   | _ when sgn < 0 => bstree_search (t1, k0)
>   | _ when sgn > 0 => bstree_search (t2, k0)
>   | _ => true
> end
>
> I would expect that the return types of all sub-expressions are `void`
> anyway, so why does the compiler complain:
>
> $ patscc -DATS_MEMALLOC_LIBC -o bst bst.dats && ./bst
> /Users/z0ltan/dev/study/ats/introduction_to_programming_in_ats/chapter4/bst.dats:
> 1022(line=53, offs=22) -- 1023(line=53, offs=23): error(parsing): the token
> is discarded.
> /Users/z0ltan/dev/study/ats/introduction_to_programming_in_ats/chapter4/bst.dats:
> 1096(line=56, offs=9) -- 1098(line=56, offs=11): error(parsing): the token
> is discarded.
> exit(ATS): uncaught exception:
> _2home_2hwxi_2Research_2ATS_2dPostiats_2src_2pats_error_2esats__FatalErrorExn(1025)
>
> The ATS FAQ recommends wrapping expressions with parentheses for such
> errors, but doing so in this case does not get rid of the errors, and
> secondly why is that even needed?
>
> Right now, this is the biggest thing that keeps tripping me up - seemingly
> random "token discarded" error messages as well as some strange "} keyword
> needed" error message etc. Experimenting randomly seems to fix them most
> times, but is there any reason to this madness?
>
> Can anyone give me general guidelines to avoid seeing these sort of
> trivial errors?
>
> Best,
>
> Timmy
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/71b5daaa-c80b-42d6-983a-72d8ab59b0ean%40googlegroups.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLqp1V-Su-LrsP5nuoaGcFjYTLn%2B2zswKztYtexFdtdNQQ%40mail.gmail.com.


Fwd: [ats-lang-users] ATS2-0.4.1 released

2020-08-02 Thread Hongwei Xi
-- Forwarded message -

Hi,

It is my pleasure to announce the release
of ATS2-0.4.1. Note that this is the version needed
(or may be needed in the future) for compiling the
ongoing implementation of ATS3 (ATS/Xanadu).


ATS-Postiats-0.4.1.tgz:
The same as ATS-Postiats-int-0.4.1.tgz
MD5: 99d99ea8296035abc7983fc3c21e1f05
SHA1: 1e1d2b33b2f89ca229689de6fc6b403d0d35b6fe
--
ATS2-Postiats-gmp-1.4.0.tgz:
MD5: 1f73c15ec2fcf0b6880f7a2b3d5da17c
SHA1: af6a943b49236f02fcc1fe671477dbff85197c6a
--
ATS2-Postiats-int-1.4.0.tgz:
MD5: 6bbdd92aa412dd7f70a9e56363b8b22f
SHA1: 6c9e4032514a297365ad1f92a17dd61ead70755f


This is the 52nd release of ATS2, the successor of the
ATS programming language. The compiler for ATS2 is given
the name ATS/Positats, ATS2/Postiats or simply Postiats.

The official website for ATS is:

http://www.ats-lang.org

ATS-Postiats is hosted at github:

https://github.com/githwxi/ATS-Postiats

Major releases of ATS2 are available at:

https://sourceforge.net/projects/ats2-lang/

Major releases of external packages for ATS2 are available at:

https://sourceforge.net/projects/ats2-lang-contrib/

##

Here is a list of major additions and changes since the last
release:

There are only a few minor modifications made to the last release;
however, these modifications are needed for compiling ATS3 in the
future.

##

Please note that there are two variants of the ATS2 package being
released:

The "gmp" variant depends on the GMP library and the "int" variant does
not depend on the GMP library. In this release
ATS2-Postiats-0.4.1.tgz is just the same as ATS2-Postiats-int-0.4.1.tgz.

##

Cheers,

--Hongwei

Computer Science Department
Boston University
111 Cummington Street
Boston, MA 02215

Email: h...@cs.bu.edu
Url: http://www.cs.bu.edu/~hwxi
Tel: +1 617 358 2511 (office)
Fax: +1 617 353 6457 (department)



___
ats-lang-users mailing list
ats-lang-us...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ats-lang-users

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLqEA1yZFFT63xSsnKDUtObL8nrrXeFS-0Ga6T_XmO98bw%40mail.gmail.com.


Re: ATS Linux - A Feedback

2020-07-26 Thread Hongwei Xi
I read some of your code in lib/string.dats. I suppose that you would soon
find that
handling structs can be a big challenge.

Even without using linear types, you could potentially find bugs involving
dereferencing
NULL pointers. For example, in the following code, pde_subdir_find
obviously assumes that
its argument 'dir' is not NULL. But is this assumption really met at all
the call sites of pde_subdir_find?

static struct proc_dir_entry *pde_subdir_find(struct proc_dir_entry *dir,
  const char *name,
  unsigned int len)
{
struct rb_node *node = dir->subdir.rb_node; // dir could potentially be 
NULL
...

}

I would not be surprised if bugs of this kind are uncovered with some
easy dependent type checking.

Furthermore, things can turn out to be more interesting if linear
types are used. For example, hidden
bugs potentially causing resource leaks can be uncovered with linear
type checking.

If you use linear types, handling structs can be quite a challenge.
Maybe it is a good idea to avoid using linear
types for now.


On Sun, Jul 26, 2020 at 8:57 PM Matthias Wolff 
wrote:

> Hi Hongwei,
>
> thanks for the feedback. Point 2 I perhaps misunderstand.
> I think the system is running with working ats code - respecting
> big endian, 32 bit coding, and memory alignment stuff. Between
> my mail and your response I wrote about 1300 lines of ats code.
> Working and running code. But for what I'm doing this. I can only
> express it with the name Schönfinkel, pure phantasy - or reality?
>
>
> Am 26.07.20 um 21:30 schrieb gmhwxi:
>
>
> Hi Matthias,
>
> Today I took a glance at your ats-linux project. Here are a few thoughts
> that I would like to share.
>
> 1. Please do not use the current library of ATS2. Instead, you should build
> a library of your own specifically for this project. Of course, you could
> use ATS2
> library at the beginning and then gradually replace the ATS library code
> with your
> own.
>
> 2. Please try to avoid using dependent types at the beginning. I would not
> until
> after I have got a running system. Think of dependent types as a way for
> you to
> do (static) debugging later.
>
> 3. Try to use abstract types a lot! Here is some code I wrote to show off
> the idea:
>
>
> https://github.com/xanadu-lang/xinterp/blob/master/srcgen/TEST/xatslib_githwxi/test-2020-07-26.dats
>
> For instance, argv is just an array of strings. But you can make it
> abstract. If you really need to make use
> of the fact that argv is an array of strings, you could just do a cast.
> Yes, this is unsafe but can be fixed later
> without much effort at all.
>
> 4. Try to use templates a lot! Probably you could study the code in
> ATS-Temptory (but don't use ATS-Temptory
> for your project as it is a quick experiment done and over at this point).
>
> Good luck!
>
> --Hongwei
>
> PS: Don't feel that I have time to contribute to your project at this
> moment. But I will be happy to make suggestions
> on translating C code into ATS.
>
>
> On Wednesday, July 1, 2020 at 9:29:58 PM UTC-4, matthias wrote:
>>
>> Hi,
>>
>> After half a year of experiencing ats (as a c++ developer) I changed my
>> point of view in how  to go forward in using ats. Comparing ats with other
>> "modern" languages is not very satisfying. Always having a position in the
>> middle - for the logical prove oriented people we have linear logic
>> (finally get control over resources, while the garbage collector solved
>> before such problems), for the machine programming oriented people linear
>> logic is like c-programming (nothing new, while garbage collection or
>> intelligent resource management may also solve serious problems) - is
>> difficult. Personally I Iike to have both - I can compare - cool. To come
>> to a point. I learned very much from this list and from the very good
>> documentation of the ats language. I started to change the linux kernel as
>> a private self teaching project. Looking from the viewpoint of a
>> c-programmer in direction to ats or alternatively to c++ is for me of
>> interest, For that, a minimal linux system of about 630 objects consists
>> now on 595 ats-dats files, may help to understand more. Sure, I haven't
>> migrated 595 c-files to real ats code. The integration is a first step
>> using the %{...%} pattern. The real migration must be done, one after the
>> other, by hand. It's a kind of training. If someone else has a personal
>> interest on linux kernel coding take my approach from git.bejocama.org.
>> It's totally open. Finally Thanks.
>>
>> Regards Matthias
>>
>> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> 

Re: ptr1 and v0tp

2020-07-26 Thread Hongwei Xi
As I suggested in my previous email, please try to build a library of your
own for this project.
Try to avoid using ptr and use cptr instead. Note that ptr is like void*
and cptr(T) is like T* in C.
Also try to avoid using dependent type at the beginning. Dependent types
can be introduced later
for the purpose of static debugging.

Personally, I feel that ATS3 would be a lot better for such a project, but
ATS2 is adequate. Once ATS3
becomes ready, the project can be readily translated from ATS2 into ATS3.

Cheers!

--Hongwei


On Sat, Jul 25, 2020 at 8:41 PM Matthias Wolff 
wrote:

> Your speed is impressing. I take all I can get. It's really an adventure.
> In my early stage of my playground "ats linux kernel" it helps to make
> good design decisions.
>
> Am 25.07.20 um 23:34 schrieb Hongwei Xi:
>
>
> #include "share/atspre_define.hats"
> #include "share/atspre_staload.hats"
> #staload UN = "prelude/SATS/unsafe.sats"
>
> #define ATS_DYNLOADFLAG 0
>
> (*
> Recursion is at the center of programming.
> And recursively defined concepts are occurring everywhere.
> For instance, the C-string concept is recursively defined.
> Let 'string(n)' be a type for C-strings of the size 'n'.
>
> We can readily implement the following three functions
> for recursively traversing a C-string:
> *)
>
> extern
> fun{}
> string_nilq
> {n:int}(string(n)): bool(n==0)
> extern
> fun{}
> string_head{n:pos}(string(n)): char
> extern
> fun{}
> string_tail{n:pos}(string(n)): string(n-1)
>
> (*
> For saving time, these three functions
> are given the following UNSAFE implementation
> *)
> implement
> string_nilq<>(cs) =
> $UN.cast
> (
> iseqz
> ($UN.ptr0_get(string2ptr(cs)))
> )
> //
> implement
> string_head<>(cs) =
> ($UN.ptr0_get(string2ptr(cs)))
> //
> implement
> string_tail<>(cs) =
> $UN.cast(ptr_succ(string2ptr(cs)))
>
> (*
> Then the length for C-strings can be implemented
> as follows:
> *)
>
> fun
> strlen
> {n:nat}
> (cs: string(n)): int(n) =
> loop(cs, 0) where
> {
> fun
> loop
> {i,j:nat|i+j==n}..
> (cs: string(i), j:int(j)): int(n) =
> if
> string_nilq(cs)
> then j else loop(string_tail(cs), j+1)
> }
>
> implement main0 () =
> let
> var s = @[char][4]('A','B','C','\0')
> val x = strlen($UN.cast{String0}(addr@(s)))
> in
> println!(x)
> end
>
> ##
>
> When compiled to assembly (after inlining), the strlen function implemented
> above is essentially the same as the one you did that uses pointers
> explicitly.
>
> Obviously, you can replace C-strings with other forms of sequences.
>
>
> On Sat, Jul 25, 2020 at 5:01 PM Matthias Wolff 
> wrote:
>
>> Surprising answer, because I don't understand the details at the moment.
>> It comes earlier than I expected. But I will take the chance. Thanks.
>> Am 25.07.20 um 21:32 schrieb Hongwei Xi:
>>
>> Your code should work if you add the following lines
>> at the beginning:
>>
>> prfun
>> lemma_char_size()
>> : [sizeof(char) > 0] void
>> prval () = lemma_char_size()
>>
>> These lines tell the type-checker that sizeof(char) is positive.
>>
>> Right now, the type system only knows that 'sizeof(char)' is an int.
>>
>>
>>
>> On Sat, Jul 25, 2020 at 9:59 AM matthias.wo...@bejocama.de <
>> matthias.wo...@bejocama.de> wrote:
>>
>>> Hi,
>>>
>>> after migrating the string functions in the lib of the linux kernel to
>>> ats I'm now starting to
>>> to improve the code in an ats sense. A first step was to change from
>>> ptr0_get/set to
>>> ptr1 (sure, still unsafe stuff - but better type checked regarding
>>> implicit type conversions).
>>>
>>> The code at the end demonstrates a little problem. ptr1_succ(pp)
>>> doesn't have the
>>> property l:agz even pp has it. Second, looking on the template parameter
>>> of ptr1_succ
>>> I get vt0p which stands for viewt@ype. I cannot actually get this in
>>> sync with documentation,
>>> because a viewt@ype should be something like vtypedef VT(T:t@ype,l:addr)
>>> = ( T@l | ptr(l) ).
>>> So I think the template parameter should be of t0p = t@ype. Otherwise I
>>> have wrong expectations
>>> in how to use these functions - and I don't really understand why my
>>> code compiles.
>>>
>>> Finally an last minute insight regarding the usage of ptr1_pred: l:addr
>>> | l > (null + sizeof(a)) .. works -
>>> without the null not. I know, in this case I should not be surprised.
&

Re: conditional expressions and branches

2020-07-25 Thread Hongwei Xi
Forgot to mention that you need parentheses:

(a <= 5) * (b <= 5)

On Sat, Jul 25, 2020 at 10:55 PM Hongwei Xi  wrote:

>
> Please use ifcase-expressions:
>
> fun
> foo
> {n:int}
> (n:int(n)): void =
> ifcase
> | n = 0 => () where {prval () = prop_verify{n == 0}()}
> | n = 1 => () where {prval () = prop_verify{n == 1}()}
> | _ (*else*) => () where {prval () = prop_verify{n != 0 && n != 1}()}
>
> ##
>
> Also, you can use '+' and '*' for || and &&, respectively. For instance,
>
> if a <= 5 * b <= 5 then ... else ...
>
> And '+' and '*' have the types expected by you.
>
>
>
>
> On Sat, Jul 25, 2020 at 10:35 PM Dambaev Alexander 
> wrote:
>
>> Hi,
>>
>> We know, that ATS is able to keep information about check in appropriate
>> branch of 'if' expression, like:
>>
>> ```
>> fn foo( i: int): int =
>>   if i < 1
>>   then (* here typechecker knows, that i < 1*)
>>   else (* here typechecker knows, that i >= 1*)
>> ```
>>
>> But sometimes, you need to use more conditions and case expressions is
>> more convenient in this case, but currently, typechecker is not always able
>> to keep such info in branches of 'case', like:
>>
>> ```
>> fn foo( a: int, b: int): int =
>>   case+ 0 of
>>   | _ when a > 10 => ...
>>   | _ when a > 5 => ...
>>   | _ when b > 10 => ...
>>   | _ when b > 5 => ...
>>   | _ => (* 1 *)
>> ```
>>
>> It will be great, if, at least in ATS3, at mark 1 typechecker will know,
>> that a <= 5 and b <= 5, because currently, as far as I got, condition like:
>> ```
>> if a <= 5 && b <= 5
>> then (* 1 *)
>> else (* 2 *)
>> ```
>> will tell typechecker, that there is a proof 'a <= 5 && b <= 5', but
>> there are no separate proofs 'a <= 5' and 'b<=5' so you have to make a
>> nested if-expressions to get them, which is not so compact as 'case'
>> expressions
>>
>> --
>> 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-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ats-lang-users/CAHjn2KxS8iGdxHRjVU2MJu_%2B5g143Lq6HKFo%2BRta06aF3ENdgg%40mail.gmail.com
>> <https://groups.google.com/d/msgid/ats-lang-users/CAHjn2KxS8iGdxHRjVU2MJu_%2B5g143Lq6HKFo%2BRta06aF3ENdgg%40mail.gmail.com?utm_medium=email_source=footer>
>> .
>>
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLpks-nnuS8yd_6QfasOQP2dN%2B7LyC%2BDAbXPA5HEdf%3DShg%40mail.gmail.com.


Re: conditional expressions and branches

2020-07-25 Thread Hongwei Xi
Please use ifcase-expressions:

fun
foo
{n:int}
(n:int(n)): void =
ifcase
| n = 0 => () where {prval () = prop_verify{n == 0}()}
| n = 1 => () where {prval () = prop_verify{n == 1}()}
| _ (*else*) => () where {prval () = prop_verify{n != 0 && n != 1}()}

##

Also, you can use '+' and '*' for || and &&, respectively. For instance,

if a <= 5 * b <= 5 then ... else ...

And '+' and '*' have the types expected by you.




On Sat, Jul 25, 2020 at 10:35 PM Dambaev Alexander 
wrote:

> Hi,
>
> We know, that ATS is able to keep information about check in appropriate
> branch of 'if' expression, like:
>
> ```
> fn foo( i: int): int =
>   if i < 1
>   then (* here typechecker knows, that i < 1*)
>   else (* here typechecker knows, that i >= 1*)
> ```
>
> But sometimes, you need to use more conditions and case expressions is
> more convenient in this case, but currently, typechecker is not always able
> to keep such info in branches of 'case', like:
>
> ```
> fn foo( a: int, b: int): int =
>   case+ 0 of
>   | _ when a > 10 => ...
>   | _ when a > 5 => ...
>   | _ when b > 10 => ...
>   | _ when b > 5 => ...
>   | _ => (* 1 *)
> ```
>
> It will be great, if, at least in ATS3, at mark 1 typechecker will know,
> that a <= 5 and b <= 5, because currently, as far as I got, condition like:
> ```
> if a <= 5 && b <= 5
> then (* 1 *)
> else (* 2 *)
> ```
> will tell typechecker, that there is a proof 'a <= 5 && b <= 5', but there
> are no separate proofs 'a <= 5' and 'b<=5' so you have to make a nested
> if-expressions to get them, which is not so compact as 'case' expressions
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CAHjn2KxS8iGdxHRjVU2MJu_%2B5g143Lq6HKFo%2BRta06aF3ENdgg%40mail.gmail.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLoAtWmL0kRe1Hpd5P%3DPMazOkzg5VeZr2pVAn%2B%3D%3DF2teEQ%40mail.gmail.com.


Re: ptr1 and v0tp

2020-07-25 Thread Hongwei Xi
#include "share/atspre_define.hats"
#include "share/atspre_staload.hats"
#staload UN = "prelude/SATS/unsafe.sats"

#define ATS_DYNLOADFLAG 0

(*
Recursion is at the center of programming.
And recursively defined concepts are occurring everywhere.
For instance, the C-string concept is recursively defined.
Let 'string(n)' be a type for C-strings of the size 'n'.

We can readily implement the following three functions
for recursively traversing a C-string:
*)

extern
fun{}
string_nilq
{n:int}(string(n)): bool(n==0)
extern
fun{}
string_head{n:pos}(string(n)): char
extern
fun{}
string_tail{n:pos}(string(n)): string(n-1)

(*
For saving time, these three functions
are given the following UNSAFE implementation
*)
implement
string_nilq<>(cs) =
$UN.cast
(
iseqz
($UN.ptr0_get(string2ptr(cs)))
)
//
implement
string_head<>(cs) =
($UN.ptr0_get(string2ptr(cs)))
//
implement
string_tail<>(cs) =
$UN.cast(ptr_succ(string2ptr(cs)))

(*
Then the length for C-strings can be implemented
as follows:
*)

fun
strlen
{n:nat}
(cs: string(n)): int(n) =
loop(cs, 0) where
{
fun
loop
{i,j:nat|i+j==n}..
(cs: string(i), j:int(j)): int(n) =
if
string_nilq(cs)
then j else loop(string_tail(cs), j+1)
}

implement main0 () =
let
var s = @[char][4]('A','B','C','\0')
val x = strlen($UN.cast{String0}(addr@(s)))
in
println!(x)
end

##

When compiled to assembly (after inlining), the strlen function implemented
above is essentially the same as the one you did that uses pointers
explicitly.

Obviously, you can replace C-strings with other forms of sequences.


On Sat, Jul 25, 2020 at 5:01 PM Matthias Wolff 
wrote:

> Surprising answer, because I don't understand the details at the moment.
> It comes earlier than I expected. But I will take the chance. Thanks.
> Am 25.07.20 um 21:32 schrieb Hongwei Xi:
>
> Your code should work if you add the following lines
> at the beginning:
>
> prfun
> lemma_char_size()
> : [sizeof(char) > 0] void
> prval () = lemma_char_size()
>
> These lines tell the type-checker that sizeof(char) is positive.
>
> Right now, the type system only knows that 'sizeof(char)' is an int.
>
>
>
> On Sat, Jul 25, 2020 at 9:59 AM matthias.wo...@bejocama.de <
> matthias.wo...@bejocama.de> wrote:
>
>> Hi,
>>
>> after migrating the string functions in the lib of the linux kernel to
>> ats I'm now starting to
>> to improve the code in an ats sense. A first step was to change from
>> ptr0_get/set to
>> ptr1 (sure, still unsafe stuff - but better type checked regarding
>> implicit type conversions).
>>
>> The code at the end demonstrates a little problem. ptr1_succ(pp)
>> doesn't have the
>> property l:agz even pp has it. Second, looking on the template parameter
>> of ptr1_succ
>> I get vt0p which stands for viewt@ype. I cannot actually get this in
>> sync with documentation,
>> because a viewt@ype should be something like vtypedef VT(T:t@ype,l:addr)
>> = ( T@l | ptr(l) ).
>> So I think the template parameter should be of t0p = t@ype. Otherwise I
>> have wrong expectations
>> in how to use these functions - and I don't really understand why my code
>> compiles.
>>
>> Finally an last minute insight regarding the usage of ptr1_pred: l:addr |
>> l > (null + sizeof(a)) .. works -
>> without the null not. I know, in this case I should not be surprised. But
>> l,r:agz | r == (l + sizeof(a)) --
>> doesn't imply r >= l.
>>
>> Here is the code - c-style strlen - very often called by the kernel and
>> the performance seems
>> to be good. The ptr0 version works (and also my pointer type modification
>> pgz):
>>
>> #define ATS_DYNLOADFLAG 0
>> #include "share/atspre_define.hats"
>> #include "share/atspre_staload.hats"
>> staload "prelude/SATS/unsafe.sats"
>>
>> fn strlen{l:agz}(p:ptr(l)) : [r:nat] size_t(r) =
>> let
>>   fun loop{ll:agz| ll >= l}(pp:ptr(ll)) : [r:agz| r >= ll] ptr(r) =
>>   case+ ptr1_get(pp) = '\0' of
>> | true => pp
>> | false => loop(ptr1_succ(pp))
>> in
>>   g1ofg0(cast{size_t}(loop(p) - p))
>> end
>>
>> implement main0 () =
>> let
>> var s = @[char][4]('A','B','C','\0')
>> val x = strlen(addr@(s))
>> in
>> println!(x)
>> end
>>
>> --
>> 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-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ats-lang-u

Re: ptr1 and v0tp

2020-07-25 Thread Hongwei Xi
Your code should work if you add the following lines
at the beginning:

prfun
lemma_char_size()
: [sizeof(char) > 0] void
prval () = lemma_char_size()

These lines tell the type-checker that sizeof(char) is positive.

Right now, the type system only knows that 'sizeof(char)' is an int.



On Sat, Jul 25, 2020 at 9:59 AM matthias.wo...@bejocama.de <
matthias.wo...@bejocama.de> wrote:

> Hi,
>
> after migrating the string functions in the lib of the linux kernel to ats
> I'm now starting to
> to improve the code in an ats sense. A first step was to change from
> ptr0_get/set to
> ptr1 (sure, still unsafe stuff - but better type checked regarding
> implicit type conversions).
>
> The code at the end demonstrates a little problem. ptr1_succ(pp)
> doesn't have the
> property l:agz even pp has it. Second, looking on the template parameter
> of ptr1_succ
> I get vt0p which stands for viewt@ype. I cannot actually get this in sync
> with documentation,
> because a viewt@ype should be something like vtypedef VT(T:t@ype,l:addr)
> = ( T@l | ptr(l) ).
> So I think the template parameter should be of t0p = t@ype. Otherwise I
> have wrong expectations
> in how to use these functions - and I don't really understand why my code
> compiles.
>
> Finally an last minute insight regarding the usage of ptr1_pred: l:addr |
> l > (null + sizeof(a)) .. works -
> without the null not. I know, in this case I should not be surprised. But
> l,r:agz | r == (l + sizeof(a)) --
> doesn't imply r >= l.
>
> Here is the code - c-style strlen - very often called by the kernel and
> the performance seems
> to be good. The ptr0 version works (and also my pointer type modification
> pgz):
>
> #define ATS_DYNLOADFLAG 0
> #include "share/atspre_define.hats"
> #include "share/atspre_staload.hats"
> staload "prelude/SATS/unsafe.sats"
>
> fn strlen{l:agz}(p:ptr(l)) : [r:nat] size_t(r) =
> let
>   fun loop{ll:agz| ll >= l}(pp:ptr(ll)) : [r:agz| r >= ll] ptr(r) =
>   case+ ptr1_get(pp) = '\0' of
> | true => pp
> | false => loop(ptr1_succ(pp))
> in
>   g1ofg0(cast{size_t}(loop(p) - p))
> end
>
> implement main0 () =
> let
> var s = @[char][4]('A','B','C','\0')
> val x = strlen(addr@(s))
> in
> println!(x)
> end
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/9e71a4f6-6be7-44ed-8e61-c7b44d260b34o%40googlegroups.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLoo4t-5ZisDftmGV1rUuHLqnuLWiw_he%3DLQYY2PUww9ZA%40mail.gmail.com.


Re: constraint solving

2020-07-25 Thread Hongwei Xi
 >> #[m1:nat | m1 <= m] size_t(m1)

Note that the leading '#' is not needed in this case.
You could just use the shorthand 'sizeLte(m)' here.

On Sat, Jul 25, 2020 at 1:58 AM Dambaev Alexander 
wrote:

> ah, looks like it is because of sort of return type:
> ```
> ): size_t(oidx) =
> ```
> I had spent a day dancing around this scaffold and got it after sending a
> messge
>
> сб, 25 июл. 2020 г. в 05:54, Dambaev Alexander :
>
>> Hi,
>> I am struggling to satisfy typechecker with implementing a loop with 2
>> indexes.
>>
>> ```
>> fn
>>   encode0
>>   {n: nat}{m:nat | m > n}{l:agz}
>>   ( o_pf: !array_v(byte, l, m)
>>   | i: &(@[byte][n])
>>   , i_sz: size_t(n)
>>   , o: ptr l
>>   , o_sz: size_t(m)
>>   ): #[m1:nat | m1 <= m] size_t(m1)
>>
>> implement encode0{n}{m}( o_pf | i, i_sz, o, o_sz) = ret where {
>>   fun
>> loop
>> {iidx: nat | iidx <= n}{oidx: nat | oidx <= m}
>> ..
>> ( iidx: size_t(iidx)
>> , oidx: size_t(oidx)
>> , i: &(@[byte][n])
>> , o: &(@[byte][m])
>> ): size_t(oidx) =
>>   if iidx < i_sz
>>   then
>> if oidx < o_sz
>> then loop( iidx + 1, oidx + 1, i, o) *(* error at this line *)*
>> else oidx
>>   else oidx
>>   val ret = loop( i2sz(0), i2sz(0), i, !o)
>> }
>> ```
>> The error is follows:
>> ```
>> 1395(line=66, offs=14) -- 1426(line=66, offs=45): error(3): unsolved
>> constraint: C3NSTRprop(C3TKmain(); S2Eeqeq(S2Eapp(S2Ecst(add_int_int);
>> S2Evar(oidx(8515)), S2Eintinf(1)); S2Evar(oidx(8515
>> ```
>> For now it is just a scaffold, which I am trying to compile with a simple
>> traverse. Later I will need both iidx and oidx, but I don't understand what
>> is the issue now
>>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CAHjn2KzNJ3m8%3DkXx-0KWHUMLgoGPL48v7E6VBTD9kCf9yemNMg%40mail.gmail.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLo-JVZPOOsZJa4iZk99m_fhMo-1o5ogxO%2B_TzwpSWBVdQ%40mail.gmail.com.


Re: unboxed datatypes

2020-07-19 Thread Hongwei Xi
Here is a little doc on manually constructing values of a datatype:

http://ats-lang.sourceforge.net/DOCUMENT/INT2PROGINATS/HTML/HTMLTOC/x2223.html

If you have a constructor of the name foo, then a type 'foo_pstruct' is
automatically introduced
(in the same namespace). You can study the generated C code to figure out
the related details.


On Sun, Jul 19, 2020 at 10:47 AM Dambaev Alexander 
wrote:

> So I have tried to use views to replace datatypes. My idea was to pass a
> variable's view and address, change it's view and write different tuples at
> it's address (because tuples are unboxed):
>
> ```
>
>
> viewdef req_v_tx_ack_v(l1: addr) = int @ l1
> viewdef req_v_push_data_v(l1: addr) = (int, bool) @ l1
>
> dataview gw_ns_request_v1_v(int, l1:addr) =
>   | req_v_tx_ack(0, l1) of req_v_tx_ack_v(l1)
>   | req_v_push_data(1, l1) of req_v_push_data_v(l1)
>
> (* axioms to revert variable's type to original *)
> extern praxi tx_ack2result
>   {l1:agz}{n1:pos}
>   ( pf: !req_v_tx_ack_v(l1) >> array_v(char?, l1, n1)
>   ): void
> extern praxi push_data2result
>   {l1:agz}{n1:pos}
>   ( pf: !req_v_push_data_v(l1) >> array_v(char?, l1, n1)
>   ): void
>
> dataview
>   result_vb
>   ( bool, a:view+, b:view+) =
>   | result_vb_succ(true, a, b) of a
>   | result_vb_fail(false, a, b) of b
>
> fn parse_request
>   {l1:agz}{n1:pos}
>   ( result_pf: !array_v(char?, l1, n1) >> result_vb( tag >= 0
>, gw_ns_request_v1_v(
> tag, l1)
>, array_v(char?, l1, n1)
>)
>   | flag: int
>   , result: ptr l1
>   ): #[tag: int ] int(tag) =
>   case+ flag of
>   | 0 => 0 where {   *(* 1 *)*
> extern praxi result2tx_ack
>   {l1:agz}{n1:pos}
>   ( pf: !array_v(char?, l1, n1) >> req_v_tx_ack_v(l1)
>   ): void
> prval () = result2tx_ack( result_pf)
> val () = !result := 0
> prval ret_pf = req_v_tx_ack( result_pf)
> prval () = result_pf := result_vb_succ( ret_pf)
>   }
>   | 1 => 1 where { *(* 2 *)*
> extern praxi result2push_data
>   {l1:agz}{n1:pos}
>   ( pf: !array_v(char?, l1, n1) >> req_v_push_data_v(l1)
>   ): void
> prval () = result2push_data( result_pf)
> val () = !result := (0,false)
> prval ret_pf = req_v_push_data( result_pf)
> prval () = result_pf := result_vb_succ( ret_pf)
>   }
>   | _ => ~1 where {
> prval ret_pf = result_pf
> prval () = result_pf := result_vb_fail(ret_pf)
>   }
>
> fn test4(): void = {
>   var result: @[char][1] with result_pf *(* 3  *)*
>   var raw = addr@result (* we need ptr l ,where l == addr@result,
> otherwise  *)
>   val s = parse_request( result_pf | 1, addr@result)
>   val () = case- s of
> | 0 => () where {   *(* 4 *)*
>   prval result_vb_succ(ret_pf) = result_pf
>   prval req_v_tx_ack( value_pf) = ret_pf
>   prval () = result_pf := value_pf
>   val token = !raw (* here we read a tuple from result's address *)
>   val () = assertloc( raw = addr@result)
>   val () = assertloc( token = 0x)
>   (* restore types *)
>   prval () = tx_ack2result( result_pf)
>   prval () = result_pf := array_v_unnil_nz( result_pf)
> }
> | 1 => () where {  *(* 5 *)*
>   prval result_vb_succ(ret_pf) = result_pf
>   prval req_v_push_data( value_pf) = ret_pf
>   prval () = result_pf := value_pf
>   val (i:int,b:bool) = !raw (* here we read a tuple from result's
> address *)
>   val () = assertloc( raw = addr@result)
>   val () = assertloc( i = 0)
>   val () = assertloc( b = false)
>   (* restore types *)
>   prval () = push_data2result( result_pf)
>   prval () = result_pf := array_v_unnil_nz( result_pf)
> }
>
> | _ when s < 0 => () where {
>   prval result_vb_fail(ret_pf) = result_pf
>   prval () = result_pf := array_v_unnil_nz(ret_pf)
> }
> }
> ```
>
> And this compile, runs and valgrind and gdb has no issues. But there are
> catchs:
> 1. If I will messup int values in marks (comments)  1 and 2, then type
> checker will complain (as expected), but at the same time, I can replace
> values at marks 4 and 5 with any random integers and type checker will be
> fine with it;
> 2. if you notice at mark 5, result buffer is of size 1*sizeof(char), but
> program stores int and (int,int) values into it, which are bigger that
> char. At the same time, gdb and valgrind do not report any issues and I
> haven't checked generated code to see if it corrupts memory.
>
> I guess, I can solve issue #1 by introducing a new sort, but I need a way
> to map sort->int values (and maybe vice verse)
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the 

Re: Issue with conditionally mutating a var twice

2020-07-17 Thread Hongwei Xi
I made the function mat4_to_quat type-check. See the attached file.

One noticeable change is the type for the 'loop' function in your code:

fun loop {n,m:nat | 0 <= m+1; m+1 <= n} .. (m: int m, qs:
&(@[quat][n]), ws: &(@[float][n]), acc1: vec3) : vec3 = ...

Also, I modified

(mat4_at(m, j, j),  mat4_at(m, k, k))

into

(mat4_at(m, j, j) + mat4_at(m, k, k)) // '+' is chosen randomly here.

##

Right now, there are a lot of casts needed in your code. Let me make a
suggestion.
When using an array of floats (instead of an array of doubles), you
primarily want to
save some memory. But for arithmetic operations, you probably want to use
doubles.
I would follow the rules below:

When a float is read from an array of floats, cast it to a double
immediately. Also, cast a
double into a float before writing to an array of floats. For example,
the following interface:

fun mat4_rotation_x ( a: float ) : mat4

should be changed to

fun mat4_rotation_x ( a: double ) : mat4

Also, please make mat4 an abstract type.

On Fri, Jul 17, 2020 at 8:04 AM d4v3y_5c0n3s  wrote:

> Okay, so gmhwxi's suggestion to use natLt(2) & natLt(3) seems to have
> worked, but I'm having trouble understanding what natLt(2) & natLt(3)
> actually is.
>
> *Could anyone explain what natLt(2) & natLt(3) mean, please?*  After
> looking at the prelude the definition of natLt() doesn't seem
> self-explanatory.
>
> As for the suggestions to use separate val-declarations in a more
> functional style, my reason for taking this approach is that I am trying to
> replicate some C code in ATS.  *I do agree that this is probably not the
> cleanest solution, I figure that I can revise it later once I get my
> overall project working.*  But I appreciate the suggestions, so thank you.
>
> Going off of what Dambaev said, *it makes sense to prove to the compiler
> that 'i' is >= 0 && < 4, but what sort of statements might I use for this? *
> I worked through chapter 12 of Intro to Programming in ATS, but I'm still
> quite unsure on how to use proofs effectively.  Thanks for this advice,
> Dambaev.
>
> Lastly, *I am running into an issue with indexing an array where the
> compiler says that the function argument must be a left-value.*  I assume
> that 'nxt' is the one that needs to be a left-value, but !nxt doesn't make
> a difference.  Any help that can be provided is appreciated.
>
> Apologies for the long response, I wanted to make sure I responded to as
> many of you as possible, because you've all been really helpful. :)
>
> Here's my updated function:
>
> implement mat4_to_quat ( m ) = let
>   val tr = m.xx + m.yy + m.zz
> in
>   if tr > 0.f then let
> val s = $MATH.sqrt(tr + 1.f)
> val w = s / 2.f
> val x = ( mat4_at(m, 1, 2) - mat4_at(m, 2, 1) ) * (0.5f / s)
> val y = ( mat4_at(m, 2, 0) - mat4_at(m, 0, 2) ) * (0.5f / s)
> val z = ( mat4_at(m, 0, 1) - mat4_at(m, 1, 0) ) * (0.5f / s)
>   in
> quat_new(x, y, z, w)
>   end else let
> val nxt = @[int](1, 2, 0)
> var q = @[float][4](0.f)
> var i = 0
> var j = 0
> var k = 0
> var s = 0
>   in
> i := ((if mat4_at(m, 1, 1) > mat4_at(m, 0, 0) then 1 else i):natLt(2));
> i := ((if mat4_at(m, 2, 2) > mat4_at(m, i, i) then 2 else i):natLt(3));
> *j := nxt[i];  <-- first error message is on this line*
> k := nxt[j];
> s := $MATH.sqrt( (mat4_at(m, i, i) - (mat4_at(m, j, j), mat4_at(m, k,
> k))) + 1.f );
> q[i] := s * 0.5f;
> s := (if (s != 0.f) then 0.5f / s else s);
> q[3] := (mat4_at(m, j, k) - mat4_at(m, k, j)) * s;
> q[j] := (mat4_at(m, i, j) + mat4_at(m, j, i)) * s;
> q[k] := (mat4_at(m, i, k) + mat4_at(m, k, i)) * s;
> quat_new(q[0], q[1], q[2], q[3])
>   end
> end
>
>
> Here's the new error message:
>
> patscc -tcats /home/d4v3y/Goldelish-Engine/source/g_engine.dats
> /home/d4v3y/Goldelish-Engine/source/g_engine.dats: 35545(line=1374,
> offs=11) -- 35549(line=1374, offs=15): error(3): the function argument
> needs to be a left-value.
> /home/d4v3y/Goldelish-Engine/source/g_engine.dats: 35544(line=1374,
> offs=10) -- 35551(line=1374, offs=17): error(3): the symbol [!] cannot be
> resolved as no match is found.
> /home/d4v3y/Goldelish-Engine/source/g_engine.dats: 35539(line=1374,
> offs=5) -- 35551(line=1374, offs=17): error(3): assignment cannot be
> performed: mismatch of bef/aft type-sizes:
> bef: [S2Eapp(S2Ecst(g1int_int_t0ype); S2Eextkind(atstype_int),
> S2Eintinf(0))]
> aft: [S2Eerrexp()]
> /home/d4v3y/Goldelish-Engine/source/g_engine.dats: 35562(line=1375,
> offs=10) -- 35568(line=1375, offs=16): error(3): the symbol [[]] cannot be
> resolved due to too many matches:
> D2ITMcst(array_get_at_guint) of 0
> D2ITMcst(array_get_at_gint) of 0
> /home/d4v3y/Goldelish-Engine/source/g_engine.dats: 35557(line=1375,
> offs=5) -- 35568(line=1375, offs=16): error(3): assignment cannot be
> performed: mismatch of bef/aft type-sizes:
> bef: [S2Eapp(S2Ecst(g1int_int_t0ype); S2Eextkind(atstype_int),
> S2Eintinf(0))]
> aft: 

Re: Issue with conditionally mutating a var twice

2020-07-16 Thread Hongwei Xi
Great advice :)

In functional programming, using 'val' is preferred over using 'var'.

For instance, if you do

let
val x = 0
val x = x + 1
val x = 5 * x
in
  ...
end

The compiler is very likely to map the three x's to one register as if the
code was written in
the following imperative style:

let
var x = 0
val () = x := x + 1
val () = x := 5 * x
in
   ...
end

On a modern architecture, register allocation is a complicated issue. By
using more val's (instead
of var's), you allow more freedom during register allocation, potentially
resulting in the generation of
more efficient object code.

On Thu, Jul 16, 2020 at 2:14 PM  wrote:

> Additionally, you might want to use different variables for i. It’s
> allowed to use the same variable name in successive let bindings. The
> different i will have different types, making it simpler for type checker
> to solve constraints.
>
> Sent from my iPhone
>
> On 16 Jul 2020, at 19:01, Hongwei Xi  wrote:
>
> 
> * >> i := ((if mat4_at(m, 1, 1) > mat4_at(m, 0, 0) then 1 else i):int);*
> *>> i := ((if mat4_at(m, 2, 2) > mat4_at(m, $showtype(i), i) then 2 else
> i):int);  // <-- this line has the error*
>
> 'i' is later used to index an array.
> It seems that you just need:
>
> i := ((if mat4_at(m, 1, 1) > mat4_at(m, 0, 0) then 1 else i):natLt(2));
> i := ((if mat4_at(m, 2, 2) > mat4_at(m, $showtype(i), i) then 2 else
> i):natLt(3);
>
>
> On Thu, Jul 16, 2020 at 8:12 AM d4v3y_5c0n3s  wrote:
>
>>   So, I'm trying to mutate a var twice in order to replicate some C code
>> that I am trying to port to ATS.  But, I've been scratching my head as to
>> why this would happen, so any help is appreciated.  In an effort to not
>> waste your time, I will be showing you the function with my issue along
>> with the declarations for the relevant functions & typedefs.  Please ask if
>> you'd like me to provide more details that I may have missed.
>>
>> The function I'm having trouble in:
>>
>> implement mat4_to_quat ( m ) = let
>>   val tr = m.xx + m.yy + m.zz
>> in
>>   if tr > 0.f then let
>> val s = $MATH.sqrt(tr + 1.f)
>> val w = s / 2.f
>> val x = ( mat4_at(m, 1, 2) - mat4_at(m, 2, 1) ) * (0.5f / s)
>> val y = ( mat4_at(m, 2, 0) - mat4_at(m, 0, 2) ) * (0.5f / s)
>> val z = ( mat4_at(m, 0, 1) - mat4_at(m, 1, 0) ) * (0.5f / s)
>>   in
>> quat_new(x, y, z, w)
>>   end else let
>> val nxt = @[int](1, 2, 0)
>> var q = @[float][4](0.f)
>> var i = 0
>> var j = 0
>> var k = 0
>> var s = 0
>>   in
>> *i := ((if mat4_at(m, 1, 1) > mat4_at(m, 0, 0) then 1 else i):int);*
>> *i := ((if mat4_at(m, 2, 2) > mat4_at(m, $showtype(i), i) then 2 else
>> i):int);  // <-- this line has the error*
>> j := nxt[i];
>> k := nxt[j];
>> s := $MATH.sqrt( (mat4_at(m, i, i) - (mat4_at(m, j, j), mat4_at(m, k,
>> k))) + 1.f );
>> q[i] := s * 0.5f;
>> s := (if (s != 0.f) then 0.5f / s else s);
>> q[3] := (mat4_at(m, j, k) - mat4_at(m, k, j)) * s;
>> q[j] := (mat4_at(m, i, j) + mat4_at(m, j, i)) * s;
>> q[k] := (mat4_at(m, i, k) + mat4_at(m, k, i)) * s;
>> quat_new(q[0], q[1], q[2], q[3])
>>   end
>> end
>>
>>
>> Here's the function's declaration:
>>
>> fun mat4_to_quat ( m: mat4 ) : quat = "sta#%"
>>
>>
>> Here's the declaration for mat4_at:
>>
>> fun mat4_at {x:nat | x < 4}{y:nat | y < 4} ( m: mat4, x: int x, y: int y
>> ) : float = "sta#%"
>>
>>
>> My full repo can be found here:
>> https://github.com/d4v3y5c0n3s/Goldelish-Engine
>> Here's the error message:
>>
>> patscc -tcats /home/d4v3y/Goldelish-Engine/source/g_engine.dats
>> **SHOWTYPE[UP]**(/home/d4v3y/Goldelish-Engine/source/g_engine.dats:
>> 35508(line=1373, offs=55) -- 35509(line=1373, offs=56)):
>> S2Eapp(S2Ecst(g0int_t0ype); S2Eextkind(atstype_int)): S2RTbas(S2RTBASimp(1;
>> t@ype))
>> /home/d4v3y/Goldelish-Engine/source/g_engine.dats: 35508(line=1373,
>> offs=55) -- 35509(line=1373, offs=56): error(3): the dynamic expression
>> cannot be assigned the type [S2Eapp(S2Ecst(g1int_int_t0ype);
>> S2Eextkind(atstype_int), S2EVar(6368))].
>> /home/d4v3y/Goldelish-Engine/source/g_engine.dats: 35508(line=1373,
>> offs=55) -- 35509(line=1373, offs=56): error(3): mismatch of static terms
>> (tyleq):
>> The actual term is: S2Eapp(S2Ecst(g0int_t0ype); S2Eextkind(atstype_int))
>> The needed term is: S2Eapp(S2Ecst(g1int_int_t0ype);
>> S2Eextkind(atstype_int), S2EVar(6368))
>> /home/d4v3

Re: Issue with conditionally mutating a var twice

2020-07-16 Thread Hongwei Xi
* >> i := ((if mat4_at(m, 1, 1) > mat4_at(m, 0, 0) then 1 else i):int);*
*>> i := ((if mat4_at(m, 2, 2) > mat4_at(m, $showtype(i), i) then 2 else
i):int);  // <-- this line has the error*

'i' is later used to index an array.
It seems that you just need:

i := ((if mat4_at(m, 1, 1) > mat4_at(m, 0, 0) then 1 else i):natLt(2));
i := ((if mat4_at(m, 2, 2) > mat4_at(m, $showtype(i), i) then 2 else
i):natLt(3);


On Thu, Jul 16, 2020 at 8:12 AM d4v3y_5c0n3s  wrote:

>   So, I'm trying to mutate a var twice in order to replicate some C code
> that I am trying to port to ATS.  But, I've been scratching my head as to
> why this would happen, so any help is appreciated.  In an effort to not
> waste your time, I will be showing you the function with my issue along
> with the declarations for the relevant functions & typedefs.  Please ask if
> you'd like me to provide more details that I may have missed.
>
> The function I'm having trouble in:
>
> implement mat4_to_quat ( m ) = let
>   val tr = m.xx + m.yy + m.zz
> in
>   if tr > 0.f then let
> val s = $MATH.sqrt(tr + 1.f)
> val w = s / 2.f
> val x = ( mat4_at(m, 1, 2) - mat4_at(m, 2, 1) ) * (0.5f / s)
> val y = ( mat4_at(m, 2, 0) - mat4_at(m, 0, 2) ) * (0.5f / s)
> val z = ( mat4_at(m, 0, 1) - mat4_at(m, 1, 0) ) * (0.5f / s)
>   in
> quat_new(x, y, z, w)
>   end else let
> val nxt = @[int](1, 2, 0)
> var q = @[float][4](0.f)
> var i = 0
> var j = 0
> var k = 0
> var s = 0
>   in
> *i := ((if mat4_at(m, 1, 1) > mat4_at(m, 0, 0) then 1 else i):int);*
> *i := ((if mat4_at(m, 2, 2) > mat4_at(m, $showtype(i), i) then 2 else
> i):int);  // <-- this line has the error*
> j := nxt[i];
> k := nxt[j];
> s := $MATH.sqrt( (mat4_at(m, i, i) - (mat4_at(m, j, j), mat4_at(m, k,
> k))) + 1.f );
> q[i] := s * 0.5f;
> s := (if (s != 0.f) then 0.5f / s else s);
> q[3] := (mat4_at(m, j, k) - mat4_at(m, k, j)) * s;
> q[j] := (mat4_at(m, i, j) + mat4_at(m, j, i)) * s;
> q[k] := (mat4_at(m, i, k) + mat4_at(m, k, i)) * s;
> quat_new(q[0], q[1], q[2], q[3])
>   end
> end
>
>
> Here's the function's declaration:
>
> fun mat4_to_quat ( m: mat4 ) : quat = "sta#%"
>
>
> Here's the declaration for mat4_at:
>
> fun mat4_at {x:nat | x < 4}{y:nat | y < 4} ( m: mat4, x: int x, y: int y )
> : float = "sta#%"
>
>
> My full repo can be found here:
> https://github.com/d4v3y5c0n3s/Goldelish-Engine
> Here's the error message:
>
> patscc -tcats /home/d4v3y/Goldelish-Engine/source/g_engine.dats
> **SHOWTYPE[UP]**(/home/d4v3y/Goldelish-Engine/source/g_engine.dats:
> 35508(line=1373, offs=55) -- 35509(line=1373, offs=56)):
> S2Eapp(S2Ecst(g0int_t0ype); S2Eextkind(atstype_int)): S2RTbas(S2RTBASimp(1;
> t@ype))
> /home/d4v3y/Goldelish-Engine/source/g_engine.dats: 35508(line=1373,
> offs=55) -- 35509(line=1373, offs=56): error(3): the dynamic expression
> cannot be assigned the type [S2Eapp(S2Ecst(g1int_int_t0ype);
> S2Eextkind(atstype_int), S2EVar(6368))].
> /home/d4v3y/Goldelish-Engine/source/g_engine.dats: 35508(line=1373,
> offs=55) -- 35509(line=1373, offs=56): error(3): mismatch of static terms
> (tyleq):
> The actual term is: S2Eapp(S2Ecst(g0int_t0ype); S2Eextkind(atstype_int))
> The needed term is: S2Eapp(S2Ecst(g1int_int_t0ype);
> S2Eextkind(atstype_int), S2EVar(6368))
> /home/d4v3y/Goldelish-Engine/source/g_engine.dats: 35512(line=1373,
> offs=59) -- 35513(line=1373, offs=60): error(3): the dynamic expression
> cannot be assigned the type [S2Eapp(S2Ecst(g1int_int_t0ype);
> S2Eextkind(atstype_int), S2EVar(6369))].
> /home/d4v3y/Goldelish-Engine/source/g_engine.dats: 35512(line=1373,
> offs=59) -- 35513(line=1373, offs=60): error(3): mismatch of static terms
> (tyleq):
> The actual term is: S2Eapp(S2Ecst(g0int_t0ype); S2Eextkind(atstype_int))
> The needed term is: S2Eapp(S2Ecst(g1int_int_t0ype);
> S2Eextkind(atstype_int), S2EVar(6369))
>
> |
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/32da2a64-1760-418e-8d45-1960f16f13d5o%40googlegroups.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLqDLKzw8QZHUNeGoNqBGHJTQnzp6Gd0S0DAK%3Dy81BSpKQ%40mail.gmail.com.


Re: arrays and viewtypes

2020-07-10 Thread Hongwei Xi
Here is another possibility:

var raw = (recv_buf, recv_sz)
var tmp = (recv_buf_pf, view@raw | addr@ raw)
val _ = array_foreach_funenv( ..., tmp)
val (recv_buf_pf, raw_pf | _) = tmp
prval () = view@raw := raw_pf


On Fri, Jul 10, 2020 at 2:23 AM Hongwei Xi  wrote:

> There are indeed two raw_pf in this case.
>
> Try this:
>
> val (recv_buf_pf, raw_pf1 | _) = tmp
> prval () = raw_pf := raw_pf1
>
> On Fri, Jul 10, 2020 at 2:16 AM Dambaev Alexander 
> wrote:
>
>> Hi,
>>
>> Thanks for your answers.
>>
>> For now, I had tried this:
>>
>> vtypedef VT = [l1:agz]
>>( array_v(char?, l, recv_sz)
>>, (ptr l, size_t recv_sz) @ l1
>>| ptr l1
>>)
>> (* ... *)
>> var raw with raw_pf = (recv_buf, recv_sz)
>> var tmp = (recv_buf_pf, raw_pf | addr@ raw)
>> val _ = array_foreach_funenv( ..., tmp)
>> val (recv_buf_pf, raw_pf | _) = tmp
>>
>> But I am getting compile error:
>> error(3): the linear dynamic variable [raw_pf$4825(-1)] needs to be
>> preserved but it is consumed instead.
>> error(3): the linear dynamic variable [raw_pf$4828(-1)] needs to be
>> consumed but it is preserved with the type [S2Eat(S2Etyrec(flt0; npf=-1;
>> 0=S2Eapp(S2Ecst(ptr); S2Evar(l(8545))), 1=S2Eapp(S2Ecst(size_t);
>> S2Evar(recv_sz(8544, S2Evar(l1$8709(14460)))] instead.
>>
>> so it looks like compiler thinks, that there are 2 different raw_pf
>> proofs. Is it expected or had I found some bug?
>>
>> Now I will try with datavtypes
>>
>> пт, 10 июл. 2020 г. в 05:48, :
>>
>>> Hi Alexander,
>>>
>>> I guess you could also pass a reference to a stack allocated variable,
>>> but that would probably be very difficult to use due to proofs,
>>> initialization and the fact you’d be using a tuple.
>>>
>>> Much easier to use what you’ve already found or what Hongwei describes.
>>>
>>> Sent from my iPhone
>>>
>>> On 10 Jul 2020, at 04:12, Dambaev Alexander 
>>> wrote:
>>>
>>> 
>>> For now, I have found the only way to achieve my goal is by using boxed
>>> tuples/boxed records:
>>>
>>> vtypedef VT = (array_v(char?,l,recv_sz) | '( ptr l, size_t recv_sz))
>>> (*...*)
>>> var tmp = (recv_buf_pf | '( recv_buf, recv_sz))
>>>
>>> I don't know if this a best way though, as I suppose, that boxed tuple
>>> is heap-allocated and I don't know how to cleanup such tuple without GC
>>>
>>> чт, 9 июл. 2020 г. в 23:54, Dambaev Alexander :
>>>
>>>> And again, I had mistyped one thing in initial email:
>>>>
>>>> (* ... *)
>>>> var tmp = (recv_buf_pf | recv_buf) (* var instead of val in both
>>>> similar lines *)
>>>> (* ... *)
>>>>
>>>>
>>>> чт, 9 июл. 2020 г. в 23:47, ice.r...@gmail.com :
>>>>
>>>>> Hi,
>>>>>
>>>>> I am trying to understand how to use array_foreach_env function to
>>>>> pass to fwork environment of more than 1 variables (of viewt@ype).
>>>>> For example, I can successfully use following:
>>>>>
>>>>> vtypedef VT = (array_v(char?, l, recv_sz | ptr l)
>>>>> fn walker
>>>>> ( array_v(pollfd_t, fdsl, nfds)
>>>>> , x : _t >> _
>>>>> , env: !VT
>>>>> ): void =
>>>>> (* body goes here *)
>>>>>
>>>>> val tmp = (recv_buf_pf | recv_buf)
>>>>> val () = array_foreach_funenv
>>>>>
>>>>>{array_v(pollfd_t, fdsl,nfds)}
>>>>>{VT}
>>>>>( fds_pf | fds, nfds, walker, tmp)
>>>>> val (recv_buf_pf | _) = tmp
>>>>>
>>>>> But, as soon as I want to use VT of type
>>>>> vtypedef VT = (array_v(char?, l, recv_sz) | ptr l, size_t recv_sz)
>>>>> (* ... *)
>>>>> val tmp = (recv_buf_pf | recv_buf, recv_sz)
>>>>> (* .. *)
>>>>> val (recv_buf_pf | _) = tmp
>>>>>
>>>>> I am getting the following error:
>>>>> error(3): mismatch of sorts:
>>>>> the needed sort is [S2RTbas(S2RTBASimp(2; viewtype))];
>>>>> the actual sort is [S2RTbas(S2RTBASimp(3; viewt0ype))].
>>>>>
>>>>> How can I fix this error? Thanks in andvance
>

Re: arrays and viewtypes

2020-07-10 Thread Hongwei Xi
There are indeed two raw_pf in this case.

Try this:

val (recv_buf_pf, raw_pf1 | _) = tmp
prval () = raw_pf := raw_pf1

On Fri, Jul 10, 2020 at 2:16 AM Dambaev Alexander 
wrote:

> Hi,
>
> Thanks for your answers.
>
> For now, I had tried this:
>
> vtypedef VT = [l1:agz]
>( array_v(char?, l, recv_sz)
>, (ptr l, size_t recv_sz) @ l1
>| ptr l1
>)
> (* ... *)
> var raw with raw_pf = (recv_buf, recv_sz)
> var tmp = (recv_buf_pf, raw_pf | addr@ raw)
> val _ = array_foreach_funenv( ..., tmp)
> val (recv_buf_pf, raw_pf | _) = tmp
>
> But I am getting compile error:
> error(3): the linear dynamic variable [raw_pf$4825(-1)] needs to be
> preserved but it is consumed instead.
> error(3): the linear dynamic variable [raw_pf$4828(-1)] needs to be
> consumed but it is preserved with the type [S2Eat(S2Etyrec(flt0; npf=-1;
> 0=S2Eapp(S2Ecst(ptr); S2Evar(l(8545))), 1=S2Eapp(S2Ecst(size_t);
> S2Evar(recv_sz(8544, S2Evar(l1$8709(14460)))] instead.
>
> so it looks like compiler thinks, that there are 2 different raw_pf
> proofs. Is it expected or had I found some bug?
>
> Now I will try with datavtypes
>
> пт, 10 июл. 2020 г. в 05:48, :
>
>> Hi Alexander,
>>
>> I guess you could also pass a reference to a stack allocated variable,
>> but that would probably be very difficult to use due to proofs,
>> initialization and the fact you’d be using a tuple.
>>
>> Much easier to use what you’ve already found or what Hongwei describes.
>>
>> Sent from my iPhone
>>
>> On 10 Jul 2020, at 04:12, Dambaev Alexander 
>> wrote:
>>
>> 
>> For now, I have found the only way to achieve my goal is by using boxed
>> tuples/boxed records:
>>
>> vtypedef VT = (array_v(char?,l,recv_sz) | '( ptr l, size_t recv_sz))
>> (*...*)
>> var tmp = (recv_buf_pf | '( recv_buf, recv_sz))
>>
>> I don't know if this a best way though, as I suppose, that boxed tuple is
>> heap-allocated and I don't know how to cleanup such tuple without GC
>>
>> чт, 9 июл. 2020 г. в 23:54, Dambaev Alexander :
>>
>>> And again, I had mistyped one thing in initial email:
>>>
>>> (* ... *)
>>> var tmp = (recv_buf_pf | recv_buf) (* var instead of val in both similar
>>> lines *)
>>> (* ... *)
>>>
>>>
>>> чт, 9 июл. 2020 г. в 23:47, ice.r...@gmail.com :
>>>
 Hi,

 I am trying to understand how to use array_foreach_env function to pass
 to fwork environment of more than 1 variables (of viewt@ype).
 For example, I can successfully use following:

 vtypedef VT = (array_v(char?, l, recv_sz | ptr l)
 fn walker
 ( array_v(pollfd_t, fdsl, nfds)
 , x : _t >> _
 , env: !VT
 ): void =
 (* body goes here *)

 val tmp = (recv_buf_pf | recv_buf)
 val () = array_foreach_funenv

{array_v(pollfd_t, fdsl,nfds)}
{VT}
( fds_pf | fds, nfds, walker, tmp)
 val (recv_buf_pf | _) = tmp

 But, as soon as I want to use VT of type
 vtypedef VT = (array_v(char?, l, recv_sz) | ptr l, size_t recv_sz)
 (* ... *)
 val tmp = (recv_buf_pf | recv_buf, recv_sz)
 (* .. *)
 val (recv_buf_pf | _) = tmp

 I am getting the following error:
 error(3): mismatch of sorts:
 the needed sort is [S2RTbas(S2RTBASimp(2; viewtype))];
 the actual sort is [S2RTbas(S2RTBASimp(3; viewt0ype))].

 How can I fix this error? Thanks in andvance

 --
 You received this message because you are subscribed to a topic in the
 Google Groups "ats-lang-users" group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/ats-lang-users/A60YvQACw4c/unsubscribe
 .
 To unsubscribe from this group and all its topics, send an email to
 ats-lang-users+unsubscr...@googlegroups.com.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/ats-lang-users/6826800e-17e0-4554-8470-3a7e304bc71bn%40googlegroups.com
 
 .

>>> --
>> 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-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ats-lang-users/CAHjn2KzgHoKJMAVypUCv17xYrB%2BFoycUySXYJknvrNVackkGqw%40mail.gmail.com
>> 
>> .
>>
>> --
>> 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 

Re: bit operations

2020-07-08 Thread Hongwei Xi
In general, if you want to call a C function in ATS,
you can just use 'extfcall' for external function calls.
Of course, if you do so, you bypass ATS type-checking.
Here is an example:

%{^
int lsl(uint u, int n) { return (u << n); }
int lsr(uint u, int n) { return (u >> n); }
%}

implement
main0() =
{
val
pow_2_10 =
$extfcall(uint, "lsl", 1, 10)
val () = println!("pow_2_10 = ", pow_2_10)
}

On Wed, Jul 8, 2020 at 10:56 AM Dambaev Alexander 
wrote:

> Thanks, I will check it out
>
> ср, 8 июл. 2020 г. в 14:30, Hongwei Xi :
>
>> You can find these operations in prelude/SATS/integer.sats
>> There are called:
>> lnot (for ~),
>> land (for &), lor (for |), lxor (for ^), lsl (for <<), and lsr (for >>).
>>
>> These operations are for unsigned ints. For signed ints, there
>> are asl (for <<) and asr (for >>).
>>
>> In ATS2, there is no implicit casting. You may have to cast a
>> signed int into an unsigned int explicitly in order to perform a bit
>> operation.
>>
>>
>> On Wed, Jul 8, 2020 at 5:33 AM ice.r...@gmail.com 
>> wrote:
>>
>>>
>>> Hi,
>>> I was not able to find bit operations
>>> in ATS, like &, |, <<, >>.
>>>
>>> Does ATS supports them?
>>>
>>> --
>>> 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-users+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/ats-lang-users/04b44a32-88e3-4855-acb9-ed7bdcc3391en%40googlegroups.com
>>> <https://groups.google.com/d/msgid/ats-lang-users/04b44a32-88e3-4855-acb9-ed7bdcc3391en%40googlegroups.com?utm_medium=email_source=footer>
>>> .
>>>
>> --
>> 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-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLr4FG-ai8xBPn-C4ZPQiXxYr0gjmLNcpy%3DcnG6ydivyVA%40mail.gmail.com
>> <https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLr4FG-ai8xBPn-C4ZPQiXxYr0gjmLNcpy%3DcnG6ydivyVA%40mail.gmail.com?utm_medium=email_source=footer>
>> .
>>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CAHjn2KzT18QD6_GYseq2guD_%3DQ8aMwnwKHhW8dqC%3DTJfLN7aHg%40mail.gmail.com
> <https://groups.google.com/d/msgid/ats-lang-users/CAHjn2KzT18QD6_GYseq2guD_%3DQ8aMwnwKHhW8dqC%3DTJfLN7aHg%40mail.gmail.com?utm_medium=email_source=footer>
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLqSbMjt-1pbGP-D-4%3DkZgJkrGbae3azsAQ3rc6RhRS-Rg%40mail.gmail.com.


Re: bit operations

2020-07-08 Thread Hongwei Xi
You can find these operations in prelude/SATS/integer.sats
There are called:
lnot (for ~),
land (for &), lor (for |), lxor (for ^), lsl (for <<), and lsr (for >>).

These operations are for unsigned ints. For signed ints, there
are asl (for <<) and asr (for >>).

In ATS2, there is no implicit casting. You may have to cast a
signed int into an unsigned int explicitly in order to perform a bit
operation.


On Wed, Jul 8, 2020 at 5:33 AM ice.r...@gmail.com 
wrote:

>
> Hi,
> I was not able to find bit operations
> in ATS, like &, |, <<, >>.
>
> Does ATS supports them?
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/04b44a32-88e3-4855-acb9-ed7bdcc3391en%40googlegroups.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLr4FG-ai8xBPn-C4ZPQiXxYr0gjmLNcpy%3DcnG6ydivyVA%40mail.gmail.com.


Re: ATS2: need help with arrays

2020-07-07 Thread Hongwei Xi
fun {n: nat | n > 0}{l: addr}
  poll

should be changed to

fun poll{n: nat | n > 0}{l: addr}

Or you can write

fun poll{n:pos}{l: addr}


On Tue, Jul 7, 2020 at 3:31 AM Dambaev Alexander 
wrote:

> Missed the return type of poll()
> ```
> fun {n: nat | n > 0}{l: addr}
>   poll
>   ( fds_pf: !array_v( pollfd_t, l, n) >> _ (* proof, that we have
> access to address range (l,n), which contains initialized array of elements
> of type pollfd_t *)
>   | fds: ptr l (* address *)
>   , nfds: size_t n (* range size *)
>   , timeout: int
>  ): int = "ext#"
> ```
>
>
> вт, 7 июл. 2020 г. в 07:28, ice.r...@gmail.com :
>
>>
>> Hi,
>> I need to provide a type for exteenal call poll() from libc.
>>
>> My initial try was that:
>> ```
>> typedef pollfd_t = $extype_struct"struct pollfd" of
>> { fd = int
>> , events = sint
>> , revents = sint
>> }
>> fun {n: nat | n > 0}{l: addr}
>>   poll
>>   ( fds_pf: !array_v( pollfd_t, l, n) >> _ (* proof, that we have
>> access to address range (l,n), which contains initialized array of elements
>> of type pollfd_t *)
>>   | fds: ptr l (* address *)
>>   , nfds: size_t n (* range size *)
>>   , timeout: int
>>  ) = "ext#"
>> ```
>>
>> Then I try to use it:
>> ```
>> fn foo(): void  = {
>>   val nfds = g1int2uint_int_size(1)
>>   val (fds_pf, fds_free_pf | fds_addr) = array_ptr_alloc(nfds)
>>   (* how should I initialize array here so fds_pf will switch it's type
>> from array_v(pollfd_t?, l, nfds) into array_v(pollfd_t, l, nfds)? *)
>>val _ = poll( fds_pf | fds_addr, nfds)
>>val () = array_ptr_free( fds_pf, fds_free_pf | fds_addr)
>> }
>> ```
>>
>> I was not able to understand how should I proof to compiler,. that I had
>> initialized array at fds_addr. I had tried to use `array_iforeach`, but it
>> does not require any proofs, so fds_pf keeps being uninitialized
>>
>> Based on:
>> 1. type of array_ptr_free (which expects fds_pf to be of type
>> array_v(pollfd_t?,l,n));
>> 2. the fact, that most of functions in array.sats are working with flat
>> arrays, for example, array_iforeach, which has type
>> ```
>> fun {a:vt0p}
>>array_iforeach
>>   {n:int}
>>   ( A0: &(@[INV(a)][n]) >> @[a][n]
>>   , asz: size_t(n)
>>   ) : sizeLte(n) // end of [array_iforeach]
>> ```
>> I conclude, that I misunderstood the purpose of array_v and it's
>> interconnection with flat arrays.
>>
>> So my questions are:
>> 1. what should be the type of poll()?
>> 2. Am I using  array_v(pollfd_t,l,n) correctly or is there other
>> motivation behind array_v?
>> 3. why array_foreach and etc do not require proofs?
>> 4. And how could I switch fds_pf's type from uninitialized to initialized
>> array with some library function (I saw the implementation of
>> array_ptr_tabulate in the tutorial, but I thought, that if std library does
>> not use similar types for functions, then I misunderstood something)
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "ats-lang-users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/ats-lang-users/w6OiwDxucBM/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> ats-lang-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ats-lang-users/558eb0ab-3306-45e6-ad62-5054afbe26ebn%40googlegroups.com
>> 
>> .
>>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CAHjn2Kzy3_ntef7S%2BdDGGNnONAGwvsxO%2BmmaPa0D5NNQx-oO7A%40mail.gmail.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLrP6oh95aMsTYbsQkJiRR_GGh4gP6KwnYHT2hoCC1Nxng%40mail.gmail.com.


Re: ATS templates vs. C++ templates

2020-07-06 Thread Hongwei Xi
Wow! This is wild C++ code :)

Can't support variadic stuff in ATS3. The type system for type-checking
in the presence of variadicity would be too complicated.

I did an imitation of your code in ATS3:

#extern
fun

 // N = n-i


dotprodN2
( i0: int(i)
, xs: array(a, n)
, ys: array(a, n)): a
(* ** ** *)
impltmp
{a:t0}
{n:i0
,i:i0}
dotprodN2
(_, _, _) = g_0()
(* ** ** *)
impltmp
{a:t0}
{D:t0}
{n:i0
,i:i0}
dotprodN2

{n-i >= 1}
(i0, xs, ys) =
sub(xs,i0)*sub(ys,i0)+
dotprodN2(i0+1, xs,ys)
(* ** ** *)
val ans3 =
dotprodN2(0, B3, B3)
(* ** ** *)

Right now, dependent type-checking is not yet implemented. Once dependent
type-checking is available, one should be able to capture array-bounds
errors
(even in template implementations).

In C++, templates are not type-checked; only template instantiations are
type-checked.
In ATS, templates are type-checked before they can be used in
instantiations. I suppose
that these two designs are rooted in fundamentally different philosophies
regarding program
correctness and program verification.

--Hongwei



On Mon, Jul 6, 2020 at 3:34 PM Matthias Wolff 
wrote:

> Some thoughts about the example (c++).
>
> In general this pattern is often used. This special example has the
> disadvantage,
> that the type T and the size N must be in any case explicitely declared in
> the call
> DotProduct::result(...). So here are two alternatives - dp1 and
> dp2.
> The first one uses fold expressions in combination with variadic templates
> and the
> second "if constexpr" for breaking the recursion.
> (btw. inline is default within the struct)
>
> #include 
> #include 
> #include 
>
> namespace detail {
>
> template
> T dp_(T ()[N], T ()[N], std::index_sequence) {
> return ((a[I] * b[I])+...);
> }
>
> }
>
> template
> T dp1(T ()[N], T ()[N]) {
>
> return detail::dp_(a,b,std::make_index_sequence{});
> }
>
>
> template
> T dp2(T ()[N], T ()[N]) {
>
> if constexpr (N == P) { return T{0}; } else {
>
> return a[P] * b[P] + dotprod(a,b);
> }
> }
>
> int main()
> {
> int a[] = {1,2,3};
> int b[] = {4,5,6};
>
> std::cerr << dp2<0>(a,b) << std::endl;
>
> std::cerr << dp1(a,b) << std::endl;
>
> return 0;
> }
>
> Am 06.07.20 um 18:31 schrieb gmhwxi:
>
>
> Here is an example of template metaprogramming in ATS3:
>
> (* ** ** *)
> abstype Z
> abstype S(type)
> (* ** ** *)
> #extern
> fun
> 
> 
> 
> dotprodN
> ( xs: array(a, n)
> , ys: array(a, n)): a
> (* ** ** *)
> impltmp
> {a:t0}
> dotprodN
> <0>(_, _) = g_0()
> (* ** ** *)
> impltmp
> {a:t0}
> {N:t0}
> {n1:i0}
> dotprodN
> 
> {n1 > 0}(xs, ys) =
> head(xs)*head(ys)+dotprodN(tail(xs),tail(ys))
> (* ** ** *)
>
> The above ATS code roughly corresponds to the following C++ code:
>
> template
>
> struct DotProductT {
>
> static inline T result(T* a, T* b) {
>
> return *a * *b + DotProduct::result(a+1,b+1);
>
> }
>
> };
>
> *// partial specialization as end criteria*
>
> template
>
> struct DotProductT {
>
> static inline T result(T*, T*) {
>
> return T{};
>
> }
>
> };
>
>
>
>
> On Sunday, July 5, 2020 at 6:53:44 PM UTC-4, gmhwxi wrote:
>>
>>
>> When I see a programming feature, I tend to ask myself immediately how
>> such a feature
>> can be implemented. Not trying to get the fine details. Just the big
>> picture.
>>
>> The template system in C++ is first and foremost a macro system. Of
>> course, in order to
>> better understand C++, we need to start with C.
>>
>> In programming language implementation, we face the issue of binding of
>> names early on.
>> Basically, if a function foo is used in some code, we need to figure out
>> where the 'foo' is declared.
>>
>> For instance, static binding in ATS3 is handled in the module trans12
>> (for translating from level-1
>> o level-2).
>>
>> C originates from assembly, which explains very well the way in which
>> binding is handled in C.
>> Every function in C is given a unique global name. If there are two
>> functions of the same name,
>> a link-time error is to be reported (by the command, say, ld). By the
>> way, if I ever want to make sure
>> that a chosen name is globally unique, I often just map the name to a
>> dummy C function (assuming
>> I am compiling to C); a link-time error is to occur if the name turns out
>> to be not unique.
>>
>> The C++ template system handles binding like C but with a twist, that is,
>> overloading resolution. In short,
>> if there are two or more declarations for a name, say. foo, then there
>> needs to be a way to determine
>> which of these declarations should be selected. C++ makes heavy use of
>> the types of the arguments of
>> foo when determine the selection. Once a template/macro declaration is
>> selection, it is used to perform
>> macro expansion; and the expanded code goes through type-checking.
>>
>> ATS does binding based on the model of lambda-calculus, which is the gold
>> standard for static 

Re: Will Traits and Concepts be supported in ATS3?

2020-07-05 Thread Hongwei Xi
Thanks for the writing!

I feel that I have now acquired a pretty clear picture as to how C++
templates
are implemented. Not the details. Just the big picture. I will put into a
post what
I have learned and then outline what kind problem I am trying to address
with a
trait-like feature in ATS3. In any case, there is currently NO plan to
implement such
a feature. Just food for thought.


On Sun, Jul 5, 2020 at 12:42 PM Matthias Wolff 
wrote:

> Hi,
>
> concerning the type traits I think a problem description is better than
> trying to say what it is.
>
> The more features a compiler provides so more time will be needed to
> produce an object. Projects become bigger and bigger and the compile
> time increases up to an hour and more.
>
> Analyzing the problem shows that beside the slowdown of the compiler
> the dependencies among the headers (sats staload) are a big problem.
> Including dats files (staload) can also be a problem and if it is possible
> in
> sats files, it must be forbidden. That says the analyzing expert.
>
> An important measure is to introduce more forwardings in the sats, that
> means introducing more abstypes and moving implementations - only c++ -
> to the cpp files.
>
> Sidenote: In c++ class forwardings make it necessary to use pointers or
> references in the function declarations. Also worth to mention that the
> object oriented aspect of member data increases the danger of couplings.
> In ats a pointer forwarding has the shape - abst@ype abc = ptr. So it's
> not
> necessary to rewrite the function.
>
> But writing only - abst@ype abc - leads later to the include of one dats
> into
> another dats. That means potential recompilation because of dats
> dependencies (fortunately patsopt is able to produce dep-files).
>
> Now it's time we remove the sats include. But it is not as easy as it
> could
> be because the removed sats file may contain more information related to
> the newly introduces abstype, which will be needed.
>
> One class of such information could be defines. Defines can be separated
> and included separately. There may be other problem classes to be
> considered. Perhaps there exists a problem class in ats that motivates to
> introduce traits. But it is difficult to say, if the problem classes of
> coupling
> are the same as in c++ (need more practise).
>
> It's import to separate the developers in two categories. Standard library
> developers and normal application developers. I don't think that more
> than 10% percent of all c++ developers have an ideas what traits are
> and even they know it, the motivation is low to use it. This may be
> totally
> different regarding the standard library developers.
>
> Therefore the flexibility of the compiler design to be able to follow
> the requirements coming from active developers will be the key.
>
> I press it into this posting:
>
> A) implementation guard: from the optics -
> It looks like context related implementation selection.
> Type classes?
>
> B) Mappings - datatype (constructor selection by index / perhaps breaks ML
> traditions)
>  abst@ype circle = ptr
>  abs@ype rectangle = ptr
>
>  datatype shape(t@ype) = shape(circle) of ... | shape(rectangle) of
> ...
>
>  instead of
>
>  datatype shape = cons_circle(circle) 
>
> C) Mappings - datasort (index support like B))
>
> Currently I'm completely satisfied with ATS2. Still enough to learn.
>
> Sorry for the length.
>
> Regards, Matthias
>
> Am 04.07.20 um 00:15 schrieb gmhwxi:
>
>
> >>I would say traits are type properties
>
> I like your description :)
>
> ##
>
> Let me use some pseudo code to illustrate a kind of support for traits
> that can be quickly implemented for ATS3.
>
> Say we have a template:
>
> #extern
> fun
> 
> foo(x: a): void
>
> And we have two different implementations for foo:
>
> impltmp
> {a}
> foo(x) = (* first *)
>
> impltmp
> 
> foo(x) = (* second *)
>
> Now we have two instances of foo in our code:
>
> val () = foo(100)
> val () = foo("100")
>
> Say that the first instance should use the first implementation of foo
> and the second instance should use the second implementation of foo.
> To achieve this, we could introduce a trait called FOO2 for the second
> implementation:
>
>
> impltmp
> 
> FOO2(a) => foo(x) = (* second *) // the pseudo syntax means that this
> implementation is guarded by FOO2(a)
>
> Let FOO2 be given the following implementations:
>
> impltmp
> {a:type}
> FOO2 = true
> impltmp
> FOO2 = false
>
> To compile the instance foo, the second implementation is first
> picked; but the guard FOO2 is false;
> so this implementation is skipped and the first implementation is picked
> next.
>
> ##
>
> Using traits for constructing guards is a low-hanging fruit. We could
> certainly think of ways for traits to be used to
> guide template resolution in a more profound manner.
>
> --Hongwei
>
>
>
>
>
> On Friday, July 3, 2020 at 4:29:29 PM UTC-4, Matthias Wolff wrote:
>>
>> C++ Term Traits:
>>
>> I 

Re: Witnessing the effectiveness of types in detecting bugs

2020-07-05 Thread Hongwei Xi
This is just my personal experience. It is difficult for me to
quantify it. My perspective is from my work on implementing
typed and untyped languages. I will say more elsewhere about
some lessons I learned.

My very point here is that we don't get to see a lot of bugs simply
because our bug detection method is not effective enough to flush
them out for us to see. In other words, there are a lot of bugs lurking
around, waiting to get triggered with some specific input or environment.

There are some interesting similarities between viruses like
COVID-19 and bugs in code. An infectious virus is often much
easier to spread if it is less lethal. This is a bit like bugs causing
memory leaks. As such bugs don't cause immediate crashes, we
can reasonably assume that they must be abundant out there.

>>with optional type checking being seemingly more popular

Gradual typing is a trendy topic nowadays. For instance, Racket is
well-known for its support of gradual typing.

It is not like that we need every program to be memory leak-free. The
real question is how to make sure that you can do it if you want a
particular
program to be memory leak-free. I don't see how this can be done with
the kind of gradual typing in Racket.

>>how much does functional programming improve safety and catch errors?

This question is too big :)

In terms of resource handling, functional vs. imperative is a bit like
socialism
vs. capitalism :)

Functional programs don't have memory leaks because they don't own memories
in the first place. You can say functional programming improves memory
safety in
this regard. And I can claim that I have never lost a single boxing match
in my life.
Well, I have participated in none.

--Hongwei

On Sun, Jul 5, 2020 at 8:37 AM Brandon Barker 
wrote:

> I feel like this could make for an interesting publication, though I'll
> admit, maybe it has been done; I haven't really looked. There are probably
> a few type systems out there where this sort of thing is possible nowadays
> with optional type checking being seemingly more popular. I think a more
> difficult question to answer from an empirical standpoint is: how much does
> functional programming improve safety and catch errors?
>
> On Sat, Jul 4, 2020 at 10:38 PM gmhwxi  wrote:
>
>>
>> I did this sort of practice before. And I paid a closer attention this
>> time.
>>
>> I implemented an interpreter for ATS3 that could handle programs
>> containing
>> type-errors. I tried it to test some of the ATS3 library code (consisting
>> of about 15K
>> lines for now). After I got the non-dependent type-checker for ATS3
>> working, I tried
>> type-checking the library code (that had already passed unit tests). Did
>> I find bugs?
>> A large number of them. And I have been writing this kind of code for
>> more than 20
>> years!
>>
>> Once I get the dependent and linear type-checker ready, I am certain that
>> many more
>> bugs will be flushed out. In particular, I am certain that a lot of
>> memory leak bugs will
>> be detected.  If I extrapolate a bit, I am pretty certain that the bug
>> ratio in C and C++
>> code is quite significant.
>>
>> Regarding the COVID-19 cases out there, I suppose we can find many more
>> of them if
>> our detection method becomes more effective. The same can be said about
>> the bugs in
>> our code.
>>
>> --Hongwei
>>
>> --
>> 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-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ats-lang-users/97b1c18a-ae9b-4f17-9322-2122edd1a004o%40googlegroups.com
>> 
>> .
>>
>
>
> --
> Brandon Barker
> brandon.bar...@gmail.com
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CAORbNRpXJBFObChSYRepeXP4VQtn94T-oyFBp_WNzR7FjgbXCg%40mail.gmail.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLp9-p6SftMjMJUTokwwHV59P9cbZkTS4g99b-zCeAQs-Q%40mail.gmail.com.


Re: The current status of ATS3 - forgot lambdas

2020-07-03 Thread Hongwei Xi
Thanks for these clarifying examples.

Now I think my guess is correct that C++ does *not *support embedded
template
implementations. Let me introduce an example to make my point.

Say we want pairs in our code. Traditionally, we declare a class(or struct)
in C++.
Then there will be a constructor for creating pairs:

class pair {  }

With the support for embeddable templates in ATS, there is another way. We
don't have
to have a constructor for pairs; we can just implement member functions for
pairs based
on some contextual data:

extern
fun pair_fst(): a
extern
fun pair_snd(): b

fun

pair_swap(): (b, a) = (pair_snd(), pair_fst())

fun
foo(x: int) =
let
  fun bar(y: int) =  let
impltmp pair_fst<>() = x
impltmp pair_snd<>() = y in pair_swap()
  end
in
  ...
end

In the above example, x and y are treated as the first and second components
of a pair. In particular, there is no pair construction here. Why is this a
very useful feature?
Well, let's think about plain C-arrays (with no attached size information).
But without size
information, a C-array cannot be used safely. In ATS, the size of a C-array
can be "gleaned"
from a context where the C-array is used. Specifically, the programmer can
implement something
like the following code to tell the compiler how to find the size
information:

impltmp

array_length(A) =  (of the type int(n))

##

Can this style of programming be done in C++?

Essentially, this means that one needs to introduce pair_fst and pair_snd
in an embedded manner as is illustrated below. My *guess* is that C++ does
*not *support this style of programming:

fun

pair_swap(): (b, a) = (pair_snd(), pair_fst())

fun
foo(x: int) =
let
  fun bar(y: int) =
  let
fun pair_fst<>() = x // [pair_fst] is embedded here
fun pair_snd<>() = y // [pair_snd] is embedded here
  in
 pair_swap()
  end
in
  ...
end








On Fri, Jul 3, 2020 at 9:54 AM Matthias Wolff 
wrote:

> A lambda is a shortcut for a function object with exactly on parenthesis
> operator implemented
>
> struct function
> {
> function(int k) : j(k) {}
>
> void operator(auto i) { cout << i << "/" << k << endl; }
>
> int j;
>
> };
>
> application: function(1)(2) or in two steps auto f = function(1); f(2)
>
> lambda:
>
> auto j = 1
>
> auto f = [j](int i) { cout << i << "/" << j << endl; };
>
> The capture copy j is like the member j of struct function.
>
> application: f(2)
>
> Therefore it's clear if I can use a lambda within a normal c-function it
> must be possible
> to declare a class/struct within a function - if there is some logic
> behind.
>
> So now I'm complete.
>
>
>
> Am 03.07.20 um 15:03 schrieb Matthias Wolff:
>
> C++ templates restricted to functions show only one half oft the truth.
>
> template
> struct function;
>
> struct XXX;
>
> template<>
> struct function {
>
> template
> void operator()(std::ostream& s, const A&... a) {
>(s  << ... << a);
> }
> };
>
> struct YYY;
>
> template<>
> struct function {
>
> template
> void operator()(const A&... a) {
>(s td::cout << ... << a);
> }
> };
>
> int main()
> {
>
> //using function object - additional constructor parenthesis
> function()(std::cout,"a",1);
>
> function()(1,"a");
>
> return 0;
>
> }
>
> Template power in c++ starts with structs or classes and templated normal
> functions
> are often used to redirect the call to templated structs and their
> specializations. Where
> structs/classes may have many also templated methods and many inner
> classes and
> yes a function - I think - can have inner structs:
>
> void my_function()
> {
> struct abc { void print() { std::cout << "ok" << std::endl; } };
>
> abc().print();
> }
> Variadic templates are really powerful "template struct
> mystruct" and next
> template type deduction.
>
> Template are not a weak point in C++. But if you look in direction of
> category theory, one can
> very quickly recognize, that this topic is a black hole. C++ has no
> mathematical inspiration and
> the same is most the time true for the programmers.
>
> Perhaps I could transport a little bit more on c++ template feelings.
>
>
> Am 03.07.20 um 08:46 schrieb gmhwxi:
>
>
> I had originally assumed that the following style of ATS template
> implementation
> could also be done in C++. But I realized that this is* not *the case
> after studying
> C++ templates tonight.
>
> fun
> 
> g_print(x: a): void
>
> impltmp
> {a:type}
> g_print(xs) = ...
>
> Did I miss something about C++ templates? It seems that the template
> parameters
> of a template implementation in C++ must be variables.
>
> --Hongwei
>
> On Tuesday, June 30, 2020 at 4:04:29 PM UTC-4, gmhwxi wrote:
>>
>> Hi Artyom,
>>
>> I will try to answer other questions later.
>>
>> >>Why are ATS3 templates more powerful than C++ templates? Could you
>> contrast the two in some way?
>>
>> I have to say that I do not 

Re: The current status of ATS3

2020-07-03 Thread Hongwei Xi
Thanks for your explanation.

I will start another thread to talk about variadic stuff.

On Fri, Jul 3, 2020 at 9:03 AM Matthias Wolff 
wrote:

> C++ templates restricted to functions show only one half oft the truth.
>
> template
> struct function;
>
> struct XXX;
>
> template<>
> struct function {
>
> template
> void operator()(std::ostream& s, const A&... a) {
>(s  << ... << a);
> }
> };
>
> struct YYY;
>
> template<>
> struct function {
>
> template
> void operator()(const A&... a) {
>(s td::cout << ... << a);
> }
> };
>
> int main()
> {
>
> //using function object - additional constructor parenthesis
> function()(std::cout,"a",1);
>
> function()(1,"a");
>
> return 0;
>
> }
>
> Template power in c++ starts with structs or classes and templated normal
> functions
> are often used to redirect the call to templated structs and their
> specializations. Where
> structs/classes may have many also templated methods and many inner
> classes and
> yes a function - I think - can have inner structs:
>
> void my_function()
> {
> struct abc { void print() { std::cout << "ok" << std::endl; } };
>
> abc().print();
> }
> Variadic templates are really powerful "template struct
> mystruct" and next
> template type deduction.
>
> Template are not a weak point in C++. But if you look in direction of
> category theory, one can
> very quickly recognize, that this topic is a black hole. C++ has no
> mathematical inspiration and
> the same is most the time true for the programmers.
>
> Perhaps I could transport a little bit more on c++ template feelings.
>
>
> Am 03.07.20 um 08:46 schrieb gmhwxi:
>
>
> I had originally assumed that the following style of ATS template
> implementation
> could also be done in C++. But I realized that this is* not *the case
> after studying
> C++ templates tonight.
>
> fun
> 
> g_print(x: a): void
>
> impltmp
> {a:type}
> g_print(xs) = ...
>
> Did I miss something about C++ templates? It seems that the template
> parameters
> of a template implementation in C++ must be variables.
>
> --Hongwei
>
> On Tuesday, June 30, 2020 at 4:04:29 PM UTC-4, gmhwxi wrote:
>>
>> Hi Artyom,
>>
>> I will try to answer other questions later.
>>
>> >>Why are ATS3 templates more powerful than C++ templates? Could you
>> contrast the two in some way?
>>
>> I have to say that I do not use C++ on a regular basis.
>> C++ used to be C + classes + templates. By the way, I often jokingly tell
>> others this is what the two plusses in
>> C++ stand for :)
>>
>> C does not support inner functions. C++ used to support no inner
>> functions. Now C++ support 'lambdas', with
>> which you can implement inner functions. But can you implement inner
>> templates in C++?
>>
>> ATS supports embedded templates (that is, inner templates). I don't know
>> whether C++ supports inner templates.
>> If it doesn't. then ATS is more powerful in this regard. This is a big
>> deal because inner templates are used ubiquitously
>> in ATS library code.
>>
>> Also, with dependent types and linear types, you can do a great deal more
>> of static checking on templates,
>> flushing out potential bugs. The introduction of features like concepts
>> in C++ tells me that template-related
>> bugs can be quite nasty, cutting big into the benefits from using
>> templates.
>>
>> Maybe "powerful" is not the right word. There is raw power and there is
>> controlled power. Kind of like nuclear
>> bombs versus nuclear power plants. I was mostly talking about the latter.
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> On Tue, Jun 30, 2020 at 2:55 PM Artyom Shalkhakov <...> wrote:
>>
>>> Hi Hongwei,
>>>
>>> Thank you very much for this work!
>>>
>>> On Monday, June 29, 2020 at 9:40:33 PM UTC+3, gmhwxi wrote:


 For those interested in ATS3.

 Before I take a break, I would like to give you an update on the
 implementation of ATS3.

 To put things into some sort of perspective, let me first say a few
 words on the motivation behind ATS3.

 Advised by Prof. Frank Pfenning, I did my PhD thesis on PROGRAM
 VERIFICATION during my years at CMU, designing and implementing DML
 (Dependently Typed ML), a programming language that extends ML with a
 restricted form of dependent types. Note that DML is the predecessor of
 ATS.
 These days, the dependent types in DML are often referred to as
 DML-style
 dependent types in the literature (in contrast to Martin-Lof's
 dependent types
 that were originally invented for creating a type-theoretic foundation
 for Mathematics).

 As you can see, there are two words in PROGRAM VERIFICATION. One must
 talk about program construction when talking about program
 verification. Originally, the kind of programs I intended to verify
 were supposedly written in an ML-like language. But it soon (even
 before 

Re: The current status of ATS3

2020-07-03 Thread Hongwei Xi
Thanks for clarifying.

In your example, there are three templates named g_print.
In particular, the types/interfaces of these three templates do
not have to be the instantiation of one general type/interface.

In ATS, we have one g_print:

fun g_print(x: a): void

And then three implementations:

impltmp g_print = ...
impltmp g_print = ...
impltmp{a:type} g_print = ...

This subtle difference affects how type-checking is performed.

In C++, template instantiation/resolution is done first and then
type-checking is performed on the result
of instantiation/resolution.

In ATS, ML-like algebraic type-checking is done before template resolution.
And linear and dependent
type-checking on the result of template resolution is planned to be done
after.


On Fri, Jul 3, 2020 at 7:55 AM Chris Double 
wrote:

> On Fri, Jul 3, 2020 at 6:46 PM gmhwxi  wrote:
> >
> > Did I miss something about C++ templates? It seems that the template
> parameters
> > of a template implementation in C++ must be variables.
>
> I think this C++ example does what you are trying, unless I'm
> misunderstanding the ATS code:
>
> --8<--
> #include 
> #include 
>
> template  void g_print(T const& x) {
> std::cout << "case 1" << std::endl;
> }
>
> template <> void g_print(int const& x) {
> std::cout << "case 2" << std::endl;
> }
>
> template  void g_print(std::list const& x) {
> std:: cout << "case 3" << std::endl;
> }
>
> int main() {
> g_print("hello");
> g_print(5);
> std::list l;
> g_print(l);
> return 0;
> }
> --8<--
>
> It prints out:
>
> case 1
> case 2
> case 3
>
> Chris.
> --
> https://bluishcoder.co.nz
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CALn1vHEpfccad3EydBsRjLsoxWo%3DgBgUGQVfD-naT9BYqTeqOQ%40mail.gmail.com
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLpBhXx%3DvaySfrkZSuoF4KfS5zL--sjzgEMX59UkCVczqQ%40mail.gmail.com.


Re: The current status of ATS3

2020-07-01 Thread Hongwei Xi
>>I'm wondering how are ATS3 templates different from ATS2 templates?

Here is a simple but very telling example:

fun

array_length(A0: array(a, n)): int(n)

The type array(T, N) is for a C-array of size N for storing values of type
T.
Given that the size information of a C-array is not attached to the array,
the function
array_length can only be implemented in a context where the size
information can be
obtained in some manner.

In ATS3 (but not in ATS2), we can implement a template of the following
interface:

fun

foo{n:int}(A0: array(a, n)): void

In ATS2, we have to change the interface to

fun

foo{n:int](A0: array(a, n), size: int(n)): void

In other words, in ATS3, the size of a C-array does not have to be passed
together with
the C-array; it can be "gleaned" from the context instead.

By the way, I remember you once asked a question on the tabulate function
template. In
ATS3, it can finally be properly done:

fun

tabulate(): list(a, n)

fun

tabulate$for{i:nat | i < n}(int(i)): a

Here is some running code that could clarify further:

https://github.com/xanadu-lang/xinterp/blob/master/TEST/prelude/array.dats

Cheers!






On Tue, Jun 30, 2020 at 3:39 PM Hongwei Xi  wrote:

> Hi Artyom,
>
> I will try to answer other questions later.
>
> >>Why are ATS3 templates more powerful than C++ templates? Could you
> contrast the two in some way?
>
> I have to say that I do not use C++ on a regular basis.
> C++ used to be C + classes + templates. By the way, I often jokingly tell
> others this is what the two plusses in
> C++ stand for :)
>
> C does not support inner functions. C++ used to support no inner
> functions. Now C++ support 'lambdas', with
> which you can implement inner functions. But can you implement inner
> templates in C++?
>
> ATS supports embedded templates (that is, inner templates). I don't know
> whether C++ supports inner templates.
> If it doesn't. then ATS is more powerful in this regard. This is a big
> deal because inner templates are used ubiquitously
> in ATS library code.
>
> Also, with dependent types and linear types, you can do a great deal more
> of static checking on templates,
> flushing out potential bugs. The introduction of features like concepts in
> C++ tells me that template-related
> bugs can be quite nasty, cutting big into the benefits from using
> templates.
>
> Maybe "powerful" is not the right word. There is raw power and there is
> controlled power. Kind of like nuclear
> bombs versus nuclear power plants. I was mostly talking about the latter.
>
>
>
>
>
>
>
>
>
> On Tue, Jun 30, 2020 at 2:55 PM Artyom Shalkhakov <
> artyom.shalkha...@gmail.com> wrote:
>
>> Hi Hongwei,
>>
>> Thank you very much for this work!
>>
>> On Monday, June 29, 2020 at 9:40:33 PM UTC+3, gmhwxi wrote:
>>>
>>>
>>> For those interested in ATS3.
>>>
>>> Before I take a break, I would like to give you an update on the
>>> implementation of ATS3.
>>>
>>> To put things into some sort of perspective, let me first say a few
>>> words on the motivation behind ATS3.
>>>
>>> Advised by Prof. Frank Pfenning, I did my PhD thesis on PROGRAM
>>> VERIFICATION during my years at CMU, designing and implementing DML
>>> (Dependently Typed ML), a programming language that extends ML with a
>>> restricted form of dependent types. Note that DML is the predecessor of
>>> ATS.
>>> These days, the dependent types in DML are often referred to as DML-style
>>> dependent types in the literature (in contrast to Martin-Lof's dependent
>>> types
>>> that were originally invented for creating a type-theoretic foundation
>>> for Mathematics).
>>>
>>> As you can see, there are two words in PROGRAM VERIFICATION. One must
>>> talk about program construction when talking about program
>>> verification. Originally, the kind of programs I intended to verify
>>> were supposedly written in an ML-like language. But it soon (even
>>> before 2008) became very clear to me that such a language badly lacks
>>> meta-programming support. And I immediately started to improvise. I
>>> first added some support for templates into ATS1 and then strengthened
>>> it in ATS2.  Unfortunately, the kind of support for templates in ATS2
>>> was in direct conflict with the support for dependent types. The
>>> original primary motivation for ATS3 was to eliminate this (crippling)
>>> conflict.
>>>
>>> Up to ATS2, I mostly did language implementation for the purpose of
>>> experimenting with a variety of programming f

Re: The current status of ATS3

2020-06-30 Thread Hongwei Xi
Hi Artyom,

I will try to answer other questions later.

>>Why are ATS3 templates more powerful than C++ templates? Could you
contrast the two in some way?

I have to say that I do not use C++ on a regular basis.
C++ used to be C + classes + templates. By the way, I often jokingly tell
others this is what the two plusses in
C++ stand for :)

C does not support inner functions. C++ used to support no inner functions.
Now C++ support 'lambdas', with
which you can implement inner functions. But can you implement inner
templates in C++?

ATS supports embedded templates (that is, inner templates). I don't know
whether C++ supports inner templates.
If it doesn't. then ATS is more powerful in this regard. This is a big deal
because inner templates are used ubiquitously
in ATS library code.

Also, with dependent types and linear types, you can do a great deal more
of static checking on templates,
flushing out potential bugs. The introduction of features like concepts in
C++ tells me that template-related
bugs can be quite nasty, cutting big into the benefits from using templates.

Maybe "powerful" is not the right word. There is raw power and there is
controlled power. Kind of like nuclear
bombs versus nuclear power plants. I was mostly talking about the latter.









On Tue, Jun 30, 2020 at 2:55 PM Artyom Shalkhakov <
artyom.shalkha...@gmail.com> wrote:

> Hi Hongwei,
>
> Thank you very much for this work!
>
> On Monday, June 29, 2020 at 9:40:33 PM UTC+3, gmhwxi wrote:
>>
>>
>> For those interested in ATS3.
>>
>> Before I take a break, I would like to give you an update on the
>> implementation of ATS3.
>>
>> To put things into some sort of perspective, let me first say a few
>> words on the motivation behind ATS3.
>>
>> Advised by Prof. Frank Pfenning, I did my PhD thesis on PROGRAM
>> VERIFICATION during my years at CMU, designing and implementing DML
>> (Dependently Typed ML), a programming language that extends ML with a
>> restricted form of dependent types. Note that DML is the predecessor of
>> ATS.
>> These days, the dependent types in DML are often referred to as DML-style
>> dependent types in the literature (in contrast to Martin-Lof's dependent
>> types
>> that were originally invented for creating a type-theoretic foundation
>> for Mathematics).
>>
>> As you can see, there are two words in PROGRAM VERIFICATION. One must
>> talk about program construction when talking about program
>> verification. Originally, the kind of programs I intended to verify
>> were supposedly written in an ML-like language. But it soon (even
>> before 2008) became very clear to me that such a language badly lacks
>> meta-programming support. And I immediately started to improvise. I
>> first added some support for templates into ATS1 and then strengthened
>> it in ATS2.  Unfortunately, the kind of support for templates in ATS2
>> was in direct conflict with the support for dependent types. The
>> original primary motivation for ATS3 was to eliminate this (crippling)
>> conflict.
>>
>> Up to ATS2, I mostly did language implementation for the purpose of
>> experimenting with a variety of programming features. At this point, I
>> no longer feel that I have time and/or energy to continue
>> experimenting. Compared to ATS2, I re-designed the implementation of
>> ATS3 to make it much more modular so as to better support future
>> changes and additions. I intend for ATS3 to eventually become a language
>> of production quality.
>>
>> ATS3 is implemented in ATS2. There are three big components planned
>> for ATS3: program construction (Part I), program compilation (Part 2),
>> and program verification (Part 3).
>>
>> ##
>>
>> Part 1:
>>
>> At this moment, I have nearly finished Part I.
>>
>> This part covers type inference (involving only ML-style algebraic
>> types) and template resolution (this is, replacing template instances
>> with proper template-free code).  There is currently a rudimentary
>> interpreter available for interpreting programs constructed in ATS3. I
>> have also being implementing a template-based prelude library for
>> ATS3.
>>
>
> I'm wondering how are ATS3 templates different from ATS2 templates?
>
>
>> Part 2:
>>
>> I will soon be starting to work on Part 2 after taking a break, hoping
>> to finish something that can be tested at the end of the Summer.
>>
>> Part 3:
>>
>> This part essentially does type-checking involving linear types and
>> dependent types. Hopefully, I will be able to get a running implementation
>> by the Spring next year.
>>
>> ##
>>
>> Based on what I have experimented so far, I find the current support
>> for templates in ATS3 to be a game-changing programming feature that
>> can greatly increase one's programming productivity. I am a bit amazed
>> by it :) If you think that the templates in C++ are powerful, then you
>> will find that the templates in ATS3 are even more powerful in many
>> aspects. Actually, not only just more powerful but also a great deal
>> safer. Keep 

  1   2   3   4   >