I had checked some more and was able to make a stateful numbers generator
using list_vt for accumulating of evaluated results here
https://github.com/dambaev/mobt2/blob/master/ats2/src/TEST/test5.dats but
for some reason, it takes forever to complete with default constraint <=
g0int_npow( 2, 24) using linear streams

I guess is due to list_vt_extent, which is O(n)

I was trying to pass pointer to a tail of the list_vt data to pass through
auxmain/auxmain_con to make extend to be O(1), but I was not able to
satisfy type checker :) So I decided to ask if it is possible to use such
pointer/hole to the tail in the environment of $ldelay?

вс, 10 июл. 2022 г. в 03:12, gmhwxi <gmh...@gmail.com>:

>
> 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 <gmh...@gmail.com>:
>>
>>> 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
>>>
>>> real    0m23.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.dats
>>>> hwxi@hongwei-t440p:/tmp$ time ./primes
>>>> 1077871
>>>>
>>>> real    0m3.118s
>>>> user    0m3.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
>>>>
>>>> real    0m8.195s
>>>> user    0m8.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
>>>>
>>>> real    0m2.120s
>>>> user    0m2.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 <gmh...@gmail.com>:
>>>>>
>>>>>> 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 <ice.r...@gmail.com>
>>>>>> wrote:
>>>>>>
>>>>>>> Hi,
>>>>>>>
>>>>>>> I had tried to implement function of type:
>>>>>>>
>>>>>>> ```
>>>>>>> fun
>>>>>>>   {a:t0p}
>>>>>>>   isPrime
>>>>>>>   ( xs: !stream_vt( int)
>>>>>>>   , x: int
>>>>>>>   ):<cloptr1>
>>>>>>>   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
>>>>>>>   ):<cloptr1>
>>>>>>>   ( 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-user...@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
>>>>>>> <https://groups.google.com/d/msgid/ats-lang-users/CAHjn2KwFq7JH%2BiZE7bWCJ_L7oZ38K-kmGBFii7DZsdxWLDsGmg%40mail.gmail.com?utm_medium=email&utm_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-user...@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
>>>>>> <https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLqp62MaoG8hugJ8h2mUt%2BsSAJ2eu6uRuJ%3D5nMOc4EbcfQ%40mail.gmail.com?utm_medium=email&utm_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-user...@googlegroups.com.
>>>
>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/ats-lang-users/d87d273b-c937-40b8-ae6a-8846a9fbb801n%40googlegroups.com
>>> <https://groups.google.com/d/msgid/ats-lang-users/d87d273b-c937-40b8-ae6a-8846a9fbb801n%40googlegroups.com?utm_medium=email&utm_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/69a5b6f5-69e9-48dd-9b1d-aa164f9b0566n%40googlegroups.com
> <https://groups.google.com/d/msgid/ats-lang-users/69a5b6f5-69e9-48dd-9b1d-aa164f9b0566n%40googlegroups.com?utm_medium=email&utm_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/CAHjn2Ky0URPmxCYFYQeT64KqcTxcLnRw7e4W0LKS8CAkqcdsjw%40mail.gmail.com.

Reply via email to