I changed char to charNZ, and it actually worked! On Sun, Dec 10, 2017 at 9:52 AM, aditya siram <aditya.si...@gmail.com> wrote:
> Oh, thanks! > > So if I wanted to return '(int, charNZ)' instead I'd need some kind of > 'praxi' asserting that it's not null? > > > On Sunday, December 10, 2017 at 8:41:18 AM UTC-6, gmhwxi wrote: > >> This is the best I could come up with. >> >> Mixing templates with dependent types almost always >> causes problems. >> >> (* ****** ****** *) >> // >> #include >> "share/atspre_staload.hats" >> // >> fn >> length_last >> {l:nat | l > 1 } >> ( >> s: string l >> ) : (int, char) = let >> typedef tenv = (int, char) >> var env: tenv = (0,s.head()) >> implement >> stream_vt_foreach$fwork<char><tenv>(c,env) = env := (env.0 + 1, c) >> val-~stream_vt_nil() = >> stream_vt_foreach_env<char><tenv>(streamize_string_char(s.tail()), >> env) >> in >> env >> end >> >> implement >> main0() = let >> val >> tup = >> length_last("abcde") >> in >> println! ("(", tup.0, ", ", tup.1, ")") >> end // end of [main0] >> >> >> On Sun, Dec 10, 2017 at 9:06 AM, aditya siram <aditya...@gmail.com> >> wrote: >> >>> Hi, >>> I'm trying to pass and mutate a stack allocated tuple in a string >>> processing function: >>> >>> fn length_last >>> {l:nat | l > 1 } >>> ( >>> s: string l >>> ): (int, char) = >>> let >>> var env = (0,s.head()) >>> implement stream_vt_foreach$fwork<charNZ><(int,charNZ)>(c,env) = >>> env := (env.0 + 1, c) >>> val _ = stream_vt_foreach_env( >>> streamize_string_char(s.tail()), >>> env >>> ) >>> in >>> env >>> end >>> >>> The stack allocated 'env' should finally have the length of the string >>> and the last character after 'stream_vt_foreach_env' is run. Instead I get >>> compile errors like: >>> length_last.dats:15:13: the dynamic expression should be a left-value >>> but it is not. >>> >>> length_last.dats:11:3: the linear dynamic variable [env$view$5548(-1)] >>> is preserved but with an incompatible type. >>> >>> length_last.dats:11:3: mismatch of static terms (tyleq): >>> >>> The actual term is: S2Etop(knd=0; [1]) >>> [1]: S2EVar(5260) >>> The needed term is: S2Etyrec(flt0; npf=-1; 0=S2Etop(knd=0; S2Etop(knd=0; >>> [1])), 1=S2Etop(knd=0; S2Etop(knd=0; [2]))) >>> [1]: g1int_int_t0ype(int_kind, 0) >>> [2]: charNZ >>> >>> length_last.dats:11:3: mismatch of static terms (tyleq): >>> >>> The actual term is: S2Eat(S2Etop(knd=0; [1]); [2]) >>> [1]: S2EVar(5260) >>> [2]: env >>> The needed term is: S2Eat(S2Etyrec(flt0; npf=-1; 0=S2Etop(knd=0; S2Etop( >>> knd=0; [1])), 1=S2Etop(knd=0; S2Etop(knd=0; [2]))); [3]) >>> [1]: g1int_int_t0ype(int_kind, 0) >>> [2]: charNZ >>> [3]: env >>> patsopt(TRANS3): there are [2] errors in total. >>> exit(ATS): uncaught exception: _2home_2deech_2Downloads_2ATS_ >>> 2ATS2_2src_2pats_error_2esats__FatalErrorExn(1025) >>> >>> Is the problem that I'm passing a stack allocated tuple as the >>> environment? >>> >>> 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/ms >>> gid/ats-lang-users/012ab377-9bd9-401d-b738-b9a3efbfd841%40go >>> oglegroups.com >>> <https://groups.google.com/d/msgid/ats-lang-users/012ab377-9bd9-401d-b738-b9a3efbfd841%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 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/fb4f195c-38b8-4ef9-adbf-ab0deadbcfc0% > 40googlegroups.com > <https://groups.google.com/d/msgid/ats-lang-users/fb4f195c-38b8-4ef9-adbf-ab0deadbcfc0%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 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/CAPPSPLpug02tPij4%3DpK8N0r2VkuUg4XVwK%3DQ4rGzZGS2RAxqEg%40mail.gmail.com.