If efficiency is a big concern, I suggest the coding style shown at:

https://pastebin.com/D8zdEmYH

which minimizes the use of malloc/free.

On Monday, January 1, 2018 at 8:34:12 PM UTC-5, gmhwxi wrote:
>
>
> After reading your code, I guess that the following example could be 
> relevant:
>
>
> http://ats-lang.sourceforge.net/DOCUMENT/INT2PROGINATS/HTML/HTMLTOC/x2223.html
>
> By the way, you could flatten the 'option'-values in your loop:
>
> fun
> {s,a:t@ype}
> getlast
> (
>   str : !Stream(s,a)
> ) : Option_vt(a) =
> loop(f_,s_i,0,mx)
>     where {
>         val mx =
>         $UNSAFE.cast{a}(0)
>         val Stream(s_i,f_) = str
>     fun loop( f  : !s -<cloptr1> Step (s,a),
>                   st : s,
>                   t0 : int, mx : a )
>           : Option_vt(a) =
>                 case f(st) of
>                  | ~Yield(st_,x_) => loop(f,st_, 1, x_)
>                  | ~Skip (st_   ) => loop(f,st_, t0, mx)
>                  | ~Done (      ) => if t0 > 0 then Some_vt(mx) else 
> None_vt()
>       }
>
> I was able to nearly half the execution time by doing the flattening.
>
> There is a safe way to do this. Please see some examples involving 
> opt_none and opt_some.
>
> On Monday, January 1, 2018 at 5:19:16 PM UTC-5, M88 wrote:
>>
>>
>> It is unclear what you translated. Could you show?
>>
>>
>> I was just saying that I didn't expect the compiler to treat 
>> stream-fusion the same way in ATS as it does in Haskell. To your point, I 
>> expected different algorithms.
>>
>> I found the tutorial useful -- implementing a custom allocation routine 
>> was easier than I expected it to be. I managed to get the version with 
>> datavtypes to run as quickly as the stack version (eg, ~12ms).   I need to 
>> refine it a bit more, but that's the start I was looking for.
>>
>> I would be interested in seeing an implementation of a). I attached the 
>> original datavtype version of the code I was using to test.  This is a toy 
>> program that creates a stream and prints the final value.
>>
>

-- 
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 post to this group, send email to ats-lang-users@googlegroups.com.
Visit this group at https://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/d30acf72-c5a5-4d7e-a0f0-e2c61df20b69%40googlegroups.com.

Reply via email to