Rust lang memory management

334 views
Skip to first unread message

H Zhang

unread,
Oct 1, 2014, 12:20:34 PM10/1/14
to ats-lan...@googlegroups.com
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

gmhwxi

unread,
Oct 1, 2014, 1:35:18 PM10/1/14
to ats-lan...@googlegroups.com
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.

Raoul Duke

unread,
Oct 1, 2014, 1:45:32 PM10/1/14
to ats-lang-users
>> 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?

gmhwxi

unread,
Oct 1, 2014, 1:50:20 PM10/1/14
to ats-lan...@googlegroups.com
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.

Raoul Duke

unread,
Oct 1, 2014, 1:55:14 PM10/1/14
to ats-lang-users
> 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.)

Hongwei Xi

unread,
Oct 1, 2014, 2:10:09 PM10/1/14
to ats-lan...@googlegroups.com
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.




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

Raoul Duke

unread,
Oct 1, 2014, 2:16:56 PM10/1/14
to ats-lang-users
> 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 *ass*uming "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.)

H Zhang

unread,
Oct 1, 2014, 2:25:47 PM10/1/14
to ats-lan...@googlegroups.com

Yes. Sorry for not spelling it out to be clear. In the context of ATS I thought that would have been the assumption.

H Zhang

unread,
Oct 1, 2014, 3:01:43 PM10/1/14
to ats-lan...@googlegroups.com

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.

Shea Levy

unread,
Oct 1, 2014, 3:05:05 PM10/1/14
to ats-lan...@googlegroups.com
Are "linear datatypes" dataviewtypes?

~Shea
> To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLqZK_QEp6Y25eGzQ9AvPwbmQMTkoJFbaTXvCO1qs86OaA%40mail.gmail.com.

Hongwei Xi

unread,
Oct 1, 2014, 3:11:51 PM10/1/14
to ats-lan...@googlegroups.com
Yes. You can also use the shorter keyword 'datavtype' for declaring a linear datatype.


gmhwxi

unread,
Oct 1, 2014, 3:48:40 PM10/1/14
to ats-lan...@googlegroups.com

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

Raoul Duke

unread,
Oct 1, 2014, 4:00:57 PM10/1/14
to ats-lang-users
it isn't the burden of finger typing on keyboards.

it is the burden of stupid bugs crashes etc. later.

gmhwxi

unread,
Oct 1, 2014, 4:05:52 PM10/1/14
to ats-lan...@googlegroups.com
The typechecker of ATS will enforce type-correctness,
which will get rid of a lot of stupid bugs.

Raoul Duke

unread,
Oct 1, 2014, 4:13:14 PM10/1/14
to ats-lang-users
> The typechecker of ATS will enforce type-correctness,
> which will get rid of a lot of stupid bugs.

sure, agreed, i'm all for good typing :) e.g. i assume/hope also
especially if linears are used to statically find memory problems.

Hongwei Xi

unread,
Oct 1, 2014, 4:22:35 PM10/1/14
to ats-lan...@googlegroups.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.

Raoul Duke

unread,
Oct 1, 2014, 4:30:41 PM10/1/14
to ats-lang-users
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 :-})

H Zhang

unread,
Oct 1, 2014, 4:40:50 PM10/1/14
to ats-lan...@googlegroups.com
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.

Barry Schwartz

unread,
Oct 1, 2014, 4:45:02 PM10/1/14
to ats-lan...@googlegroups.com
gmhwxi <gmh...@gmail.com> skribis:
> The typechecker of ATS will enforce type-correctness,
> which will get rid of a lot of stupid bugs.

I have put it this way:

Most programming errors are type errors in some language that people
aren’t using.


Raoul Duke

unread,
Oct 1, 2014, 4:45:35 PM10/1/14
to ats-lang-users
On Wed, Oct 1, 2014 at 1: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.

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

Raoul Duke

unread,
Oct 1, 2014, 4:47:40 PM10/1/14
to ats-lang-users
>> The typechecker of ATS will enforce type-correctness,
>> which will get rid of a lot of stupid bugs.
> I have put it this way:
> Most programming errors are type errors in some language that people
> aren’t using.

nice!



on the whole i mostly heartily concur with that way of thinking.

(although the time i saw a usenet post where somebody was trying to
explain how to use monads in haskell to reverse a string (in place, i
guess it must have been) was just horrible, vile, evil stuff. :-)

Barry Schwartz

unread,
Oct 1, 2014, 5:29:30 PM10/1/14
to ats-lan...@googlegroups.com
Raoul Duke <rao...@gmail.com> skribis:
The strictest static type systems I have used before are Caml Light
and OCaml, so I can’t vouch for Haskell’s monads being friendly or
not.

(I wonder if it might be more obvious to people that C actually
_causes_ buffer overruns, dangling pointers, etc., if they had
experience with FORTRAN 77, which has the same problems but few to no
kneejerk defenders.)

H Zhang

unread,
Oct 1, 2014, 5:36:56 PM10/1/14
to ats-lan...@googlegroups.com

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.

Raoul Duke

unread,
Oct 1, 2014, 5:43:19 PM10/1/14
to ats-lang-users
> part. ML Kit tried but regions management didn't work 100%. I am still
> trying to figure out how Rust is doing it.


i think Rust tried and claimed optimistic success with more than one
thing only to back off and go another way later. if i actually
understood the issue i assume i/one could google up answers with the
right keywords, no?

are you talking about managed vs. owned pointers?

Hongwei Xi

unread,
Oct 1, 2014, 5:45:06 PM10/1/14
to ats-lan...@googlegroups.com
>> 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.


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

Raoul Duke

unread,
Oct 1, 2014, 5:49:13 PM10/1/14
to ats-lang-users
> 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.


do i get it right that you can start with Boehm first, too? as the
most easy route to Getting Something Working. and then easily
(easily?) migrate to statically tracked manual memory management?

Hongwei Xi

unread,
Oct 1, 2014, 5:58:58 PM10/1/14
to ats-lan...@googlegroups.com
Indeed. This kind of gradual software development is what I think a great strength of ATS.


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

Barry Schwartz

unread,
Oct 1, 2014, 6:20:25 PM10/1/14
to ats-lan...@googlegroups.com
Hongwei Xi <gmh...@gmail.com> skribis:
> 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.

I’m disabled now, but when I was working I’d often write code for some
string-parsing task in Icon and then translate the result to C. Hardly
any difference in what the code did, but in Icon it was easier to
think.

H Zhang

unread,
Oct 1, 2014, 6:41:40 PM10/1/14
to ats-lan...@googlegroups.com
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).

Shea Levy

unread,
Oct 1, 2014, 6:50:39 PM10/1/14
to ats-lan...@googlegroups.com
If you want to just do exe_name := file_name_step + ".exe" and not have
to worry about it, then what's wrong exactly with using normal ADTs?

~Shea

On Wed, Oct 01, 2014 at 03:41:40PM -0700, H Zhang 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 <javascript:>>
> >> email to ats-lang-user...@googlegroups.com <javascript:>.
> >> To post to this group, send email to ats-lan...@googlegroups.com
> >> <javascript:>.
> >> <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.

Haitao Zhang

unread,
Oct 1, 2014, 6:57:58 PM10/1/14
to ats-lan...@googlegroups.com
That requires GC at some stage or "fixing" it manually. See Hongwei's earlier response:


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

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.

Barry Schwartz

unread,
Oct 1, 2014, 7:17:42 PM10/1/14
to ats-lan...@googlegroups.com
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.)

Haitao Zhang

unread,
Oct 1, 2014, 7:27:41 PM10/1/14
to ats-lan...@googlegroups.com
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.


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

Raoul Duke

unread,
Oct 1, 2014, 7:35:12 PM10/1/14
to ats-lang-users
> I’m disabled now, but when I was working I’d often write code for some
> string-parsing task in Icon and then translate the result to C. Hardly
> any difference in what the code did, but in Icon it was easier to
> think.

now if only there were a compiler that could do that for ya... :-)

Raoul Duke

unread,
Oct 1, 2014, 7:36:59 PM10/1/14
to ats-lang-users
On Wed, Oct 1, 2014 at 3:57 PM, Haitao Zhang <zht...@gmail.com> wrote:
> That requires GC at some stage

why is GC so bad? :-)

Hongwei Xi

unread,
Oct 1, 2014, 9:10:39 PM10/1/14
to ats-lan...@googlegroups.com
>>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.


gmhwxi

unread,
Oct 1, 2014, 9:18:02 PM10/1/14
to ats-lan...@googlegroups.com
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.

Haitao Zhang

unread,
Oct 1, 2014, 9:50:50 PM10/1/14
to ats-lan...@googlegroups.com
GC is not bad per se. We don't write code in isolation. I interact with GC'ed languages all day long, but sometimes I need to drop down to a lower level to write extensions. You can't just put GC in a library willy nilly.

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

Haitao Zhang

unread,
Oct 1, 2014, 9:55:45 PM10/1/14
to ats-lan...@googlegroups.com
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.

gmhwxi

unread,
Oct 1, 2014, 10:11:24 PM10/1/14
to ats-lan...@googlegroups.com
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(?).

Haitao Zhang

unread,
Oct 1, 2014, 10:14:27 PM10/1/14
to ats-lan...@googlegroups.com
Ah this is the thread (itself a continuation of a previous thread :-) 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.

Haitao Zhang

unread,
Oct 1, 2014, 10:17:42 PM10/1/14
to ats-lan...@googlegroups.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.

gmhwxi

unread,
Oct 1, 2014, 10:33:16 PM10/1/14
to ats-lan...@googlegroups.com
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).

Yannick Duchêne

unread,
Oct 1, 2014, 11:19:05 PM10/1/14
to ats-lan...@googlegroups.com


Le jeudi 2 octobre 2014 04:11:24 UTC+2, gmhwxi a écrit :
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?

Hongwei Xi

unread,
Oct 1, 2014, 11:48:19 PM10/1/14
to ats-lan...@googlegroups.com
In ATS2-contrib, there are also document/ and projects/, which are not packed
into the current release of ATS2-contrib. There directories only contain documentation,
which you can easily access on-line.


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

Haitao Zhang

unread,
Oct 1, 2014, 11:51:03 PM10/1/14
to ats-lan...@googlegroups.com
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?

gmhwxi

unread,
Oct 1, 2014, 11:59:44 PM10/1/14
to ats-lan...@googlegroups.com
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.

Haitao Zhang

unread,
Oct 2, 2014, 12:20:58 AM10/2/14
to ats-lan...@googlegroups.com
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.

Hongwei Xi

unread,
Oct 2, 2014, 1:37:49 AM10/2/14
to ats-lan...@googlegroups.com
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.


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

H Zhang

unread,
Oct 2, 2014, 11:20:30 AM10/2/14
to ats-lan...@googlegroups.com
I have a working C implementation. It didn't take much time but it is bare-bones. The trick was to get out of the C world as soon as I can. However if I can find a good more expressive replacement for C I feel a lot more can be done to make the extension easier to use. I test drove some DLL loading code using ATS at the time. While it is nice how easy it was to mix with the C world the expressiveness level wasn't much higher because I refrained from using the more functional features. Do you have an example of how you can implement something using all ATS features without regard to memory allocation issues and then later on fixing the leaks while maintaining the high level of expressiveness and readability? Showing some before and after code can be very helpful for people to understand what the expectation should be.

Brandon Barker

unread,
Oct 2, 2014, 11:37:26 AM10/2/14
to ats-lang-users
While this is probably not the only example, it is the first I could find: https://github.com/githwxi/ATS-Postiats/tree/master/doc/EXAMPLE/EFFECTIVATS/file-copying

Hongwei Xi

unread,
Oct 2, 2014, 12:25:23 PM10/2/14
to ats-lan...@googlegroups.com
Here is an example showing the 'non-linear' to 'linear' transition:

http://www.ats-lang.org/EXAMPLE/EFFECTIVATS/word-counting/main.html

The problem is that you don't get to see the process of doing the transition; you
can only see the end product of the transition.

Actually, a lot of code in libats went through the non-linear to linear transition.
For instance, the linear version of AVL tree implementation is entirely based on the
non-linear version. I emphasized this point explicitly in my ATS-intro book:

http://www.ats-lang.org/DOCUMENT/INT2PROGINATS/HTML/x4030.html


On Thu, Oct 2, 2014 at 11:20 AM, H Zhang <zht...@gmail.com> wrote:

Haitao Zhang

unread,
Oct 2, 2014, 7:23:01 PM10/2/14
to ats-lan...@googlegroups.com
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.
Reply all
Reply to author
Forward
0 new messages