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.si...@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-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/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/CAKO6%3DqgfQxJLCtbw2j2r7sd6fJwenYw5h31LRmp0zkjEg-t6pQ%40mail.gmail.com.