The support for type inference in ATS2 is weak. Often you need a type annotation for a case-expression (or an if-expression):
implement main0() = { val a = 0 val b = ( case+ a of | 0 => Some_vt(0) *(* 9 *)* | _ => None_vt() *(* 10 *)* ) : Option_vt(int) val () = case+ b of | ~None_vt() => () | ~Some_vt(_) => () } On Tue, Oct 13, 2020 at 10:09 AM Dambaev Alexander <ice.redm...@gmail.com> wrote: > Hi, > > In this example, I am trying to define a binding of type Option_vt(int), > > ``` > #include "share/atspre_staload.hats" > > #define ATS_DYNLOADFLAG 0 > > implement main0() = { > val a = 0 > val b = > case+ a of > | 0 => Some_vt(0) *(* 9 *)* > | _ => None_vt() *(* 10 *)* > val () = > case+ b of > | ~None_vt() => () > | ~Some_vt(_) => () > } > ``` > but I get the following error from the compiler: > ``` > patscc -O2 -DATS_MEMALLOC_LIBC -I"../libs/" -o issue main.dats > /data/devel/ats2/issue/main.dats: 136(line=9, offs=12) -- 146(line=9, > offs=22): error(3): the dynamic expression cannot be assigned the type > [S2EVar(5243)]. > /data/devel/ats2/issue/main.dats: 136(line=9, offs=12) -- 146(line=9, > offs=22): error(3): mismatch of sorts in unification: > The sort of variable is: S2RTbas(S2RTBASimp(1; t@ype)) > The sort of solution is: S2RTbas(S2RTBASimp(2; viewtype)) > /data/devel/ats2/issue/main.dats: 136(line=9, offs=12) -- 146(line=9, > offs=22): error(3): mismatch of static terms (tyleq): > The actual term is: S2Eapp(S2Ecst(option_vt0ype_bool_vtype); > S2Eapp(S2Ecst(g1int_int_t0ype); S2Eextkind(atstype_int), S2Eintinf(0)), > S2Ecst(true_bool)) > The needed term is: S2EVar(5243) > /data/devel/ats2/issue/main.dats: 158(line=10, offs=12) -- 167(line=10, > offs=21): error(3): the dynamic expression cannot be assigned the type > [S2EVar(5243)]. > /data/devel/ats2/issue/main.dats: 158(line=10, offs=12) -- 167(line=10, > offs=21): error(3): mismatch of sorts in unification: > The sort of variable is: S2RTbas(S2RTBASimp(1; t@ype)) > The sort of solution is: S2RTbas(S2RTBASimp(2; viewtype)) > /data/devel/ats2/issue/main.dats: 158(line=10, offs=12) -- 167(line=10, > offs=21): error(3): mismatch of static terms (tyleq): > The actual term is: S2Eapp(S2Ecst(option_vt0ype_bool_vtype); S2EVar(5245), > S2Ecst(false_bool)) > The needed term is: S2EVar(5243) > /data/devel/ats2/issue/main.dats: 200(line=13, offs=7) -- 210(line=13, > offs=17): error(3): the constructor pattern cannot be assigned the type > [S2EVar(5243)]. > /data/devel/ats2/issue/main.dats: 223(line=14, offs=7) -- 234(line=14, > offs=18): error(3): the constructor pattern cannot be assigned the type > [S2EVar(5243)]. > ``` > what is wrong with this example? > > Instead, this example is working: > ``` > #include "share/atspre_staload.hats" > > #define ATS_DYNLOADFLAG 0 > > implement main0() = { > val a = 0 > val b = > * f(a) where { fn f(a:int):<> Option_vt(int) =* > case+ a of > | 0 => Some_vt(0) > | _ => None_vt() > } > val () = > case+ b of > | ~None_vt() => () > | ~Some_vt(_) => () > ``` > I have tried to reread the tutorial, but haven't found something related > to this behavior > > -- > 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 view this discussion on the web visit > https://groups.google.com/d/msgid/ats-lang-users/CAHjn2KxcKRHMZxWkZZTqy7yQLLbx3LQ_FeTGrSn76xvXWh4%2BeQ%40mail.gmail.com > <https://groups.google.com/d/msgid/ats-lang-users/CAHjn2KxcKRHMZxWkZZTqy7yQLLbx3LQ_FeTGrSn76xvXWh4%2BeQ%40mail.gmail.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 view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLot_wFq%2BbqZT4PAUoUM8EEgv_N_uc1FMYb%3Dbn9fhDs%2BEg%40mail.gmail.com.