# Some examples that might be helpful

**URL:** <https://discourse.ats-lang.org/t/some-examples-that-might-be-helpful/410>\
**Category:** Google Group\
**Created:** [March 4, 2014, 3:57pm UTC](https://discourse.ats-lang.org/t/some-examples-that-might-be-helpful/410 "2014-03-04T15:57:55Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chotu\_S](https://avatars.discourse-cdn.com/v4/letter/c/7cd45c/32.png) [@Chotu\_S](https://discourse.ats-lang.org/u/Chotu_S)\
**Post date:** [March 4, 2014, 3:57pm UTC](https://discourse.ats-lang.org/t/some-examples-that-might-be-helpful/410/1 "2014-03-04T15:57:55Z")

</div>

I have written some examples on array and classdec that might be helpful to  
some user of ATS. Most of these examples are similar to examples in "doc"  
of ATS and some directly taken from sources in ATS contrib and lib.

[https://bitbucket.org/chotu/ats\_code\_collect\_public/src/](https://bitbucket.org/chotu/ats_code_collect_public/src/)

Some of array examples consists of converting a array allocated on a stack  
to arrayptr , arrayview to arrayptr and arrayptr to arrayview.

A classdec example consist of simple single standalone application of gtk  
and does not use gtk from contrib.

Just a side note these might not be idiomatic of doing thing in ATS and  
can’t even say they are correct.

---

<div class="post-metadata">

**Author:** ![Brandon\_Barker](https://sea1.discourse-cdn.com/flex019/user_avatar/discourse.ats-lang.org/brandon_barker/32/61_2.png) [@Brandon\_Barker](https://discourse.ats-lang.org/u/Brandon_Barker)\
**Post date:** [March 7, 2014, 3:07am UTC](https://discourse.ats-lang.org/t/some-examples-that-might-be-helpful/410/2 "2014-03-07T03:07:15Z")

</div>

Where the end aim is to have a linear implementation and safety is not  
critical, I wonder if it is better to start out with linear mixed with  
unsafe, in order to make the transition easier later on (I do not know if  
this is true). It seems hard for most programmers to used to using  
unsafe.sats, but I am thinking of breaking the habit by deliberately trying  
to use it on some practice code as much as possible for a while.On Wednesday, March 5, 2014 9:55:31 AM UTC-5, gmhwxi wrote:

> One thing that sets ATS apart from other programming languages  
> is the support for gradually transitioning an implementation that depends  
> on  
> GC into one that does not. This kind of transitioning can be guided by  
> typechecking.
> 
> There are several ways to use higher-order functions in ATS without the  
> need for GC:
> 
> 1. Using templates.
> 2. Using stack-allocated closures.
> 3. Using linear closures, which are heap-allocated and can be safely freed.
> 
> Note that (1) and (2) do not even rely on malloc/free. So in ATS, you can  
> use higher-order functions in a setting (e.g., embedded programming) where  
> dynamic memory allocation is not allowed or supported.
> 
> On Wednesday, March 5, 2014 1:08:05 AM UTC-5, H Zhang wrote:
> 
> > If systems software is the target shouldn’t we try harder to remove  
> > dependence on GC? Or is it your view that non-linear types do not add much  
> > value in ATS? What about higher order functions and closures? If stack  
> > allocation is the answer how does one return a closure that is stack  
> > allocated (I assume functions are first class objects in ATS but I may be  
> > mistaken)? Or is GC dependence acceptable for systems software? Even if  
> > that were the case it is still hard to create portable libraries (which I  
> > think is where ATS could really shine, at least in the beginning) if there  
> > is a dependence on access to runtime GC.
> > 
> > Haitao
> > 
> > On Tuesday, March 4, 2014 6:49:26 PM UTC-8, gmhwxi wrote:
> > 
> > > Thanks for sharing it!
> > > 
> > > I can see that you are getting more and more comfortable with ATS 🙂
> > > 
> > > If more and more people are willing to contribute, then it may no longer  
> > > be too far-stretched to  
> > > say that ATS will be able to make a visible positive impact on the  
> > > qualify of software in the future.  
> > > In particular, the quality of systems software!
> > > 
> > > On Tuesday, March 4, 2014 10:57:55 AM UTC-5, chotu s wrote:
> > > 
> > > > I have written some examples on array and classdec that might be  
> > > > helpful to some user of ATS. Most of these examples are similar to examples  
> > > > in “doc” of ATS and some directly taken from sources in ATS contrib and lib.
> > > > 
> > > > [Bitbucket](https://bitbucket.org/chotu/ats_code_collect_public/src/)
> > > > 
> > > > Some of array examples consists of converting a array allocated on a  
> > > > stack to arrayptr , arrayview to arrayptr and arrayptr to arrayview.
> > > > 
> > > > A classdec example consist of simple single standalone application of  
> > > > gtk and does not use gtk from contrib.
> > > > 
> > > > Just a side note these might not be idiomatic of doing thing in ATS and  
> > > > can’t even say they are correct.

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [March 5, 2014, 2:49am UTC](https://discourse.ats-lang.org/t/some-examples-that-might-be-helpful/410/3 "2014-03-05T02:49:26Z")

</div>

Thanks for sharing it!

I can see that you are getting more and more comfortable with ATS 🙂

If more and more people are willing to contribute, then it may no longer be  
too far-stretched to  
say that ATS will be able to make a visible positive impact on the qualify  
of software in the future.  
In particular, the quality of systems software!On Tuesday, March 4, 2014 10:57:55 AM UTC-5, chotu s wrote:

> I have written some examples on array and classdec that might be helpful  
> to some user of ATS. Most of these examples are similar to examples in  
> “doc” of ATS and some directly taken from sources in ATS contrib and lib.
> 
> [Bitbucket](https://bitbucket.org/chotu/ats_code_collect_public/src/)
> 
> Some of array examples consists of converting a array allocated on a stack  
> to arrayptr , arrayview to arrayptr and arrayptr to arrayview.
> 
> A classdec example consist of simple single standalone application of gtk  
> and does not use gtk from contrib.
> 
> Just a side note these might not be idiomatic of doing thing in ATS and  
> can’t even say they are correct.

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [March 5, 2014, 2:55pm UTC](https://discourse.ats-lang.org/t/some-examples-that-might-be-helpful/410/4 "2014-03-05T14:55:31Z")

</div>

One thing that sets ATS apart from other programming languages  
is the support for gradually transitioning an implementation that depends on  
GC into one that does not. This kind of transitioning can be guided by  
typechecking.

There are several ways to use higher-order functions in ATS without the  
need for GC:

1. Using templates.
2. Using stack-allocated closures.
3. Using linear closures, which are heap-allocated and can be safely freed.

Note that (1) and (2) do not even rely on malloc/free. So in ATS, you can  
use higher-order functions in a setting (e.g., embedded programming) where  
dynamic memory allocation is not allowed or supported.On Wednesday, March 5, 2014 1:08:05 AM UTC-5, H Zhang wrote:

> If systems software is the target shouldn’t we try harder to remove  
> dependence on GC? Or is it your view that non-linear types do not add much  
> value in ATS? What about higher order functions and closures? If stack  
> allocation is the answer how does one return a closure that is stack  
> allocated (I assume functions are first class objects in ATS but I may be  
> mistaken)? Or is GC dependence acceptable for systems software? Even if  
> that were the case it is still hard to create portable libraries (which I  
> think is where ATS could really shine, at least in the beginning) if there  
> is a dependence on access to runtime GC.
> 
> Haitao
> 
> On Tuesday, March 4, 2014 6:49:26 PM UTC-8, gmhwxi wrote:
> 
> > Thanks for sharing it!
> > 
> > I can see that you are getting more and more comfortable with ATS 🙂
> > 
> > If more and more people are willing to contribute, then it may no longer  
> > be too far-stretched to  
> > say that ATS will be able to make a visible positive impact on the  
> > qualify of software in the future.  
> > In particular, the quality of systems software!
> > 
> > On Tuesday, March 4, 2014 10:57:55 AM UTC-5, chotu s wrote:
> > 
> > > I have written some examples on array and classdec that might be helpful  
> > > to some user of ATS. Most of these examples are similar to examples in  
> > > “doc” of ATS and some directly taken from sources in ATS contrib and lib.
> > > 
> > > [Bitbucket](https://bitbucket.org/chotu/ats_code_collect_public/src/)
> > > 
> > > Some of array examples consists of converting a array allocated on a  
> > > stack to arrayptr , arrayview to arrayptr and arrayptr to arrayview.
> > > 
> > > A classdec example consist of simple single standalone application of  
> > > gtk and does not use gtk from contrib.
> > > 
> > > Just a side note these might not be idiomatic of doing thing in ATS and  
> > > can’t even say they are correct.

---

<div class="post-metadata">

**Author:** ![H\_Zhang](https://avatars.discourse-cdn.com/v4/letter/h/b77776/32.png) [@H\_Zhang](https://discourse.ats-lang.org/u/H_Zhang)\
**Post date:** [March 5, 2014, 6:08am UTC](https://discourse.ats-lang.org/t/some-examples-that-might-be-helpful/410/5 "2014-03-05T06:08:05Z")

</div>

If systems software is the target shouldn’t we try harder to remove  
dependence on GC? Or is it your view that non-linear types do not add much  
value in ATS? What about higher order functions and closures? If stack  
allocation is the answer how does one return a closure that is stack  
allocated (I assume functions are first class objects in ATS but I may be  
mistaken)? Or is GC dependence acceptable for systems software? Even if  
that were the case it is still hard to create portable libraries (which I  
think is where ATS could really shine, at least in the beginning) if there  
is a dependence on access to runtime GC.

HaitaoOn Tuesday, March 4, 2014 6:49:26 PM UTC-8, gmhwxi wrote:

> Thanks for sharing it!
> 
> I can see that you are getting more and more comfortable with ATS 🙂
> 
> If more and more people are willing to contribute, then it may no longer  
> be too far-stretched to  
> say that ATS will be able to make a visible positive impact on the qualify  
> of software in the future.  
> In particular, the quality of systems software!
> 
> On Tuesday, March 4, 2014 10:57:55 AM UTC-5, chotu s wrote:
> 
> > I have written some examples on array and classdec that might be helpful  
> > to some user of ATS. Most of these examples are similar to examples in  
> > “doc” of ATS and some directly taken from sources in ATS contrib and lib.
> > 
> > [Bitbucket](https://bitbucket.org/chotu/ats_code_collect_public/src/)
> > 
> > Some of array examples consists of converting a array allocated on a  
> > stack to arrayptr , arrayview to arrayptr and arrayptr to arrayview.
> > 
> > A classdec example consist of simple single standalone application of gtk  
> > and does not use gtk from contrib.
> > 
> > Just a side note these might not be idiomatic of doing thing in ATS and  
> > can’t even say they are correct.

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [March 5, 2014, 2:50am UTC](https://discourse.ats-lang.org/t/some-examples-that-might-be-helpful/410/6 "2014-03-05T02:50:35Z")

</div>

I forgot the mention that I added objectify/unobjectify into  
prelude/arrayptr.  
Give them a try if you have time.On Tuesday, March 4, 2014 9:49:26 PM UTC-5, gmhwxi wrote:

> Thanks for sharing it!
> 
> I can see that you are getting more and more comfortable with ATS 🙂
> 
> If more and more people are willing to contribute, then it may no longer  
> be too far-stretched to  
> say that ATS will be able to make a visible positive impact on the qualify  
> of software in the future.  
> In particular, the quality of systems software!
> 
> On Tuesday, March 4, 2014 10:57:55 AM UTC-5, chotu s wrote:
> 
> > I have written some examples on array and classdec that might be helpful  
> > to some user of ATS. Most of these examples are similar to examples in  
> > “doc” of ATS and some directly taken from sources in ATS contrib and lib.
> > 
> > [Bitbucket](https://bitbucket.org/chotu/ats_code_collect_public/src/)
> > 
> > Some of array examples consists of converting a array allocated on a  
> > stack to arrayptr , arrayview to arrayptr and arrayptr to arrayview.
> > 
> > A classdec example consist of simple single standalone application of gtk  
> > and does not use gtk from contrib.
> > 
> > Just a side note these might not be idiomatic of doing thing in ATS and  
> > can’t even say they are correct.

---

<div class="post-metadata">

**Author:** ![Brandon\_Barker](https://sea1.discourse-cdn.com/flex019/user_avatar/discourse.ats-lang.org/brandon_barker/32/61_2.png) [@Brandon\_Barker](https://discourse.ats-lang.org/u/Brandon_Barker)\
**Post date:** [March 5, 2014, 6:14am UTC](https://discourse.ats-lang.org/t/some-examples-that-might-be-helpful/410/7 "2014-03-05T06:14:19Z")

</div>

I’m pretty sure functions are first class objects, but not function  
templates.

Brandon Barker  
brandon…@gmail.comOn Wed, Mar 5, 2014 at 1:11 AM, Brandon Barker [brandon...@gmail.com](mailto:brandon...@gmail.com)wrote:

> My impression is use of GC is often done while prototyping something.
> 
> For stack allocated closures see this thread:  
> [Redirecting to Google Groups](https://groups.google.com/forum/#!topic/ats-lang-users/wzPNLsScga4)
> 
> On Wednesday, March 5, 2014 1:08:05 AM UTC-5, H Zhang wrote:
> 
> > If systems software is the target shouldn’t we try harder to remove  
> > dependence on GC? Or is it your view that non-linear types do not add much  
> > value in ATS? What about higher order functions and closures? If stack  
> > allocation is the answer how does one return a closure that is stack  
> > allocated (I assume functions are first class objects in ATS but I may be  
> > mistaken)? Or is GC dependence acceptable for systems software? Even if  
> > that were the case it is still hard to create portable libraries (which I  
> > think is where ATS could really shine, at least in the beginning) if there  
> > is a dependence on access to runtime GC.
> > 
> > Haitao
> > 
> > On Tuesday, March 4, 2014 6:49:26 PM UTC-8, gmhwxi wrote:
> > 
> > > Thanks for sharing it!
> > > 
> > > I can see that you are getting more and more comfortable with ATS 🙂
> > > 
> > > If more and more people are willing to contribute, then it may no longer  
> > > be too far-stretched to  
> > > say that ATS will be able to make a visible positive impact on the  
> > > qualify of software in the future.  
> > > In particular, the quality of systems software!
> > > 
> > > On Tuesday, March 4, 2014 10:57:55 AM UTC-5, chotu s wrote:
> > > 
> > > > I have written some examples on array and classdec that might be  
> > > > helpful to some user of ATS. Most of these examples are similar to examples  
> > > > in “doc” of ATS and some directly taken from sources in ATS contrib and lib.
> > > > 
> > > > [Bitbucket](https://bitbucket.org/chotu/ats_code_collect_public/src/)
> > > > 
> > > > Some of array examples consists of converting a array allocated on a  
> > > > stack to arrayptr , arrayview to arrayptr and arrayptr to arrayview.
> > > > 
> > > > A classdec example consist of simple single standalone application of  
> > > > gtk and does not use gtk from contrib.
> > > > 
> > > > Just a side note these might not be idiomatic of doing thing in ATS and  
> > > > can’t even say they are correct.
> > > > 
> > > > –  
> > > > 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](mailto:ats-lang-user...@googlegroups.com).  
> > > > To post to this group, send email to [ats-lan...@googlegroups.com](mailto:ats-lan...@googlegroups.com).  
> > > > To view this discussion on the web visit  
> > > > [https://groups.google.com/d/msgid/ats-lang-users/e373105c-2177-4c44-801d-9a9e5d916f75%40googlegroups.com](https://groups.google.com/d/msgid/ats-lang-users/e373105c-2177-4c44-801d-9a9e5d916f75%40googlegroups.com)[https://groups.google.com/d/msgid/ats-lang-users/e373105c-2177-4c44-801d-9a9e5d916f75%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/ats-lang-users/e373105c-2177-4c44-801d-9a9e5d916f75%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > .

---

<div class="post-metadata">

**Author:** ![Brandon\_Barker](https://sea1.discourse-cdn.com/flex019/user_avatar/discourse.ats-lang.org/brandon_barker/32/61_2.png) [@Brandon\_Barker](https://discourse.ats-lang.org/u/Brandon_Barker)\
**Post date:** [March 5, 2014, 6:11am UTC](https://discourse.ats-lang.org/t/some-examples-that-might-be-helpful/410/8 "2014-03-05T06:11:28Z")

</div>

My impression is use of GC is often done while prototyping something.

For stack allocated closures see this thread:  
[Redirecting to Google Groups](https://groups.google.com/forum/#!topic/ats-lang-users/wzPNLsScga4On) Wednesday, March 5, 2014 1:08:05 AM UTC-5, H Zhang wrote:

> If systems software is the target shouldn’t we try harder to remove  
> dependence on GC? Or is it your view that non-linear types do not add much  
> value in ATS? What about higher order functions and closures? If stack  
> allocation is the answer how does one return a closure that is stack  
> allocated (I assume functions are first class objects in ATS but I may be  
> mistaken)? Or is GC dependence acceptable for systems software? Even if  
> that were the case it is still hard to create portable libraries (which I  
> think is where ATS could really shine, at least in the beginning) if there  
> is a dependence on access to runtime GC.
> 
> Haitao
> 
> On Tuesday, March 4, 2014 6:49:26 PM UTC-8, gmhwxi wrote:
> 
> > Thanks for sharing it!
> > 
> > I can see that you are getting more and more comfortable with ATS 🙂
> > 
> > If more and more people are willing to contribute, then it may no longer  
> > be too far-stretched to  
> > say that ATS will be able to make a visible positive impact on the  
> > qualify of software in the future.  
> > In particular, the quality of systems software!
> > 
> > On Tuesday, March 4, 2014 10:57:55 AM UTC-5, chotu s wrote:
> > 
> > > I have written some examples on array and classdec that might be helpful  
> > > to some user of ATS. Most of these examples are similar to examples in  
> > > “doc” of ATS and some directly taken from sources in ATS contrib and lib.
> > > 
> > > [Bitbucket](https://bitbucket.org/chotu/ats_code_collect_public/src/)
> > > 
> > > Some of array examples consists of converting a array allocated on a  
> > > stack to arrayptr , arrayview to arrayptr and arrayptr to arrayview.
> > > 
> > > A classdec example consist of simple single standalone application of  
> > > gtk and does not use gtk from contrib.
> > > 
> > > Just a side note these might not be idiomatic of doing thing in ATS and  
> > > can’t even say they are correct.

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [March 7, 2014, 5:41pm UTC](https://discourse.ats-lang.org/t/some-examples-that-might-be-helpful/410/9 "2014-03-07T17:41:43Z")

</div>

Ultimately, programming is an art.

One should use whatever he or she finds to be the most effective approach  
that suits  
his or her problems.On Thursday, March 6, 2014 10:07:15 PM UTC-5, Brandon Barker wrote:

> Where the end aim is to have a linear implementation and safety is not  
> critical, I wonder if it is better to start out with linear mixed with  
> unsafe, in order to make the transition easier later on (I do not know if  
> this is true). It seems hard for most programmers to used to using  
> unsafe.sats, but I am thinking of breaking the habit by deliberately trying  
> to use it on some practice code as much as possible for a while.
> 
> On Wednesday, March 5, 2014 9:55:31 AM UTC-5, gmhwxi wrote:
> 
> > One thing that sets ATS apart from other programming languages  
> > is the support for gradually transitioning an implementation that depends  
> > on  
> > GC into one that does not. This kind of transitioning can be guided by  
> > typechecking.
> > 
> > There are several ways to use higher-order functions in ATS without the  
> > need for GC:
> > 
> > 1. Using templates.
> > 2. Using stack-allocated closures.
> > 3. Using linear closures, which are heap-allocated and can be safely  
> > freed.
> > 
> > Note that (1) and (2) do not even rely on malloc/free. So in ATS, you can  
> > use higher-order functions in a setting (e.g., embedded programming) where  
> > dynamic memory allocation is not allowed or supported.
> > 
> > On Wednesday, March 5, 2014 1:08:05 AM UTC-5, H Zhang wrote:
> > 
> > > If systems software is the target shouldn’t we try harder to remove  
> > > dependence on GC? Or is it your view that non-linear types do not add much  
> > > value in ATS? What about higher order functions and closures? If stack  
> > > allocation is the answer how does one return a closure that is stack  
> > > allocated (I assume functions are first class objects in ATS but I may be  
> > > mistaken)? Or is GC dependence acceptable for systems software? Even if  
> > > that were the case it is still hard to create portable libraries (which I  
> > > think is where ATS could really shine, at least in the beginning) if there  
> > > is a dependence on access to runtime GC.
> > > 
> > > Haitao
> > > 
> > > On Tuesday, March 4, 2014 6:49:26 PM UTC-8, gmhwxi wrote:
> > > 
> > > > Thanks for sharing it!
> > > > 
> > > > I can see that you are getting more and more comfortable with ATS 🙂
> > > > 
> > > > If more and more people are willing to contribute, then it may no  
> > > > longer be too far-stretched to  
> > > > say that ATS will be able to make a visible positive impact on the  
> > > > qualify of software in the future.  
> > > > In particular, the quality of systems software!
> > > > 
> > > > On Tuesday, March 4, 2014 10:57:55 AM UTC-5, chotu s wrote:
> > > > 
> > > > > I have written some examples on array and classdec that might be  
> > > > > helpful to some user of ATS. Most of these examples are similar to examples  
> > > > > in “doc” of ATS and some directly taken from sources in ATS contrib and lib.
> > > > > 
> > > > > [Bitbucket](https://bitbucket.org/chotu/ats_code_collect_public/src/)
> > > > > 
> > > > > Some of array examples consists of converting a array allocated on a  
> > > > > stack to arrayptr , arrayview to arrayptr and arrayptr to arrayview.
> > > > > 
> > > > > A classdec example consist of simple single standalone application of  
> > > > > gtk and does not use gtk from contrib.
> > > > > 
> > > > > Just a side note these might not be idiomatic of doing thing in ATS  
> > > > > and can’t even say they are correct.
