Rust lang memory management

Rust is able to do support ADT and pattern matching without requiring the
use of GC. Does anyone know how that is achieved? Is everything on stack?
Why can’t ATS do something similar?

Haitao

Ah this is the thread (itself a continuation of a previous thread :slight_smile:
https://groups.google.com/forum/#!searchin/ats-lang-users/heap/ats-lang-users/jtg3f_P-xx0/ihW05rcULccJ

And your answer was that: “Linear values are often not freed; instead, they
turn into non-linear values”

So it seems the answer to my question would still be that it is still not
easy to use ADTs and closures.On Wed, Oct 1, 2014 at 6:55 PM, Haitao Zhang zht...@gmail.com wrote:

That is good to know. Last time we talked (a few months back) I got a
different impression. So this means I can specify what malloc/free ATS uses
to compile ADT and closures? Or do I let them have the default and I can
specify a different set for the manually managed code? Last time I looked
at the instruction set macros of ATS I didn’t think that was possible.

On Wed, Oct 1, 2014 at 6:18 PM, gmhwxi gmh...@gmail.com wrote:

Yes, you can have different sets of malloc/free pairs as long as you
don’t use GC.
If you use GC, then you probably do not want to have different sets of
malloc/free pairs.

On Wednesday, October 1, 2014 7:27:41 PM UTC-4, H Zhang wrote:

Yes that is what regions analysis does. That is a good “poor man”'s
substitute for regions analysis but I think in ATS you can’t really specify
multiple mallocs (?). You would have to drop back to C to do that.

On Wed, Oct 1, 2014 at 4:17 PM, Barry Schwartz <chemoe…@chemoelectric. org> wrote:

H Zhang zht...@gmail.com skribis:

The problem with letting it dangle now and fix it later that is: 1) I
have
to remember doing that and also pick up what I was doing before and 2)
assuming the tools give meaningful warnings so I can go right to
where the
issue is the “fix” would still pollute the code and make it harder to
read.
Really I should be able to say exe_name := file_name_stem + “.exe” and
forget about it. I don’t care about the performance here nor memory
usage.
Just needs it to be safe. But it is a heavy price to pay if I have to
use
Python to get little niceties like this. If 90% of the cases can be
handled
automatically I don’t mind handling the cases that can’t be resolved.
Then
I can reserve the mental energy to use linear types on things that
really
matter to me performance wise (time and space).

In my working days as a C programmer of slow programs that could eat
up memory freely, I used to use a little ‘reaping allocator’ I
wrote. Not at all complicated. Call it instead of malloc directly, and
use it just like malloc, but the allocated pieces had a link field in
them so you could free them all at once. So I’d start up the allocator
at the beginning of routine and put a ‘reap’ at the end. In between, I
could act somewhat as if I had a garbage collector.

Simple solutions often work fine.

(Python OTOH makes things so complicated that I wouldn’t trust a proof
of correctness of some Python code if it existed, and don’t trust
tests.)


You received this message because you are subscribed to a topic in the
Google Groups “ats-lang-users” group.
To unsubscribe from this topic, visit https://groups.google.com/d/
topic/ats-lang-users/a17ftxArgIw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
ats-lang...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit https://groups.google.com/d/
msgid/ats-lang-users/20141001231739.GA16565%40crud.


You received this message because you are subscribed to a topic in the
Google Groups “ats-lang-users” group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/ats-lang-users/a17ftxArgIw/unsubscribe.
To unsubscribe from this group and all its topics, 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 http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/d5a77967-bb91-4bca-aaa9-d6f65c25e36f%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/d5a77967-bb91-4bca-aaa9-d6f65c25e36f%40googlegroups.com?utm_medium=email&utm_source=footer
.

I would not worry about freeing memory at the beginning. I would just
implement the extension and get
it work first. Only after getting a running implementation, I will start to
think about a way to get rid of memory leaks.
With the help of linear types, I feel pretty good about succeeding in
getting rid of leaks at the end. Juggling too many
things at once can easily make you mentally tired, losing the very interest
you need to go forward.On Thu, Oct 2, 2014 at 12:20 AM, Haitao Zhang zht...@gmail.com wrote:

An extension could also call the host which might in turn call the
extension so it could be nested, but that may not be the norm. The problem
is like this:

We have a top level GC’ed interpreter that we want to write extensions
for. The large data structure is held in the extension memory with long
life cycles. The top level can call the extension to query about the data
held there. There are a lot of boiler plates to handle FFI calls to
translate data formats and parse call options etc. In the end some answer
is produced and send back to the top level caller. So the bulk of the
manually allocated linear objects are relatively static. I would like to
be able to use a higher level abstraction than what C could provide for
tasks that don’t involve malloc/free of the long-lived objects so that I
don’t have to worry about the little things. If the calls are not nested
then yes at the end of a call I can just batch free the non-linear objects
(those auto allocated for ADTs, closures etc) that will no longer be
needed. Only the linear objects need to persist between calls.

On Wed, Oct 1, 2014 at 8:59 PM, gmhwxi gmh...@gmail.com wrote:

My understanding is that you only need one allocator. Linear values can
be freed during a call to your library function and non-linear values
are all freed at once at the end of the call.

On Wednesday, October 1, 2014 11:51:03 PM UTC-4, H Zhang wrote:

Thanks for the clarification. I will give this approach some more
thoughts then. Since linear values can turn into non-linear values, the
non-linear allocator possibly needs to free the memory allocated by the
linear allocator, right? But the non-linear allocator would not know what
are pointers in the part of heap it manages, nor would it know if it is
safe to free what they point to?

On Wed, Oct 1, 2014 at 7:33 PM, gmhwxi gmh...@gmail.com wrote:

Moving ahead one step, it would then be nice to distinguish linear and

non-linear allocations so we can have two heaps, one for the linear
structures and one for the nonlinear ones. Before type erasure ATS has
information on what allocations are linear, correct? Is there also a way to
guarantee that linear structures don’t contain pointers to the nonlinear
heap? This way we can also use linear types to return structures without
copying and/or store side effects, safer than using only CFFI? Not sure how
useful or feasible this is.

Linear values are often not freed; instead, they turn into non-linear
value

I think my answer was to the second part of your question (quoted
above). You cannot
have one heap for linear values and another one for non-linear values
because linear values
can be turned into non-linear ones.

Now I think I understand what you want to do. You can just write your
own heap allocator
(as was suggested in your first paragraph).

On Wednesday, October 1, 2014 10:14:27 PM UTC-4, H Zhang wrote:

Ah this is the thread (itself a continuation of a previous thread :slight_smile:
Redirecting to Google Groups
heap/ats-lang-users/jtg3f_P-xx0/ihW05rcULccJ

And your answer was that: “Linear values are often not freed; instead,
they turn into non-linear values”

So it seems the answer to my question would still be that it is still
not easy to use ADTs and closures.

On Wed, Oct 1, 2014 at 6:55 PM, Haitao Zhang zht...@gmail.com wrote:

That is good to know. Last time we talked (a few months back) I got a
different impression. So this means I can specify what malloc/free ATS uses
to compile ADT and closures? Or do I let them have the default and I can
specify a different set for the manually managed code? Last time I looked
at the instruction set macros of ATS I didn’t think that was possible.

On Wed, Oct 1, 2014 at 6:18 PM, gmhwxi gmh...@gmail.com wrote:

Yes, you can have different sets of malloc/free pairs as long as you
don’t use GC.
If you use GC, then you probably do not want to have different sets
of malloc/free pairs.

On Wednesday, October 1, 2014 7:27:41 PM UTC-4, H Zhang wrote:

Yes that is what regions analysis does. That is a good “poor man”'s
substitute for regions analysis but I think in ATS you can’t really specify
multiple mallocs (?). You would have to drop back to C to do that.

On Wed, Oct 1, 2014 at 4:17 PM, Barry Schwartz < chem...@chemoelectric.org> wrote:

H Zhang zht...@gmail.com skribis:

The problem with letting it dangle now and fix it later that is:

  1. I have

to remember doing that and also pick up what I was doing before
and 2)
assuming the tools give meaningful warnings so I can go right to
where the
issue is the “fix” would still pollute the code and make it
harder to read.
Really I should be able to say exe_name := file_name_stem +
“.exe” and
forget about it. I don’t care about the performance here nor
memory usage.
Just needs it to be safe. But it is a heavy price to pay if I
have to use
Python to get little niceties like this. If 90% of the cases can
be handled
automatically I don’t mind handling the cases that can’t be
resolved. Then
I can reserve the mental energy to use linear types on things
that really
matter to me performance wise (time and space).

In my working days as a C programmer of slow programs that could
eat
up memory freely, I used to use a little ‘reaping allocator’ I
wrote. Not at all complicated. Call it instead of malloc directly,
and
use it just like malloc, but the allocated pieces had a link field
in
them so you could free them all at once. So I’d start up the
allocator
at the beginning of routine and put a ‘reap’ at the end. In
between, I
could act somewhat as if I had a garbage collector.

Simple solutions often work fine.

(Python OTOH makes things so complicated that I wouldn’t trust a
proof
of correctness of some Python code if it existed, and don’t trust
tests.)


You received this message because you are subscribed to a topic in
the Google Groups “ats-lang-users” group.
To unsubscribe from this topic, visit https://groups.google.com/d/
topic/ats-lang-users/a17ftxArgIw/unsubscribe.
To unsubscribe from this group and all its topics, send an email
to ats-lang...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/20141001231
739.GA16565%40crud.


You received this message because you are subscribed to a topic in
the Google Groups “ats-lang-users” group.
To unsubscribe from this topic, visit https://groups.google.com/d/to
pic/ats-lang-users/a17ftxArgIw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
ats-lang...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/d5a77967-bb
91-4bca-aaa9-d6f65c25e36f%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/d5a77967-bb91-4bca-aaa9-d6f65c25e36f%40googlegroups.com?utm_medium=email&utm_source=footer
.


You received this message because you are subscribed to a topic in the
Google Groups “ats-lang-users” group.
To unsubscribe from this topic, visit https://groups.google.com/d/
topic/ats-lang-users/a17ftxArgIw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
ats-lang...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit https://groups.google.com/d/
msgid/ats-lang-users/f00755c4-793f-45ef-87a6-dd82e8664a51%
40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/f00755c4-793f-45ef-87a6-dd82e8664a51%40googlegroups.com?utm_medium=email&utm_source=footer
.


You received this message because you are subscribed to a topic in the
Google Groups “ats-lang-users” group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/ats-lang-users/a17ftxArgIw/unsubscribe.
To unsubscribe from this group and all its topics, 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 http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/19d98c70-49ae-4a97-96f0-a2fdd64d6435%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/19d98c70-49ae-4a97-96f0-a2fdd64d6435%40googlegroups.com?utm_medium=email&utm_source=footer
.


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 http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/CAFUyvhryK%2BvJMmCWMr1059-XnB8e8CS3u9XJqVaj5%2B5ehwff5w%40mail.gmail.com
https://groups.google.com/d/msgid/ats-lang-users/CAFUyvhryK%2BvJMmCWMr1059-XnB8e8CS3u9XJqVaj5%2B5ehwff5w%40mail.gmail.com?utm_medium=email&utm_source=footer
.

There is no default malloc/free pair. It has to be specified
by the programmer.

-DATS_MEMALLOC_LIBC: using libc malloc/free
-DATS_MEMALLOC_GCBDW: using Boehm GC

Here is an example showing how to supply a malloc/free pair of your own

https://github.com/githwxi/ATS-Postiats-contrib/tree/master/document/EXAMPLE/CA-HSR2/program-1-2

Quick digression: seems I don’t find this in the contrib directory of my
installation. Should contrib from GitHub be installed instead of that of
from Sourceforge?

Really I should be able to say exe_name := file_name_stem + “.exe” and
forget about it.

Yes, you can forget it now. But later, if you like, you use the typechecker
to find the places
where you need to make minor changes. Of course, we could probably come up
with a fancy tool
to do this automatically. But then we have to learn such a tool to use it.
How many tools like this
should or can we actually learn?

A few days ago, I wrote some ATS code to generate PHP code. First, I have

abstype tmpfile

After my code is functioning, I changed the declaration into

absvtype tmpfile

In this way, I made sure that the PHP code would properly delete all the
tmp files generated in the middle.
Trust me, this is very simple and very effective.On Wed, Oct 1, 2014 at 6:41 PM, H Zhang zht...@gmail.com wrote:

The problem with letting it dangle now and fix it later that is: 1) I have
to remember doing that and also pick up what I was doing before and 2)
assuming the tools give meaningful warnings so I can go right to where the
issue is the “fix” would still pollute the code and make it harder to read.
Really I should be able to say exe_name := file_name_stem + “.exe” and
forget about it. I don’t care about the performance here nor memory usage.
Just needs it to be safe. But it is a heavy price to pay if I have to use
Python to get little niceties like this. If 90% of the cases can be handled
automatically I don’t mind handling the cases that can’t be resolved. Then
I can reserve the mental energy to use linear types on things that really
matter to me performance wise (time and space).

On Wednesday, October 1, 2014 2:45:06 PM UTC-7, gmhwxi wrote:

It is the mental distraction that is annoying.

I once tried to juggle 3 oranges (or apples) in front of the students
taking my class
so as to show them how difficult it is. When programming, people tend to
juggle many
concepts mentally, complicating programming unnecessarily.

In ATS, you can always use a non-linear type first and then change it to
a linear one
later. This allows you to focus on what you are doing.

On Wed, Oct 1, 2014 at 4:40 PM, H Zhang zht...@gmail.com wrote:

It is the mental distraction that is annoying. E.g. in C for something
trivial like changing the extension of a filename one needs to allocate a
string, pass it on and later remember to free it. That is just very
distracting from the logical flow. Not only that, it is very annoying to
read codes that are littered with things like that as it interferes with
following the programmer’s true intention.

On Wednesday, October 1, 2014 12:48:40 PM UTC-7, gmhwxi wrote:

without having to manually manage all the life cycles

Your assumption is that this must be very burdensome. But really? One
needs to actually
do it in order to get a real sense of it.

Think about a system that you want to implement. If there is something
that prevents you from
implementing the system, I bet it is unlikely due to the need to
manually manage something; it
usually happens at a much earlier stage.

On Wednesday, October 1, 2014 3:01:43 PM UTC-4, H Zhang wrote:

Rust is Apache/MIT licensed so that whatever they do should be okay to
borrow in ATS as well?

The way I think about the language mismatch problem, if we take data
structures as the central of focus of programming, is that managed
languages don’t let you control every detail of the data structure that is
most important to you, while c/c++ forces you to manage every little detail
that is unimportant to you. For the data structure that carries the whole
program state I want to be very careful about everything, but in any given
function I am only working on a small part of it I want to be able to use
abstract (not just primitive) temporary or not so temporary smallish
structures without having to manually manage all the life cycles. I don’t
know if Rust is It but I do think it is an important gap to address.

On Wednesday, October 1, 2014 10:35:18 AM UTC-7, gmhwxi wrote:

Interesting.

My guess is that some kind of (sophisticated) flow analysis is
involved.

Is everything on stack?

Putting everything on stack would make it so difficult to do
general-purpose programming
even if it is still possible.

Why can’t ATS do something similar?

You mean to rely on flow analysis (instead of linear types) for
memory management?

Well, this has to do with my training. The lessons I learned from
automated theorem-proving
made me constantly try to avert complex algorithms of heavy heuristic
nature.

On Wednesday, October 1, 2014 12:20:34 PM UTC-4, H Zhang wrote:

Rust is able to do support ADT and pattern matching without
requiring the use of GC. Does anyone know how that is achieved? Is
everything on stack? Why can’t ATS do something similar?

Haitao


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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit https://groups.google.com/d/
msgid/ats-lang-users/feaf3c7e-cc59-4eb8-9df7-de315635e3fe%
40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/feaf3c7e-cc59-4eb8-9df7-de315635e3fe%40googlegroups.com?utm_medium=email&utm_source=footer
.


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 http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/12e14207-ecb7-468b-8f90-5240cae352d6%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/12e14207-ecb7-468b-8f90-5240cae352d6%40googlegroups.com?utm_medium=email&utm_source=footer
.

True. Pattern-matching per se has nothing to do with GC.

However, the values to be matched against are usually compound values
that need to be created at run-time. I guess Haitao’s question is about
where
such compound values are stored and how they are freed.On Wednesday, October 1, 2014 1:45:32 PM UTC-4, Raoul Duke wrote:

Rust is able to do support ADT and pattern matching without requiring
the
use of GC.

My guess is that some kind of (sophisticated) flow analysis is involved.

i guess i’m just really ignorant, because i don’t understand why ADTs
or pattern matching require a GC.

e.g. pattern matches can oft be compiled down to switch statements, no?

Rust is able to do support ADT and pattern matching without requiring the
use of GC.

My guess is that some kind of (sophisticated) flow analysis is involved.

i guess i’m just really ignorant, because i don’t understand why ADTs
or pattern matching require a GC.

e.g. pattern matches can oft be compiled down to switch statements, no?

yes, i’m excited about all those! and we got to see some when Will did
the tutorial for us. (Will, any chance your notes & examples from that
can be posted to the list?) great stuff.

(although i am still 101% convinced that the way “!” us used is the
opposite of what it should be. we even ran into that uxability problem
while Will was doing his tutorial :-})

Are “linear datatypes” dataviewtypes?

~SheaOn Wed, Oct 01, 2014 at 02:10:09PM -0400, Hongwei Xi wrote:

I assume that ADT means algebraic datatype in the given context.

Yes, you can have ADTs in pretty much any programming languages.
But the languages you mentioned above do not have a type system to
help the programmer use ADTs safely.

Is there a way to implement ADTs without relying on GC? Of course, such
a implementation should not leak memory. In ATS, you can use linear
datatypes
without GC and without fear of memory leaks.

On Wed, Oct 1, 2014 at 1:54 PM, Raoul Duke rao...@gmail.com wrote:

However, the values to be matched against are usually compound values
that need to be created at run-time. I guess Haitao’s question is about
where
such compound values are stored and how they are freed.

i still don’t get it. i can have (things approximating at least) ADTs
in C/++/Obj-C, can i not?

(note: i’m not arguing for non-gc, i just do not yet understand the
issue here, it all seems confused and conflated and confabulated to
me.)


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 http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/CAJ7XQb5D5vWWW8a7zjB-F5%2Bw2rjkucwtWujcHPxHYMQWqtjFpg%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-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLqZK_QEp6Y25eGzQ9AvPwbmQMTkoJFbaTXvCO1qs86OaA%40mail.gmail.com.

I would like to write library/extensions that do not require GC. However I
also want to be able to use functional programming techniques for most of
the boiler-plates and only manage the performance-critical part of data by
hand.On Wed, Oct 1, 2014 at 7:11 PM, gmhwxi gmh...@gmail.com wrote:

There is no default malloc/free pair. It has to be specified
by the programmer.

-DATS_MEMALLOC_LIBC: using libc malloc/free
-DATS_MEMALLOC_GCBDW: using Boehm GC

Here is an example showing how to supply a malloc/free pair of your own

https://github.com/githwxi/ATS-Postiats-contrib/tree/master/document/EXAMPLE/CA-HSR2/program-1-2

I am not actually very clear about what you are trying to do. I had the
impression that you wanted to have
two GCs: one in ATS and one in Prolog(?).

On Wednesday, October 1, 2014 9:55:45 PM UTC-4, H Zhang wrote:

That is good to know. Last time we talked (a few months back) I got a
different impression. So this means I can specify what malloc/free ATS uses
to compile ADT and closures? Or do I let them have the default and I can
specify a different set for the manually managed code? Last time I looked
at the instruction set macros of ATS I didn’t think that was possible.

On Wed, Oct 1, 2014 at 6:18 PM, gmhwxi gmh...@gmail.com wrote:

Yes, you can have different sets of malloc/free pairs as long as you
don’t use GC.
If you use GC, then you probably do not want to have different sets of
malloc/free pairs.

On Wednesday, October 1, 2014 7:27:41 PM UTC-4, H Zhang wrote:

Yes that is what regions analysis does. That is a good “poor man”'s
substitute for regions analysis but I think in ATS you can’t really specify
multiple mallocs (?). You would have to drop back to C to do that.

On Wed, Oct 1, 2014 at 4:17 PM, Barry Schwartz < chem...@chemoelectric.org> wrote:

H Zhang zht...@gmail.com skribis:

The problem with letting it dangle now and fix it later that is: 1)
I have
to remember doing that and also pick up what I was doing before and

assuming the tools give meaningful warnings so I can go right to
where the
issue is the “fix” would still pollute the code and make it harder
to read.
Really I should be able to say exe_name := file_name_stem + “.exe”
and
forget about it. I don’t care about the performance here nor memory
usage.
Just needs it to be safe. But it is a heavy price to pay if I have
to use
Python to get little niceties like this. If 90% of the cases can be
handled
automatically I don’t mind handling the cases that can’t be
resolved. Then
I can reserve the mental energy to use linear types on things that
really
matter to me performance wise (time and space).

In my working days as a C programmer of slow programs that could eat
up memory freely, I used to use a little ‘reaping allocator’ I
wrote. Not at all complicated. Call it instead of malloc directly, and
use it just like malloc, but the allocated pieces had a link field in
them so you could free them all at once. So I’d start up the allocator
at the beginning of routine and put a ‘reap’ at the end. In between, I
could act somewhat as if I had a garbage collector.

Simple solutions often work fine.

(Python OTOH makes things so complicated that I wouldn’t trust a proof
of correctness of some Python code if it existed, and don’t trust
tests.)


You received this message because you are subscribed to a topic in the
Google Groups “ats-lang-users” group.
To unsubscribe from this topic, visit https://groups.google.com/d/to
pic/ats-lang-users/a17ftxArgIw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
ats-lang...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit https://groups.google.com/d/
msgid/ats-lang-users/20141001231739.GA16565%40crud.


You received this message because you are subscribed to a topic in the
Google Groups “ats-lang-users” group.
To unsubscribe from this topic, visit https://groups.google.com/d/
topic/ats-lang-users/a17ftxArgIw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
ats-lang...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit https://groups.google.com/d/
msgid/ats-lang-users/d5a77967-bb91-4bca-aaa9-d6f65c25e36f%
40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/d5a77967-bb91-4bca-aaa9-d6f65c25e36f%40googlegroups.com?utm_medium=email&utm_source=footer
.


You received this message because you are subscribed to a topic in the
Google Groups “ats-lang-users” group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/ats-lang-users/a17ftxArgIw/unsubscribe.
To unsubscribe from this group and all its topics, 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 http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/660ac218-ae08-4aaf-ae04-105ad2753e73%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/660ac218-ae08-4aaf-ae04-105ad2753e73%40googlegroups.com?utm_medium=email&utm_source=footer
.

There is no default malloc/free pair. It has to be specified
by the programmer.

-DATS_MEMALLOC_LIBC: using libc malloc/free
-DATS_MEMALLOC_GCBDW: using Boehm GC

Here is an example showing how to supply a malloc/free pair of your own

I am not actually very clear about what you are trying to do. I had the
impression that you wanted to have
two GCs: one in ATS and one in Prolog(?).On Wednesday, October 1, 2014 9:55:45 PM UTC-4, H Zhang wrote:

That is good to know. Last time we talked (a few months back) I got a
different impression. So this means I can specify what malloc/free ATS uses
to compile ADT and closures? Or do I let them have the default and I can
specify a different set for the manually managed code? Last time I looked
at the instruction set macros of ATS I didn’t think that was possible.

On Wed, Oct 1, 2014 at 6:18 PM, gmhwxi <gmh...@gmail.com <javascript:>> wrote:

Yes, you can have different sets of malloc/free pairs as long as you
don’t use GC.
If you use GC, then you probably do not want to have different sets of
malloc/free pairs.

On Wednesday, October 1, 2014 7:27:41 PM UTC-4, H Zhang wrote:

Yes that is what regions analysis does. That is a good “poor man”'s
substitute for regions analysis but I think in ATS you can’t really specify
multiple mallocs (?). You would have to drop back to C to do that.

On Wed, Oct 1, 2014 at 4:17 PM, Barry Schwartz <chemoe…@chemoelectric. org> wrote:

H Zhang zht...@gmail.com skribis:

The problem with letting it dangle now and fix it later that is: 1) I
have
to remember doing that and also pick up what I was doing before and 2)
assuming the tools give meaningful warnings so I can go right to
where the
issue is the “fix” would still pollute the code and make it harder to
read.
Really I should be able to say exe_name := file_name_stem + “.exe” and
forget about it. I don’t care about the performance here nor memory
usage.
Just needs it to be safe. But it is a heavy price to pay if I have to
use
Python to get little niceties like this. If 90% of the cases can be
handled
automatically I don’t mind handling the cases that can’t be resolved.
Then
I can reserve the mental energy to use linear types on things that
really
matter to me performance wise (time and space).

In my working days as a C programmer of slow programs that could eat
up memory freely, I used to use a little ‘reaping allocator’ I
wrote. Not at all complicated. Call it instead of malloc directly, and
use it just like malloc, but the allocated pieces had a link field in
them so you could free them all at once. So I’d start up the allocator
at the beginning of routine and put a ‘reap’ at the end. In between, I
could act somewhat as if I had a garbage collector.

Simple solutions often work fine.

(Python OTOH makes things so complicated that I wouldn’t trust a proof
of correctness of some Python code if it existed, and don’t trust
tests.)


You received this message because you are subscribed to a topic in the
Google Groups “ats-lang-users” group.
To unsubscribe from this topic, visit https://groups.google.com/d/
topic/ats-lang-users/a17ftxArgIw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
ats-lang...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit https://groups.google.com/d/
msgid/ats-lang-users/20141001231739.GA16565%40crud.


You received this message because you are subscribed to a topic in the
Google Groups “ats-lang-users” group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/ats-lang-users/a17ftxArgIw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
ats-lang...@googlegroups.com <javascript:>.
To post to this group, send email to ats-l...@googlegroups.com
<javascript:>.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/d5a77967-bb91-4bca-aaa9-d6f65c25e36f%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/d5a77967-bb91-4bca-aaa9-d6f65c25e36f%40googlegroups.com?utm_medium=email&utm_source=footer
.

Yes that is what regions analysis does. That is a good “poor man”'s
substitute for regions analysis but I think in ATS you can’t really specify
multiple mallocs (?). You would have to drop back to C to do that.On Wed, Oct 1, 2014 at 4:17 PM, Barry Schwartz < chemoe...@chemoelectric.org> wrote:

H Zhang zht...@gmail.com skribis:

The problem with letting it dangle now and fix it later that is: 1) I
have
to remember doing that and also pick up what I was doing before and 2)
assuming the tools give meaningful warnings so I can go right to where
the
issue is the “fix” would still pollute the code and make it harder to
read.
Really I should be able to say exe_name := file_name_stem + “.exe” and
forget about it. I don’t care about the performance here nor memory
usage.
Just needs it to be safe. But it is a heavy price to pay if I have to use
Python to get little niceties like this. If 90% of the cases can be
handled
automatically I don’t mind handling the cases that can’t be resolved.
Then
I can reserve the mental energy to use linear types on things that really
matter to me performance wise (time and space).

In my working days as a C programmer of slow programs that could eat
up memory freely, I used to use a little ‘reaping allocator’ I
wrote. Not at all complicated. Call it instead of malloc directly, and
use it just like malloc, but the allocated pieces had a link field in
them so you could free them all at once. So I’d start up the allocator
at the beginning of routine and put a ‘reap’ at the end. In between, I
could act somewhat as if I had a garbage collector.

Simple solutions often work fine.

(Python OTOH makes things so complicated that I wouldn’t trust a proof
of correctness of some Python code if it existed, and don’t trust
tests.)


You received this message because you are subscribed to a topic in the
Google Groups “ats-lang-users” group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/ats-lang-users/a17ftxArgIw/unsubscribe.
To unsubscribe from this group and all its topics, 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 http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/20141001231739.GA16565%40crud
.

That is good to know. Last time we talked (a few months back) I got a
different impression. So this means I can specify what malloc/free ATS uses
to compile ADT and closures? Or do I let them have the default and I can
specify a different set for the manually managed code? Last time I looked
at the instruction set macros of ATS I didn’t think that was possible.On Wed, Oct 1, 2014 at 6:18 PM, gmhwxi gmh...@gmail.com wrote:

Yes, you can have different sets of malloc/free pairs as long as you don’t
use GC.
If you use GC, then you probably do not want to have different sets of
malloc/free pairs.

On Wednesday, October 1, 2014 7:27:41 PM UTC-4, H Zhang wrote:

Yes that is what regions analysis does. That is a good “poor man”'s
substitute for regions analysis but I think in ATS you can’t really specify
multiple mallocs (?). You would have to drop back to C to do that.

On Wed, Oct 1, 2014 at 4:17 PM, Barry Schwartz <chemoe…@chemoelectric. org> wrote:

H Zhang zht...@gmail.com skribis:

The problem with letting it dangle now and fix it later that is: 1) I
have
to remember doing that and also pick up what I was doing before and 2)
assuming the tools give meaningful warnings so I can go right to where
the
issue is the “fix” would still pollute the code and make it harder to
read.
Really I should be able to say exe_name := file_name_stem + “.exe” and
forget about it. I don’t care about the performance here nor memory
usage.
Just needs it to be safe. But it is a heavy price to pay if I have to
use
Python to get little niceties like this. If 90% of the cases can be
handled
automatically I don’t mind handling the cases that can’t be resolved.
Then
I can reserve the mental energy to use linear types on things that
really
matter to me performance wise (time and space).

In my working days as a C programmer of slow programs that could eat
up memory freely, I used to use a little ‘reaping allocator’ I
wrote. Not at all complicated. Call it instead of malloc directly, and
use it just like malloc, but the allocated pieces had a link field in
them so you could free them all at once. So I’d start up the allocator
at the beginning of routine and put a ‘reap’ at the end. In between, I
could act somewhat as if I had a garbage collector.

Simple solutions often work fine.

(Python OTOH makes things so complicated that I wouldn’t trust a proof
of correctness of some Python code if it existed, and don’t trust
tests.)


You received this message because you are subscribed to a topic in the
Google Groups “ats-lang-users” group.
To unsubscribe from this topic, visit https://groups.google.com/d/
topic/ats-lang-users/a17ftxArgIw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
ats-lang...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit https://groups.google.com/d/
msgid/ats-lang-users/20141001231739.GA16565%40crud.


You received this message because you are subscribed to a topic in the
Google Groups “ats-lang-users” group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/ats-lang-users/a17ftxArgIw/unsubscribe.
To unsubscribe from this group and all its topics, 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 http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/d5a77967-bb91-4bca-aaa9-d6f65c25e36f%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/d5a77967-bb91-4bca-aaa9-d6f65c25e36f%40googlegroups.com?utm_medium=email&utm_source=footer
.

After reading more on this it seems Rust hasn’t really solved the problem
after all. What they call ADT is actually just an Enum type that does not
allow recursive definition without explicit indirection. A list or tree
defined through their Enum type would be very different from what you have
in ML. For example I don’t think two lists defined this way can share their
tails. I have not found any example of how this can be used non-trivially.On Wed, Oct 1, 2014 at 9:20 AM, H Zhang zht...@gmail.com wrote:

Rust is able to do support ADT and pattern matching without requiring the
use of GC. Does anyone know how that is achieved? Is everything on stack?
Why can’t ATS do something similar?

Haitao


You received this message because you are subscribed to a topic in the
Google Groups “ats-lang-users” group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/ats-lang-users/a17ftxArgIw/unsubscribe.
To unsubscribe from this group and all its topics, 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 http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/10a07a6e-fb96-4883-aff5-04ee70e2fbbe%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/10a07a6e-fb96-4883-aff5-04ee70e2fbbe%40googlegroups.com?utm_medium=email&utm_source=footer
.

Moving ahead one step, it would then be nice to distinguish linear and
non-linear allocations so we can have two heaps, one for the linear
structures and one for the nonlinear ones. Before type erasure ATS has
information on what allocations are linear, correct? Is there also a way to
guarantee that linear structures don’t contain pointers to the nonlinear
heap? This way we can also use linear types to return structures without
copying and/or store side effects, safer than using only CFFI? Not sure how
useful or feasible this is.

Linear values are often not freed; instead, they turn into non-linear
value

I think my answer was to the second part of your question (quoted above).
You cannot
have one heap for linear values and another one for non-linear values
because linear values
can be turned into non-linear ones.

Now I think I understand what you want to do. You can just write your own
heap allocator
(as was suggested in your first paragraph).On Wednesday, October 1, 2014 10:14:27 PM UTC-4, H Zhang wrote:

Ah this is the thread (itself a continuation of a previous thread :slight_smile:
Redirecting to Google Groups

And your answer was that: “Linear values are often not freed; instead,
they turn into non-linear values”

So it seems the answer to my question would still be that it is still not
easy to use ADTs and closures.

On Wed, Oct 1, 2014 at 6:55 PM, Haitao Zhang <zht...@gmail.com <javascript:>> wrote:

That is good to know. Last time we talked (a few months back) I got a
different impression. So this means I can specify what malloc/free ATS uses
to compile ADT and closures? Or do I let them have the default and I can
specify a different set for the manually managed code? Last time I looked
at the instruction set macros of ATS I didn’t think that was possible.

On Wed, Oct 1, 2014 at 6:18 PM, gmhwxi <gmh...@gmail.com <javascript:>> wrote:

Yes, you can have different sets of malloc/free pairs as long as you
don’t use GC.
If you use GC, then you probably do not want to have different sets of
malloc/free pairs.

On Wednesday, October 1, 2014 7:27:41 PM UTC-4, H Zhang wrote:

Yes that is what regions analysis does. That is a good “poor man”'s
substitute for regions analysis but I think in ATS you can’t really specify
multiple mallocs (?). You would have to drop back to C to do that.

On Wed, Oct 1, 2014 at 4:17 PM, Barry Schwartz < chem...@chemoelectric.org> wrote:

H Zhang zht...@gmail.com skribis:

The problem with letting it dangle now and fix it later that is: 1)
I have
to remember doing that and also pick up what I was doing before and

assuming the tools give meaningful warnings so I can go right to
where the
issue is the “fix” would still pollute the code and make it harder
to read.
Really I should be able to say exe_name := file_name_stem + “.exe”
and
forget about it. I don’t care about the performance here nor memory
usage.
Just needs it to be safe. But it is a heavy price to pay if I have
to use
Python to get little niceties like this. If 90% of the cases can be
handled
automatically I don’t mind handling the cases that can’t be
resolved. Then
I can reserve the mental energy to use linear types on things that
really
matter to me performance wise (time and space).

In my working days as a C programmer of slow programs that could eat
up memory freely, I used to use a little ‘reaping allocator’ I
wrote. Not at all complicated. Call it instead of malloc directly, and
use it just like malloc, but the allocated pieces had a link field in
them so you could free them all at once. So I’d start up the allocator
at the beginning of routine and put a ‘reap’ at the end. In between, I
could act somewhat as if I had a garbage collector.

Simple solutions often work fine.

(Python OTOH makes things so complicated that I wouldn’t trust a proof
of correctness of some Python code if it existed, and don’t trust
tests.)


You received this message because you are subscribed to a topic in the
Google Groups “ats-lang-users” group.
To unsubscribe from this topic, visit https://groups.google.com/d/
topic/ats-lang-users/a17ftxArgIw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
ats-lang...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit https://groups.google.com/d/
msgid/ats-lang-users/20141001231739.GA16565%40crud.


You received this message because you are subscribed to a topic in the
Google Groups “ats-lang-users” group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/ats-lang-users/a17ftxArgIw/unsubscribe
.
To unsubscribe from this group and all its topics, send an email to
ats-lang...@googlegroups.com <javascript:>.
To post to this group, send email to ats-l...@googlegroups.com
<javascript:>.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/d5a77967-bb91-4bca-aaa9-d6f65c25e36f%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/d5a77967-bb91-4bca-aaa9-d6f65c25e36f%40googlegroups.com?utm_medium=email&utm_source=footer
.

I assume that ADT means algebraic datatype in the given context.

ah, yup, so many things come down to confusion over definitions and
semantics. i was assuming “abstract” not “algebraic” d’oh. i should
know better since i’ve seen this distinction/confusion elsewhere
before (at least i’m not alone).

(there are things about Algebraics that can be done in crappy
languages: a modern C compiler will tell you if your switch statement
is not exhaustive in case’s, etc.)

The problem with letting it dangle now and fix it later that is: 1) I have
to remember doing that and also pick up what I was doing before and 2)
assuming the tools give meaningful warnings so I can go right to where the
issue is the “fix” would still pollute the code and make it harder to read.
Really I should be able to say exe_name := file_name_stem + “.exe” and
forget about it. I don’t care about the performance here nor memory usage.
Just needs it to be safe. But it is a heavy price to pay if I have to use
Python to get little niceties like this. If 90% of the cases can be handled
automatically I don’t mind handling the cases that can’t be resolved. Then
I can reserve the mental energy to use linear types on things that really
matter to me performance wise (time and space).On Wednesday, October 1, 2014 2:45:06 PM UTC-7, gmhwxi wrote:

It is the mental distraction that is annoying.

I once tried to juggle 3 oranges (or apples) in front of the students
taking my class
so as to show them how difficult it is. When programming, people tend to
juggle many
concepts mentally, complicating programming unnecessarily.

In ATS, you can always use a non-linear type first and then change it to a
linear one
later. This allows you to focus on what you are doing.

On Wed, Oct 1, 2014 at 4:40 PM, H Zhang <zht...@gmail.com <javascript:>> wrote:

It is the mental distraction that is annoying. E.g. in C for something
trivial like changing the extension of a filename one needs to allocate a
string, pass it on and later remember to free it. That is just very
distracting from the logical flow. Not only that, it is very annoying to
read codes that are littered with things like that as it interferes with
following the programmer’s true intention.

On Wednesday, October 1, 2014 12:48:40 PM UTC-7, gmhwxi wrote:

without having to manually manage all the life cycles

Your assumption is that this must be very burdensome. But really? One
needs to actually
do it in order to get a real sense of it.

Think about a system that you want to implement. If there is something
that prevents you from
implementing the system, I bet it is unlikely due to the need to
manually manage something; it
usually happens at a much earlier stage.

On Wednesday, October 1, 2014 3:01:43 PM UTC-4, H Zhang wrote:

Rust is Apache/MIT licensed so that whatever they do should be okay to
borrow in ATS as well?

The way I think about the language mismatch problem, if we take data
structures as the central of focus of programming, is that managed
languages don’t let you control every detail of the data structure that is
most important to you, while c/c++ forces you to manage every little detail
that is unimportant to you. For the data structure that carries the whole
program state I want to be very careful about everything, but in any given
function I am only working on a small part of it I want to be able to use
abstract (not just primitive) temporary or not so temporary smallish
structures without having to manually manage all the life cycles. I don’t
know if Rust is It but I do think it is an important gap to address.

On Wednesday, October 1, 2014 10:35:18 AM UTC-7, gmhwxi wrote:

Interesting.

My guess is that some kind of (sophisticated) flow analysis is
involved.

Is everything on stack?

Putting everything on stack would make it so difficult to do
general-purpose programming
even if it is still possible.

Why can’t ATS do something similar?

You mean to rely on flow analysis (instead of linear types) for memory
management?

Well, this has to do with my training. The lessons I learned from
automated theorem-proving
made me constantly try to avert complex algorithms of heavy heuristic
nature.

On Wednesday, October 1, 2014 12:20:34 PM UTC-4, H Zhang wrote:

Rust is able to do support ADT and pattern matching without requiring
the use of GC. Does anyone know how that is achieved? Is everything on
stack? Why can’t ATS do something similar?

Haitao


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...@googlegroups.com <javascript:>.
To post to this group, send email to ats-l...@googlegroups.com
<javascript:>.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/feaf3c7e-cc59-4eb8-9df7-de315635e3fe%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/feaf3c7e-cc59-4eb8-9df7-de315635e3fe%40googlegroups.com?utm_medium=email&utm_source=footer
.

I am not against GC but the problem is that there is no generic performant
GC. To have a really good one you need a large eco-system (JVM or CLR). You
also have to commit to one GC – so it is hard to link against libraries if
they don’t all use the same GC. Without language support you end up with
conservative GC like Boehm that has to do all kind of crazy things to
figure out your intentions.

The annoyance I am referring to don’t really require a true GC to address,
but like Hongwei said it probably requires some heuristics on the
compiler’s part. ML Kit tried but regions management didn’t work 100%. I am
still trying to figure out how Rust is doing it.On Wednesday, October 1, 2014 1:45:35 PM UTC-7, Raoul Duke wrote:

On Wed, Oct 1, 2014 at 1:40 PM, H Zhang <zht...@gmail.com <javascript:>> wrote:

It is the mental distraction that is annoying. E.g. in C for something
trivial like changing the extension of a filename one needs to allocate
a
string, pass it on and later remember to free it. That is just very
distracting from the logical flow. Not only that, it is very annoying to
read codes that are littered with things like that as it interferes with
following the programmer’s true intention.

if you could snap your fingers and magically make something that
works, what do you think it would look like.

e.g. even with GC one still has to have something like IDisposeable.
personally i day-dream of a hybrid RC+GC that would be the best of all
possible worlds. there’s quite a bit of interesting research on that,
but nothing productized enough for e.g. me to easily use it for making
video games across platforms. like, i guess i’d want something that
matches Boehm API since it seems like a lot of projects know about
that at least, but does a better job than Boehm. (not that i
personally have metrics on Boehm, i’m just going based on what some
people i think i trust have said about it. :slight_smile:

Thanks for the clarification. I will give this approach some more thoughts
then. Since linear values can turn into non-linear values, the non-linear
allocator possibly needs to free the memory allocated by the linear
allocator, right? But the non-linear allocator would not know what are
pointers in the part of heap it manages, nor would it know if it is safe to
free what they point to?On Wed, Oct 1, 2014 at 7:33 PM, gmhwxi gmh...@gmail.com wrote:

Moving ahead one step, it would then be nice to distinguish linear and

non-linear allocations so we can have two heaps, one for the linear
structures and one for the nonlinear ones. Before type erasure ATS has
information on what allocations are linear, correct? Is there also a way to
guarantee that linear structures don’t contain pointers to the nonlinear
heap? This way we can also use linear types to return structures without
copying and/or store side effects, safer than using only CFFI? Not sure how
useful or feasible this is.

Linear values are often not freed; instead, they turn into non-linear
value

I think my answer was to the second part of your question (quoted above).
You cannot
have one heap for linear values and another one for non-linear values
because linear values
can be turned into non-linear ones.

Now I think I understand what you want to do. You can just write your own
heap allocator
(as was suggested in your first paragraph).

On Wednesday, October 1, 2014 10:14:27 PM UTC-4, H Zhang wrote:

Ah this is the thread (itself a continuation of a previous thread :slight_smile:
Redirecting to Google Groups
users/heap/ats-lang-users/jtg3f_P-xx0/ihW05rcULccJ

And your answer was that: “Linear values are often not freed; instead,
they turn into non-linear values”

So it seems the answer to my question would still be that it is still not
easy to use ADTs and closures.

On Wed, Oct 1, 2014 at 6:55 PM, Haitao Zhang zht...@gmail.com wrote:

That is good to know. Last time we talked (a few months back) I got a
different impression. So this means I can specify what malloc/free ATS uses
to compile ADT and closures? Or do I let them have the default and I can
specify a different set for the manually managed code? Last time I looked
at the instruction set macros of ATS I didn’t think that was possible.

On Wed, Oct 1, 2014 at 6:18 PM, gmhwxi gmh...@gmail.com wrote:

Yes, you can have different sets of malloc/free pairs as long as you
don’t use GC.
If you use GC, then you probably do not want to have different sets of
malloc/free pairs.

On Wednesday, October 1, 2014 7:27:41 PM UTC-4, H Zhang wrote:

Yes that is what regions analysis does. That is a good “poor man”'s
substitute for regions analysis but I think in ATS you can’t really specify
multiple mallocs (?). You would have to drop back to C to do that.

On Wed, Oct 1, 2014 at 4:17 PM, Barry Schwartz < chem...@chemoelectric.org> wrote:

H Zhang zht...@gmail.com skribis:

The problem with letting it dangle now and fix it later that is: 1)
I have
to remember doing that and also pick up what I was doing before and

assuming the tools give meaningful warnings so I can go right to
where the
issue is the “fix” would still pollute the code and make it harder
to read.
Really I should be able to say exe_name := file_name_stem + “.exe”
and
forget about it. I don’t care about the performance here nor memory
usage.
Just needs it to be safe. But it is a heavy price to pay if I have
to use
Python to get little niceties like this. If 90% of the cases can be
handled
automatically I don’t mind handling the cases that can’t be
resolved. Then
I can reserve the mental energy to use linear types on things that
really
matter to me performance wise (time and space).

In my working days as a C programmer of slow programs that could eat
up memory freely, I used to use a little ‘reaping allocator’ I
wrote. Not at all complicated. Call it instead of malloc directly, and
use it just like malloc, but the allocated pieces had a link field in
them so you could free them all at once. So I’d start up the allocator
at the beginning of routine and put a ‘reap’ at the end. In between, I
could act somewhat as if I had a garbage collector.

Simple solutions often work fine.

(Python OTOH makes things so complicated that I wouldn’t trust a proof
of correctness of some Python code if it existed, and don’t trust
tests.)


You received this message because you are subscribed to a topic in
the Google Groups “ats-lang-users” group.
To unsubscribe from this topic, visit https://groups.google.com/d/to
pic/ats-lang-users/a17ftxArgIw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
ats-lang...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit https://groups.google.com/d/
msgid/ats-lang-users/20141001231739.GA16565%40crud.


You received this message because you are subscribed to a topic in the
Google Groups “ats-lang-users” group.
To unsubscribe from this topic, visit https://groups.google.com/d/
topic/ats-lang-users/a17ftxArgIw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
ats-lang...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit https://groups.google.com/d/
msgid/ats-lang-users/d5a77967-bb91-4bca-aaa9-d6f65c25e36f%
40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/d5a77967-bb91-4bca-aaa9-d6f65c25e36f%40googlegroups.com?utm_medium=email&utm_source=footer
.


You received this message because you are subscribed to a topic in the
Google Groups “ats-lang-users” group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/ats-lang-users/a17ftxArgIw/unsubscribe.
To unsubscribe from this group and all its topics, 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 http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/f00755c4-793f-45ef-87a6-dd82e8664a51%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/f00755c4-793f-45ef-87a6-dd82e8664a51%40googlegroups.com?utm_medium=email&utm_source=footer
.

It is the mental distraction that is annoying. E.g. in C for something
trivial like changing the extension of a filename one needs to allocate a
string, pass it on and later remember to free it. That is just very
distracting from the logical flow. Not only that, it is very annoying to
read codes that are littered with things like that as it interferes with
following the programmer’s true intention.On Wednesday, October 1, 2014 12:48:40 PM UTC-7, gmhwxi wrote:

without having to manually manage all the life cycles

Your assumption is that this must be very burdensome. But really? One
needs to actually
do it in order to get a real sense of it.

Think about a system that you want to implement. If there is something
that prevents you from
implementing the system, I bet it is unlikely due to the need to manually
manage something; it
usually happens at a much earlier stage.

On Wednesday, October 1, 2014 3:01:43 PM UTC-4, H Zhang wrote:

Rust is Apache/MIT licensed so that whatever they do should be okay to
borrow in ATS as well?

The way I think about the language mismatch problem, if we take data
structures as the central of focus of programming, is that managed
languages don’t let you control every detail of the data structure that is
most important to you, while c/c++ forces you to manage every little detail
that is unimportant to you. For the data structure that carries the whole
program state I want to be very careful about everything, but in any given
function I am only working on a small part of it I want to be able to use
abstract (not just primitive) temporary or not so temporary smallish
structures without having to manually manage all the life cycles. I don’t
know if Rust is It but I do think it is an important gap to address.

On Wednesday, October 1, 2014 10:35:18 AM UTC-7, gmhwxi wrote:

Interesting.

My guess is that some kind of (sophisticated) flow analysis is involved.

Is everything on stack?

Putting everything on stack would make it so difficult to do
general-purpose programming
even if it is still possible.

Why can’t ATS do something similar?

You mean to rely on flow analysis (instead of linear types) for memory
management?

Well, this has to do with my training. The lessons I learned from
automated theorem-proving
made me constantly try to avert complex algorithms of heavy heuristic
nature.

On Wednesday, October 1, 2014 12:20:34 PM UTC-4, H Zhang wrote:

Rust is able to do support ADT and pattern matching without requiring
the use of GC. Does anyone know how that is achieved? Is everything on
stack? Why can’t ATS do something similar?

Haitao