How to name a function in ATS3?

91 views
Skip to first unread message

gmhwxi

unread,
Jul 7, 2024, 5:11:56 PM7/7/24
to ats-lang-users

Instead of stating rules, I will just give a few examples. More will be said later.

Computing the length of a given list:

fun list_length(xs: list(a)): sint

Nothing special here. The full name of the function should be list_length_sint

Computing the length of a given linear list:

fun list_vt_length0(xs: list_vt(a)): sint // xs is freed after the call
fun list_vt_length1(xs: !list_vt(a)): sint // xs is still available after the call

Linear list reverse-append:

fun list_vt_rappend01(xs: list_vt(a), ys: !list_vt(a)): list_vt(a)

The full name of the function should be: list_vt_rappend0_llist__llist1.
This name along indicates that the first argument (xs) is consumed;
the second argument (ys) is kept (llist1); the return value is a linear list
(llist).

Enough beans are spilled here :)

Cheers,

--Hongwei



gmhwxi

unread,
Jul 9, 2024, 11:16:13 AM7/9/24
to ats-lang-users
Here are two examples that may be of interest:

fun
<x0:vt>
strm_vt_prepend0__llist0
(strm_vt(x0), list_vt(x0)): strm_vt(x0)

fun
<x0:vt>
strm_vt_prepend0__lstrm0
(strm_vt(x0), strm_vt(x0)): strm_vt(x0)

'strm_vt' means that the subject (1st argument) is a linear stream
'prepend0' is the verb indicating that the object (2nd argument) is
put in front of the subject; the lense 0 means that the subject is to be consumed
llist0/lstrm0 means that the object is a linear list/stream to be consumed by the function.
Reply all
Reply to author
Forward
0 new messages