ср, 2 янв. 2019 г. в 09:41, aditya siram <aditya.si...@gmail.com>:

> Awesome. That does typecheck but when I try to build it with:
>
> "$PATSHOME/bin/patscc" -O3 -flto -s -D_GNU_SOURCE -DATS_MEMALLOC_LIBC -I${
> PATSHOME}/contrib -O3 -o triples triples.dats -latslib
>
>
>
I don't have a compiler with me here but it seems like the function should
be made into a template (i.e. the type parameters should be put prior to
the function's name in the declaration).

This typechecks and the online compiler will accept it:

fun test (): void = {
  val xs = stream_vt_make_cons ((g0ofg1)1, stream_vt_make_cons ((g0ofg1)2,
stream_vt_make_nil{int} ()))

  val ys = stream_vt_make_cons ((g0ofg1)"x", stream_vt_make_cons
((g0ofg1)"y", stream_vt_make_nil{string} ()))

  val zs = merge<int><string> (xs, ys)

  val l = stream2list_vt (zs)
  val () = println!(l) // should print something like: 1,x; 2,y

  val () = list_vt_free(l)
}

Unfortunately I can't run it (the glot.io-provided compiler doesn't support
stream_vt_make_* functions).


> I get:
>
> /home/deech/ATS/test/ATS/ATS2/ccomp/runtime/pats_ccomp_instrset.h:276:35:
> error: assignment to expression with array type
>  #define ATSINSmove(tmp, val) (tmp = val)
>                                    ^
> triples_dats.c:1062:1: note: in expansion of macro ‘ATSINSmove’
>  ATSINSmove(tmp19, ATSSELcon(env0, postiats_tysum_3, atslab__0)) ;
>  ^~~~~~~~~~
> /home/deech/ATS/test/ATS/ATS2/ccomp/runtime/pats_ccomp_instrset.h:276:35:
> error: assignment to expression with array type
>  #define ATSINSmove(tmp, val) (tmp = val)
>                                    ^
> triples_dats.c:1070:1: note: in expansion of macro ‘ATSINSmove’
>  ATSINSmove(tmp21, ATSSELcon(env1, postiats_tysum_4, atslab__0)) ;
>  ^~~~~~~~~~
> /home/deech/ATS/test/ATS/ATS2/ccomp/runtime/pats_ccomp_instrset.h:327:65:
> error: assignment to expression with array type
>  #define ATSINSstore_fltrec_ofs(tmp, tyrec, lab, val) ((tmp).lab = val)
>                                                                  ^
> triples_dats.c:1093:1: note: in expansion of macro ‘ATSINSstore_fltrec_ofs
> ’
>  ATSINSstore_fltrec_ofs(tmp23, postiats_tyrec_2, atslab__0, tmp19) ;
>  ^~~~~~~~~~~~~~~~~~~~~~
> /home/deech/ATS/test/ATS/ATS2/ccomp/runtime/pats_ccomp_instrset.h:327:65:
> error: assignment to expression with array type
>  #define ATSINSstore_fltrec_ofs(tmp, tyrec, lab, val) ((tmp).lab = val)
>                                                                  ^
> triples_dats.c:1094:1: note: in expansion of macro ‘ATSINSstore_fltrec_ofs
> ’
>  ATSINSstore_fltrec_ofs(tmp23, postiats_tyrec_2, atslab__1, tmp21) ;
>  ^~~~~~~~~~~~~~~~~~~~~~
>
>
>
>
> On Wednesday, January 2, 2019 at 1:21:24 AM UTC-6, Artyom Shalkhakov wrote:
>>
>> Hello Aditya!
>>
>> I've modified this a bit by inserting freeing:
>>
>> fun merge
>>   {a: t@ype}
>>   {b: t@ype}
>>   (
>>     s1: stream_vt a,
>>     s2: stream_vt b
>>   ) : stream_vt(@(a,b)) =
>>   let
>>     val _s1 = !s1
>>     val _s2 = !s2
>>   in
>>     $ldelay
>>      (
>>       (
>>       case+ (_s1,_s2) of
>>       | (~stream_vt_cons(_s1e, _s1s),
>>          ~stream_vt_cons(_s2e, _s2s)) =>
>>              stream_vt_cons(@(_s1e,_s2e), merge(_s1s,_s2s))
>>       | (~stream_vt_nil (), _) => (stream_vt_con_free(_s2);
>> stream_vt_nil())
>>       | (_, ~stream_vt_nil ()) => (stream_vt_con_free(_s1);
>> stream_vt_nil())
>>       )
>>      , (stream_vt_con_free(_s1); stream_vt_con_free(_s2))
>>      )
>>   end
>>
>> This type-checks (but I have not run it).
>>
>> $ldelay requires us to supply as its second argument an expression that
>> will free up all resources that are used in its first argument.
>>
>> ср, 2 янв. 2019 г. в 08:10, aditya siram <aditya...@gmail.com>:
>>
>>> I trying to understand the stream_vt datatype by writing a function
>>> that merges two streams in a stream of tuples but not having much luck, the
>>> following:
>>>
>>> fun merge
>>>   {a: t@ype}
>>>   {b: t@ype}
>>>   (
>>>     s1: stream_vt a,
>>>     s2: stream_vt b
>>>   ) : stream_vt(@(a,b)) =
>>>   let
>>>     val _s1 = !s1
>>>     val _s2 = !s2
>>>   in
>>>     $ldelay
>>>      (
>>>       case+ (_s1,_s2) of
>>>       | (~stream_vt_cons(_s1, _s1s),
>>>          ~stream_vt_cons(_s2, _s2s)) =>
>>>              stream_vt_cons((_s1,_s2), merge(_s1s,_s2s))
>>>       | (_,_) => stream_vt_nil()
>>>      )
>>>   end
>>>
>>> gives me the errors:
>>>
>>> ...: 465(line=27, offs=9) -- 590(line=29, offs=57): error(3): the
>>> dynamic variable [_s2$4720(-1)] is consumed but it should be retained
>>> with the type [S2Eapp(S2Ecst(stream_vt_con); S2Evar(b(8451)))] instead.
>>> ...: 465(line=27, offs=9) -- 590(line=29, offs=57): error(3): the
>>> dynamic variable [_s1$4719(-1)] is consumed but it should be retained
>>> with the type [S2Eapp(S2Ecst(stream_vt_con); S2Evar(a(8450)))] instead.
>>> ...: 368(line=20, offs=3) -- 636(line=32, offs=6): error(3): the linear
>>> dynamic variable [_s1$4719(-1)] needs to be consumed but it is
>>> preserved with the type [S2Eapp(S2Ecst(stream_vt_con); S2Evar(a(8450)))]
>>> instead.
>>> ...: 368(line=20, offs=3) -- 636(line=32, offs=6): error(3): the linear
>>> dynamic variable [_s2$4720(-1)] needs to be consumed but it is
>>> preserved with the type [S2Eapp(S2Ecst(stream_vt_con); S2Evar(b(8451)))]
>>> instead.
>>> patsopt(TRANS3): there are [4] errors in total.
>>> exit(ATS): uncaught exception:
>>> _2home_2deech_2ATS_2triples_2dats_2ATS_2ATS2_2src_2pats_error_2esats__FatalErrorExn
>>> (1025)
>>>
>>> Any help is appreciated.
>>>
>>> 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-user...@googlegroups.com.
>>> To post to this group, send email to ats-lan...@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/21f9263f-e0be-4dcb-8bf6-45031eaea85a%40googlegroups.com
>>> <https://groups.google.com/d/msgid/ats-lang-users/21f9263f-e0be-4dcb-8bf6-45031eaea85a%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>
>>
>> --
>> Cheers,
>> Artyom Shalkhakov
>>
> --
> 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/ee6d25b3-4790-4d5e-b1d0-e61d66f20a7a%40googlegroups.com
> <https://groups.google.com/d/msgid/ats-lang-users/ee6d25b3-4790-4d5e-b1d0-e61d66f20a7a%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
Cheers,
Artyom Shalkhakov

-- 
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/CAKO6%3DqjDxYVB0tpavjh_nZx_R3z4TCk0mzbJUaQrco7TyWU99w%40mail.gmail.com.

Reply via email to