I annotated your code as follows:

  fun{a:t@ype} eval(x:Expr a): a =
    case+ x of
    | I i => i
    | B b => b
    | Add (t1, t2) => eval<int>(t1) + eval<int>(t2)
    | Mul (t1, t2) => eval<int>(t1) * eval<int>(t2)
    | Eq{a2}(t1, t2) => equals<a2>(eval<a2>(t1), eval<a2>(t2))

As a2 can be any type, the ATS compiler cannot find code for equals<a2>
(nor for eval<a2>).


On Mon, Oct 15, 2018 at 9:51 PM Chris Double <chris.dou...@double.co.nz>
wrote:

> I have some GADT code that fails at the C compilation stage. It's a
> variant of:
>
> https://gist.github.com/doublec/a3cc8f3431cabe9a319c8e7ba27e7890
>
> But the Eq constructor of Expr uses the type index instead of being
> 'int' so equality can be done against booleans and ints. The full code
> is:
>
> ----------------8<---------------
> #include "share/atspre_define.hats"
> #include "share/atspre_staload.hats"
>
> datatype Expr(a:t@ype)  =
>   | I(int) of int
>   | B(bool) of bool
>   | Add(int) of (Expr int, Expr int)
>   | Mul(int) of (Expr int, Expr int)
>   | Eq(bool) of (Expr a, Expr a)
>
> extern fun{a:t@ype} equals(t1:a, t2:a): bool
> implement equals<int>(t1,t2) = g0int_eq(t1,t2)
> implement equals<bool>(t1,t2) = eq_bool0_bool0(t1,t2)
>
> fun{a:t@ype} eval(x:Expr a): a =
>   case+ x of
>   | I i => i
>   | B b => b
>   | Add (t1, t2) => eval(t1) + eval(t2)
>   | Mul (t1, t2) => eval(t1) * eval(t2)
>   | Eq (t1, t2) => equals(t1, t2)
>
> implement main0() = let
>   val term1 = Eq(I(5), Add(I(1), I(4)))
>   val term2 = Mul(I(2), I(4))
>   val res1 = eval(term1)
>   val res2 = eval(term2)
> in
>   println!("res1=", res1, " and res2=", res2)
> end
> ----------------8<---------------
>
> This fails to compile at the C stage with:
>
> In file included from arith3_dats.c:15:0:
> arith3_dats.c: In function ‘eval_2__2__1’:
> arith3_dats.c:1098:24: error: ‘PMVtmpltcstmat’ undeclared (first use
> in this function)
>  ATSINSmove(tmpret2__1,
> PMVtmpltcstmat[0](equals<S2EVar(5554)>)(tmp9__1, tmp10__1)) ;
>                         ^
> ATS2-Postiats-0.3.11//ccomp/runtime/pats_ccomp_instrset.h:276:37:
> note: in definition of macro ‘ATSINSmove’
>  #define ATSINSmove(tmp, val) (tmp = val)
> ....
>
> Any thoughts on what I'm doing wrong?
>
> --
> https://bluishcoder.co.nz
>
> --
> 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/CALn1vHGGZyh8VFq3p63LRtWxjvGx-mXg1f_dBAZHR99hmwTQsg%40mail.gmail.com
> .
>

-- 
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/CAPPSPLrMsBR9XXHUtW9JmSRuA4kKCdcXEcx0cAwb3WtiDkHoKw%40mail.gmail.com.

Reply via email to