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
...: 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)
--
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.
"$PATSHOME/bin/patscc" -O3 -flto -s -D_GNU_SOURCE -DATS_MEMALLOC_LIBC -I${PATSHOME}/contrib -O3 -o triples triples.dats -latslib
/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) ;
^~~~~~~~~~~~~~~~~~~~~~
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
To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/ee6d25b3-4790-4d5e-b1d0-e61d66f20a7a%40googlegroups.com.
#include "share/atspre_staload.hats"
extern fun {a:t@ype}{b:t@ype}
merge : (stream_vt a, stream_vt b) -> stream_vt(@(a,b))
implement{a}{b} merge (xs, ys) = let
fun
auxmain (xs: stream_vt a, ys: stream_vt b) : stream_vt(@(a,b)) = $ldelay
(
(
case+ !xs of
| ~stream_vt_nil() => (~ys; stream_vt_nil())
| ~stream_vt_cons(x, xs) =>
case+ !ys of
| ~stream_vt_nil() => (~xs; stream_vt_nil())
| ~stream_vt_cons(y, ys) =>
stream_vt_cons(@(x, y), auxmain(xs, ys))
) ,
(
~xs; ~ys
)
)
in
auxmain(xs, ys)
end
implement main0() =
{
val xs = streamize_list_vt_elt($list_vt{int}(1, 2))
val ys = streamize_list_vt_elt($list_vt{string}("x", "y"))
Yes, this compiles and runs as expected. Although, I am not sure that I have ever used 'stream_vt_con_free'. A slightly different way to do the same without using stream_vt_con_free,
#include "share/atspre_staload.hats"
extern fun {a:t@ype}{b:t@ype}
merge : (stream_vt a, stream_vt b) -> stream_vt(@(a,b))
implement{a}{b} merge (xs, ys) = let
fun
auxmain (xs: stream_vt a, ys: stream_vt b) : stream_vt(@(a,b)) = $ldelay
(
(
case+ !xs of
| ~stream_vt_nil() => (~ys; stream_vt_nil())
| ~stream_vt_cons(x, xs) =>
case+ !ys of
| ~stream_vt_nil() => (~xs; stream_vt_nil())
| ~stream_vt_cons(y, ys) =>
stream_vt_cons(@(x, y), auxmain(xs, ys))
) ,
(
~xs; ~ys
)
)
in
auxmain(xs, ys)
end
To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/5b227e90-3395-44ab-aee7-b648408ae4a2%40googlegroups.com.