Read constraints error of compiler in ATS2

hello,
I am just moving to ATS2 now and I find very hard to read errors of
constraints because the compiler does not say which line it refers to.
Is there a trick to locate these kind of errors ?

For example :

… a lot of warnings …
warning(3): s3exp_make_s2exp: s2e0 = S2Einvar(S2Evar(x(4149)))
warning(3): s3exp_make_s2exp: s2e0 = S2Einvar(S2Evar(x(4149)))
warning(3): s3exp_make_s2exp: s2e0 = S2Einvar(S2Evar(x(4149)))
warning(3): s3exp_make_s2exp: s2e0 = S2Eexi(n$3490(6979); ; S2Eapp(S2Ecst(
list_vt); S2Evar(a(4264)), S2Evar(n$3490(6979))))
warning(3): s3exp_make_s2exp: s2e0 = S2Eexi(n$3500(6989); ; S2Eapp(S2Ecst(
list_vt); S2Evar(a(4264)), S2Evar(n$3500(6989))))
warning(3): s3exp_make_s2exp: s2e0 = S2Eexi(n$1054$3487(6976); ; S2Eapp(
S2Ecst(list_vt); S2Einvar(S2Evar(a(4264))), S2Evar(n$1054$3487(6976))))
warning(3): s3exp_make_s2exp: s2e0 = S2Eexi(n$1054$3487(6976); ; S2Eapp(
S2Ecst(list_vt); S2Einvar(S2Evar(a(4264))), S2Evar(n$1054$3487(6976))))
warning(3): s3exp_make_s2exp: s2e0 = S2Einvar(S2Evar(a(4352)))
warning(3): s3exp_make_s2exp: s2e0 = S2Einvar(S2Evar(a(4352)))
warning(3): s3exp_make_s2exp: s2e0 = S2Einvar(S2Evar(a(4357)))
warning(3): s3exp_make_s2exp: s2e0 = S2Einvar(S2Evar(a(4357)))
warning(3): s3exp_make_s2exp: s2e0 = S2EVar(1791)
exit(ATS): [assert] failed: /usr/users/cydu/programming/ATS/ATS-Postiats/src
/pats_constraint3_icnstr.dats: 7854(line=289, offs=14) – 7870(line=289,offs
=30)
*** [/usr/users/cydu/programming/ATS/DEV/ats_samples/frp/lin2/
coroutinelin_dats.c] Error code 1

thanks :slight_smile:

For now, you need it in ATS2 (but not in ATS1).

hi,
my code sample :

#include “share/atspre_staload_tmpdef.hats”

// event signature
absviewtype event_vt (a: vt0p) = ptr

extern castfn event_of_list {a: vt0p}{n: nat} (l: list_vt(a, n)):<>event_vt a
extern castfn list_of_event {a: vt0p} (e: event_vt a):<> [n: nat] list_vt(a,n
)

extern fun{a: t@ype} event_vt_last(e: event_vt(a)): [b: bool] (event_vt(a),option_vt
(a, b))

// get last event
implement{a} event_vt_last(e) = @(e’, last l’) where {
fun {a: t@ype} last {n:nat} (e: list_vt(a, n)): [b: bool] option_vt(a, b)
= case+ e of
| ~list_vt_cons (x, ~list_vt_nil()) => Some_vt{a} x
| ~list_vt_cons (x, y) => last
y
| ~list_vt_nil () => None_vt{a} ()
val l = list_of_event{a} e
val l’ = list_vt_copy
l
val e’ = event_of_list{a} l
}

implement main0(argc, argv) = let
val e = event_of_list $list_vt{int} (1,2,3,4,5)
val (e’, last_e) = event_vt_last e
val l = list_of_event e’
val () = ( case+ last_e of
| ~Some_vt (x) => println! ("last event is ", x)
| ~None_vt () => () ): void
in
list_vt_free l
end

thanks

This is an error from the ATS compiler. Could you post your code somewhere
so that I can take a look?
It seems that a generated constraint cannot be handled by the
constraint-solver.

I’m not sure about the warnings, but it looks like the error’s line and
columns are printed (289 and 14 to 30 in this case).

I went ahead to declare some functions on events:

https://github.com/githwxi/ATS-Postiats/blob/master/doc/PROJECT/SMALL/coroutine/SATS/event.sats

Here is a list-based implementation of evset (event set):

https://github.com/githwxi/ATS-Postiats/blob/master/doc/PROJECT/SMALL/coroutine/DATS/event_list.dats

Though I am still not clear about how events are going to be used, I feel
that a list-based implementation is naive.
Nonetheless, it is a good start.

Here is a rule of thumb for programming in ATS (and in many other languages
as well).

When you use list to implement event, you in general do not write code
manipulating lists directly. Instead,
you try to use existing list-funtions to do what you need. Only if what you
need cannot be implemented (efficiently)
based on existing functions, you try to implement it on your own. For
instance, I just added list_vt_unextend for
your need of list_get_last. If you implement list-functions on your own,
you want to do it in a way so that the code
may be moved into the list-library.

Cheers!

thanks a lot for advices !

By now an event of type T is just a collection of values of type T (mainly
because event query can be sampled at fixed rate and more than one value
can occur between event queries)
I just use list now because it is the easiest way to implement it.

I just work on concepts first, I want to make sure I can make real usage of
it before working more on implementation.

my code ported to ats2 is now here :


My next step is trying to use this paradigm for a simple opengl
visualization with Glfw

I’ll wipe out my redundant code as you noticed me

cheers :wink:

The code needs to be written as follows:

// get last event
implement{a} event_vt_last(e) = @(e’, x) where {
fun last {n:nat} (e: list_vt(a, n)): [b: bool] option_vt(a, b)
= case+ e of
| ~list_vt_cons (x, ~list_vt_nil()) => Some_vt{a} x
| ~list_vt_cons (x, y) => last y
| ~list_vt_nil () => None_vt{a} ()
val l = list_of_event{a} e
val l’ = list_vt_copy l
val e’ = event_of_list{a} l
val x = last l’
}

I changed the constraint solve a bit to report this issue in a more
meaningful way.

I see some serious problems with the following style of implementation.
I would like to get you on the right track of using ATS to implement events.
What is really an event? If you treat ‘event’ as a class, what kind of
methods
do you want to support?

// event signature
absviewtype event_vt (a: vt0p) = ptr

extern castfn event_of_list {a: vt0p}{n: nat} (l: list_vt(a, n)):<>event_vt a
extern castfn list_of_event {a: vt0p} (e: event_vt a):<> [n: nat] list_vt(a,n
)

extern fun{a: t@ype} event_vt_last(e: event_vt(a)): [b: bool] (event_vt(a),option_vt
(a, b))

Sorry to interrupt your discussion, but I have some other questions. For
the first line above,

absviewtype event_vt (a: vt0p) = ptr

Do we really need the “= ptr” part? Alex tells me that “absviewtype” is
boxed, it’s size is already determined.