Linear component may be abandoned


#1

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 (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
(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,


#2

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): bOn Thursday, July 14, 2016 at 10:39:08 AM UTC-4, gmhwxi wrote:

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

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

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

On Thu, Jul 14, 2016 at 9:20 AM, Steinway Wu <> wrote:

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 (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
(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,


#3

stream_vt_con is considered an internal type; it should be kept as such.

fun {a,b:vt@ype} stream_vt_map$fopr (a - 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 - b): b

On Thursday, July 14, 2016 at 10:39:08 AM UTC-4, gmhwxi wrote:

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

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

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

On Thu, Jul 14, 2016 at 9:20 AM, Steinway Wu <> wrote:

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 (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
(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,


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/f72cd27d-4084-41b6-a6fe-b94a7e3e1563%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/f72cd27d-4084-41b6-a6fe-b94a7e3e1563%40googlegroups.com?utm_medium=email&utm_source=footer
.


#4

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

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

  2. The ‘xs’ on the right-hand side is a variable (with address); its
    content needs to be taken out before free@ can be called.On Thu, Jul 14, 2016 at 9:20 AM, Steinway Wu stein...@gmail.com wrote:

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 (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
(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,


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
https://groups.google.com/d/msgid/ats-lang-users/a443c141-c62d-49a3-88d9-68ab64640cbb%40googlegroups.com?utm_medium=email&utm_source=footer
.


#5

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.On Thursday, July 14, 2016 at 1:41:00 PM UTC-4, Steinway Wu 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): b

On Thursday, July 14, 2016 at 10:39:08 AM UTC-4, gmhwxi wrote:

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

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

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

On Thu, Jul 14, 2016 at 9:20 AM, Steinway Wu <> wrote:

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 (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
(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,