Linear component may be abandoned.

124 views
Skip to first unread message

Steinway Wu

unread,
Jul 14, 2016, 9:20:49 AM7/14/16
to ats-lang-users
Hi, 

In `stream_vt.dats`, I saw the following snippets,

fun {a:vt0p} {b:vt0p} stream_vt_map_con (xs: stream_vt (a)) : stream_vt_con (b) = let
    val xs_con = !xs
in
    case+ xs_con of
    | @stream_vt_cons(x, xs) => let
        val y = stream_vt_map$fopr<a><b> (x) // fopr is of type {a,b:vt@ype} &a >> a?! -> b
        val xs = xs
        val () = free@ (xs_con)
      in
        stream_vt_cons{b}(y, stream_vt_map<a><b> (xs))
      end 
    | ~stream_vt_nil((*void*)) => stream_vt_nil()
end


and I have three questions. 

1. what is a?! 
2. why fopr takes &a, instead of just a?
3. what happened when val xs = xs 

Thanks, 

Hongwei Xi

unread,
Jul 14, 2016, 10:39:08 AM7/14/16
to ats-lan...@googlegroups.com
1.

When [a] is a linear type, a?! is only the data part of [a] (that is, there is no view in a?!).
When [a] is non-linear, then a?! is just [a].

2. When [a] is large (containing many bytes), call-by-reference can be more efficient. The convention
    in ATS is to use call-by-reference when linear data is handled.

3. The 'xs' on the right-hand side is a variable (with address); its content needs to be taken out before free@ can be called.




--
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/msgid/ats-lang-users/a443c141-c62d-49a3-88d9-68ab64640cbb%40googlegroups.com.

Steinway Wu

unread,
Jul 14, 2016, 1:41:00 PM7/14/16
to ats-lan...@googlegroups.com
What about this? Let the worker function consume a. And in map, free the constructor, instead of unfold the constructor. 

fun {a,b:vt@ype} stream_vt_map_con (xs: stream_vt a): stream_vt_con b
fun
{a,b:vt@ype} stream_vt_map$fopr (a):<cloref1> b

Hongwei Xi

unread,
Jul 14, 2016, 2:20:23 PM7/14/16
to ats-lan...@googlegroups.com
stream_vt_con is considered an internal type; it should be kept as such.

>> fun {a,b:vt@ype} stream_vt_map$fopr (a -<cloref1> b): b

This is probably easier to use but less efficient when [a] is large. In C, one rarely passes a big struct; always
passes a pointer to a big struct.

stream_vt is very different from stream; stream_vt is essentially just one node (while stream is a list of nodes).
So when using stream_vt, one may use stream_vt(T) for a very big flat T.

On Thu, Jul 14, 2016 at 1:40 PM, Steinway Wu <stein...@gmail.com> wrote:
What about this? Let the worker function consume a. And in map, free the constructor, instead of unfold the constructor. 

fun {a,b:vt@ype} stream_vt_map_con (xs: stream_vt a):
stream_vt_con b
fun
{a,b:vt@ype} stream_vt_map$fopr (a -<cloref1> b): b

--
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.

gmhwxi

unread,
Jul 14, 2016, 2:34:01 PM7/14/16
to ats-lang-users
Maybe what your want is some kind of mapfree function?

Please take a look at list_vt_mapfree.

For stream_vt, it makes sense to process a linear stream until some condition is met
and then process the rest of the stream later.

Yannick Duchêne

unread,
Jun 19, 2018, 12:49:53 PM6/19/18
to ats-lang-users


Le jeudi 14 juillet 2016 16:39:08 UTC+2, gmhwxi a écrit :
1.

When [a] is a linear type, a?! is only the data part of [a] (that is, there is no view in a?!).
When [a] is non-linear, then a?! is just [a].

I thought `a?!` was meaning “initialized” . The data part: does it means `a?!` is of some datatype ?

Hongwei Xi

unread,
Jun 19, 2018, 12:52:58 PM6/19/18
to ats-lan...@googlegroups.com
Conceptually, a view VT equals (V | T), where V is the view and T is the data.
So VT?! equals T.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to ats-lang-users@googlegroups.com.

Yannick Duchêne

unread,
Jun 23, 2018, 5:51:53 AM6/23/18
to ats-lang-users
So if `?!` means “data part” may be it’s better to read `?` as “no data part” instead of “unintitialized”, although it may be implied.

I just wonder where the wording topization (for `?`) and typization (for `?!`) come from. That ’s the wording used in Postiats source. I though about the logical “top” symbol, but it’s unrelated I believe.

Hongwei Xi

unread,
Jun 23, 2018, 7:23:31 AM6/23/18
to ats-lan...@googlegroups.com
Given a type T, T is always a subtype of T?. That is why the word 'top' is used.

--
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+unsubscribe@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.

Yannick Duchêne

unread,
Jul 7, 2018, 11:05:13 AM7/7/18
to ats-lang-users


Le samedi 23 juin 2018 11:51:53 UTC+2, Yannick Duchêne a écrit :
So if `?!` means “data part” may be it’s better to read `?` as “no data part” instead of “unintitialized”, although it may be implied.

[…]

Or may be both. It seems `_`  as a dynamic expression becomes a `D1Etop` (top, again) in Postiats, and a comment about it somewhere says “uninitialized exp”.

I wanted to check something after I learned this, and was surprised to see this:

        static fn f (int): int
        val a = f(_)

… type‑checks.

Hongwei Xi

unread,
Jul 7, 2018, 5:09:20 PM7/7/18
to ats-lan...@googlegroups.com

The symbol '_' refers to a "special" value that is unspecified.
This feature is not yet implemented in ATS2 (and likely will not
in future, either).

If you compile the above code, you will get an error message of
some kind.


--
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+unsubscribe@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.
Reply all
Reply to author
Forward
0 new messages