Request for some comments on ats code

For review purpose I have written a very tiny code for vectors in ats. If
anyone can quickly go through it (whenever they get free time) and comment
on the points below will be great. I have tried the code to be similar to
examples given in “Effective ATS” .

Code is given here : Vectorshttps://bitbucket.org/chotu/ats-explore/src/534b279028e38488265860a5cac81820381c272d/lainats/vector.dats?at=master

  1. I want to know how to allocate the vector on a stack instead on a heap

  2. I want to know is vector_add function ok ?

  3. Is this how one would go about programming in ATS2

Any further comment is also welcome

Thanks

I can’t seem to compile the code for :

#include “share/atspre_define.hats”
#include “share/atspre_staload.hats”
staload UN = “prelude/SATS/unsafe.sats”

implement main0 () = {
var bytes = @100
}

Or did you meant :

var bytes = @[byte][100]On Fri, Feb 14, 2014 at 9:48 PM, gmhwxi gmh...@gmail.com wrote:

You are welcome.

A good design should decouple the issue of memory allocation
and object initialization:

extern
fun vector_make_ngc{n:int}{l:addr} (bytes(n) @ l | ptr (l)): vector

var bytes = @100 // statically allocated stack memory of 100 bytes
val vector = vector_make_ngc (view@bytes | addr@bytes)

Take a look at:

http://www.ats-lang.org/LIBRARY/libats/qlist.html

The functions qstruct_objectify and qstruct_unobjectify may shed some
light on this.

On Friday, February 14, 2014 10:56:05 AM UTC-5, chotu s wrote:

Thanks a “lot” guys , I’ll read all the suggestions and links tomorrow(as
it is late here) and will ask related question after that.

Regarding stack allocation , what I had in mind was small size and
temporary arrays whose size is known at compile time , some thing like val
v = make_local_vector_n(n) , where n is known at compile time.

I think stack allocation idea came to me from the udacity parallel
programming competition where allocating main memory on gpu was costly(if I
remember correctly) , but they had different types of memory layer so one
can also use the fast shared memory whose capacity ranged from 64K to
256K(subject to correction).

Thanks for great suggestions.

On Fri, Feb 14, 2014 at 8:50 PM, gmhwxi gmh...@gmail.com wrote:

Actually, most people do not realize that a real danger with alloca is
that tail-recursion,
which should be done in constant space, may easily cause stack-overflow
when it is coupled
with stack-allocation. The issue is very similar to inlining a function
that calls alloca.

On Friday, February 14, 2014 10:09:12 AM UTC-5, Brandon Barker wrote:

Thanks, also here’s some related discussion http://stackoverflow.com/
questions/1018853/why-is-alloca-not-considered-good-practice.
On Feb 14, 2014 9:43 AM, “gmhwxi” gmh...@gmail.com wrote:

You can use alloca to allocate memory on stack at run-time.
Here is an example I did:

https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAM
PLE/ATS-QA-LIST/alloca.dats

On Friday, February 14, 2014 8:23:49 AM UTC-5, Brandon Barker wrote:

For stack allocation my impression is that you allocate it as a tuple:
See this page and the next page:
http://www.ats-lang.org/DOCUMENT/INTPROGINATS/HTML/x273.html

I don’t know how to write a function to allocate a tuple of arbitrary
size, however.

Brandon Barker
brand...@gmail.com

On Fri, Feb 14, 2014 at 2:16 AM, chotu s cho...@gmail.com wrote:

Thanks I’ll take a look soon.

On Fri, Feb 14, 2014 at 11:27 AM, gmhwxi gmh...@gmail.com wrote:

Here is an interface for vectors:

http://www.ats-lang.org/LIBRARY/libats/gvector.html

On Friday, February 14, 2014 12:52:16 AM UTC-5, gmhwxi wrote:

In general, if the index n occurs in the type vector(a, n), then
the size (of the type int(n)) should not be
stored inside a vector (of the type vector(a, n)). A big point in
having dependent types is to allow a vector
and its size information to be stored separately.

On Friday, February 14, 2014 12:39:37 AM UTC-5, gmhwxi wrote:

When you say ‘allocate the vector on a stack’, do you mean
allocating
the arrayptr on stack?

On Thursday, February 13, 2014 11:20:33 PM UTC-5, chotu s wrote:

For review purpose I have written a very tiny code for vectors
in ats. If anyone can quickly go through it (whenever they get free time)
and comment on the points below will be great. I have tried the code to be
similar to examples given in “Effective ATS” .

Code is given here : Vectorshttps://bitbucket.org/chotu/ats-explore/src/534b279028e38488265860a5cac81820381c272d/lainats/vector.dats?at=master

  1. I want to know how to allocate the vector on a stack instead
    on a heap

  2. I want to know is vector_add function ok ?

  3. Is this how one would go about programming in ATS2

Any further comment is also welcome

Thanks


You received this message because you are subscribed to the Google
Groups “ats-lang-users” group.
To unsubscribe from this group and stop receiving emails from it,
send an email to ats-lang...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/2c3bcbb2-ca
d6-46da-956c-b0da4c129450%40googlegroups.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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/CAAZxu4zZHW
YAW2AD8sU6VVdsQ7Fk%3DGbG81JdpMV5ZYPzYurAsg%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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/
msgid/ats-lang-users/57f1a0bb-f0ba-4a06-95b3-15f988245530%40go
oglegroups.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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/3b808393-f696-4513-b065-f978e68e751b%40googlegroups.com
.

For stack allocation my impression is that you allocate it as a tuple:
See this page and the next page:
http://www.ats-lang.org/DOCUMENT/INTPROGINATS/HTML/x273.html

I don’t know how to write a function to allocate a tuple of arbitrary size,
however.

Brandon Barker
brandon…@gmail.comOn Fri, Feb 14, 2014 at 2:16 AM, chotu s chot...@gmail.com wrote:

Thanks I’ll take a look soon.

On Fri, Feb 14, 2014 at 11:27 AM, gmhwxi gmh...@gmail.com wrote:

Here is an interface for vectors:

http://www.ats-lang.org/LIBRARY/libats/gvector.html

On Friday, February 14, 2014 12:52:16 AM UTC-5, gmhwxi wrote:

In general, if the index n occurs in the type vector(a, n), then the
size (of the type int(n)) should not be
stored inside a vector (of the type vector(a, n)). A big point in having
dependent types is to allow a vector
and its size information to be stored separately.

On Friday, February 14, 2014 12:39:37 AM UTC-5, gmhwxi wrote:

When you say ‘allocate the vector on a stack’, do you mean allocating
the arrayptr on stack?

On Thursday, February 13, 2014 11:20:33 PM UTC-5, chotu s wrote:

For review purpose I have written a very tiny code for vectors in ats.
If anyone can quickly go through it (whenever they get free time) and
comment on the points below will be great. I have tried the code to be
similar to examples given in “Effective ATS” .

Code is given here : Vectorshttps://bitbucket.org/chotu/ats-explore/src/534b279028e38488265860a5cac81820381c272d/lainats/vector.dats?at=master

  1. I want to know how to allocate the vector on a stack instead on a
    heap

  2. I want to know is vector_add function ok ?

  3. Is this how one would go about programming in ATS2

Any further comment is also welcome

Thanks


You received this message because you are subscribed to the Google Groups
“ats-lang-users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/2c3bcbb2-cad6-46da-956c-b0da4c129450%40googlegroups.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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/CAAZxu4zZHWYAW2AD8sU6VVdsQ7Fk%3DGbG81JdpMV5ZYPzYurAsg%40mail.gmail.com
.

When you say ‘allocate the vector on a stack’, do you mean allocating
the arrayptr on stack?On Thursday, February 13, 2014 11:20:33 PM UTC-5, chotu s wrote:

For review purpose I have written a very tiny code for vectors in ats. If
anyone can quickly go through it (whenever they get free time) and comment
on the points below will be great. I have tried the code to be similar to
examples given in “Effective ATS” .

Code is given here : Vectorshttps://bitbucket.org/chotu/ats-explore/src/534b279028e38488265860a5cac81820381c272d/lainats/vector.dats?at=master

  1. I want to know how to allocate the vector on a stack instead on a heap

  2. I want to know is vector_add function ok ?

  3. Is this how one would go about programming in ATS2

Any further comment is also welcome

Thanks

Thanks, also here’s some related discussion
c - Why is the use of alloca() not considered good practice? - Stack Overflow Feb 14, 2014 9:43 AM, “gmhwxi” gmh...@gmail.com wrote:

You can use alloca to allocate memory on stack at run-time.
Here is an example I did:

https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAMPLE/ATS-QA-LIST/alloca.dats

On Friday, February 14, 2014 8:23:49 AM UTC-5, Brandon Barker wrote:

For stack allocation my impression is that you allocate it as a tuple:
See this page and the next page:
http://www.ats-lang.org/DOCUMENT/INTPROGINATS/HTML/x273.html

I don’t know how to write a function to allocate a tuple of arbitrary
size, however.

Brandon Barker
brand...@gmail.com

On Fri, Feb 14, 2014 at 2:16 AM, chotu s cho...@gmail.com wrote:

Thanks I’ll take a look soon.

On Fri, Feb 14, 2014 at 11:27 AM, gmhwxi gmh...@gmail.com wrote:

Here is an interface for vectors:

http://www.ats-lang.org/LIBRARY/libats/gvector.html

On Friday, February 14, 2014 12:52:16 AM UTC-5, gmhwxi wrote:

In general, if the index n occurs in the type vector(a, n), then the
size (of the type int(n)) should not be
stored inside a vector (of the type vector(a, n)). A big point in
having dependent types is to allow a vector
and its size information to be stored separately.

On Friday, February 14, 2014 12:39:37 AM UTC-5, gmhwxi wrote:

When you say ‘allocate the vector on a stack’, do you mean allocating
the arrayptr on stack?

On Thursday, February 13, 2014 11:20:33 PM UTC-5, chotu s wrote:

For review purpose I have written a very tiny code for vectors in
ats. If anyone can quickly go through it (whenever they get free time) and
comment on the points below will be great. I have tried the code to be
similar to examples given in “Effective ATS” .

Code is given here : Vectorshttps://bitbucket.org/chotu/ats-explore/src/534b279028e38488265860a5cac81820381c272d/lainats/vector.dats?at=master

  1. I want to know how to allocate the vector on a stack instead on
    a heap

  2. I want to know is vector_add function ok ?

  3. Is this how one would go about programming in ATS2

Any further comment is also welcome

Thanks


You received this message because you are subscribed to the Google
Groups “ats-lang-users” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to ats-lang...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/
msgid/ats-lang-users/2c3bcbb2-cad6-46da-956c-b0da4c129450%
40googlegroups.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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/
msgid/ats-lang-users/CAAZxu4zZHWYAW2AD8sU6VVdsQ7Fk%
3DGbG81JdpMV5ZYPzYurAsg%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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/57f1a0bb-f0ba-4a06-95b3-15f988245530%40googlegroups.com
.

I had forgotten the rather important point that the buffer had not been
initialized.

typedef bytes (n:int) = @[byte][n]

typedef b0ytes (n:int) = @[byte?][n]On Tuesday, February 18, 2014 2:32:05 PM UTC-5, gmhwxi wrote:

Here is some code for doing stack allocation of a vector:

(* ****** ****** *)

abstype vector(l:addr, n:int)

(* ****** ****** *)

extern
fun vector_make_ngc
{l:addr}{n:int} (b0ytes(n) @ l | ptr l): vector(l, n)
extern
fun vector_unmake_ngc
{l:addr}{n:int} (vector(l, n)): (bytes(n) @ l | ptr l)

(* ****** ****** *)

implement
main0 () =
{
var mybuf = @[byte]100
val myvec = vector_make_ngc (view@mybuf | addr@mybuf)
val (pf | p) = vector_unmake_ngc (myvec)
prval () = view@mybuf := pf
}

(* ****** ****** *)

On Tuesday, February 18, 2014 10:12:47 AM UTC-5, chotu s wrote:

Thanks. It compiles now. I’ll study the code.

On Tue, Feb 18, 2014 at 8:19 PM, Brandon Barker brand...@gmail.comwrote:

Also:

  1. I don’t think you need the first staload I had
  2. If you replace the identifier ‘mybytes’ with ‘bytes’ you will run in
    to trouble.

On Tuesday, February 18, 2014 9:47:15 AM UTC-5, Brandon Barker wrote:

You are right, I was just curious to get a better idea of what was
happening (if it existed).

I’m not really sure why what you are doing doesn’t typecheck, but here
is a version that does:

#include “share/atspre_define.hats”
#include “share/atspre_staload.hats”

staload “prelude/basics_sta.sats”
staload UN = “prelude/SATS/unsafe.sats”

extern
fun
vector_make_ngc{n:int}{l:addr} (!bytes(n) @ l | ptr (l)): void

implement main0 () = {
var mybytes = @[byte]100 // statically allocated stack memory of
100 bytes

val (pf2, fpf2 | p2) = $UN.ptr0_vtake{bytes(100)}(addr@mybytes)
val () = vector_make_ngc (pf2 | p2)
prval() = fpf2(pf2)

}

On Tuesday, February 18, 2014 8:58:28 AM UTC-5, chotu s wrote:

I don’t think I need a implementation of vector_make_ngc to compile
the code , I only want it to type check , but correct me if I am wrong.

On Tue, Feb 18, 2014 at 7:24 PM, Brandon Barker brand...@gmail.comwrote:

Where is the implementation for vector_make_ngc?

Brandon Barker
brand...@gmail.com

On Tue, Feb 18, 2014 at 8:43 AM, chotu s cho...@gmail.com wrote:

I can’t seem to compile example :

#include “share/atspre_define.hats”
#include “share/atspre_staload.hats”

extern
fun
vector_make_ngc{n:int}{l:addr} (bytes(n) @ l | ptr (l)): void

implement main0 () = {
var bytes = @[byte]100 // statically allocated stack memory of
100 bytes
val () = vector_make_ngc (view@bytes | addr@bytes)
}

On Sat, Feb 15, 2014 at 8:27 PM, gmhwxi gmh...@gmail.com wrote:

implement main0 () = {
var bytes = @[char]100

}

On Saturday, February 15, 2014 5:23:51 AM UTC-5, chotu s wrote:

I can’t seem to compile the code for :

#include “share/atspre_define.hats”
#include “share/atspre_staload.hats”
staload UN = “prelude/SATS/unsafe.sats”

implement main0 () = {
var bytes = @100
}

Or did you meant :

var bytes = @[byte][100]

On Fri, Feb 14, 2014 at 9:48 PM, gmhwxi gmh...@gmail.com wrote:

You are welcome.

A good design should decouple the issue of memory allocation
and object initialization:

extern
fun vector_make_ngc{n:int}{l:addr} (bytes(n) @ l | ptr (l)):
vector

var bytes = @100 // statically allocated stack memory of 100
bytes
val vector = vector_make_ngc (view@bytes | addr@bytes)

Take a look at:

http://www.ats-lang.org/LIBRARY/libats/qlist.html

The functions qstruct_objectify and qstruct_unobjectify may shed
some light on this.

On Friday, February 14, 2014 10:56:05 AM UTC-5, chotu s wrote:

Thanks a “lot” guys , I’ll read all the suggestions and links
tomorrow(as it is late here) and will ask related question after that.

Regarding stack allocation , what I had in mind was small size
and temporary arrays whose size is known at compile time , some thing like
val v = make_local_vector_n(n) , where n is known at compile time.

I think stack allocation idea came to me from the udacity
parallel programming competition where allocating main memory on gpu was
costly(if I remember correctly) , but they had different types of memory
layer so one can also use the fast shared memory whose capacity ranged from
64K to 256K(subject to correction).

Thanks for great suggestions.

On Fri, Feb 14, 2014 at 8:50 PM, gmhwxi gmh...@gmail.comwrote:

Actually, most people do not realize that a real danger with
alloca is that tail-recursion,
which should be done in constant space, may easily cause
stack-overflow when it is coupled
with stack-allocation. The issue is very similar to inlining a
function that calls alloca.

On Friday, February 14, 2014 10:09:12 AM UTC-5, Brandon Barker wrote:

Thanks, also here’s some related discussion
c - Why is the use of alloca() not considered good practice? - Stack Overflow
-considered-good-practice.
On Feb 14, 2014 9:43 AM, “gmhwxi” gmh...@gmail.com wrote:

You can use alloca to allocate memory on stack at run-time.
Here is an example I did:

https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAM
PLE/ATS-QA-LIST/alloca.dats

On Friday, February 14, 2014 8:23:49 AM UTC-5, Brandon Barker wrote:

For stack allocation my impression is that you allocate it
as a tuple:
See this page and the next page:
http://www.ats-lang.org/DOCUMENT/INTPROGINATS/HTML/x273.html

I don’t know how to write a function to allocate a tuple of
arbitrary size, however.

Brandon Barker
brand...@gmail.com

On Fri, Feb 14, 2014 at 2:16 AM, chotu s cho...@gmail.comwrote:

Thanks I’ll take a look soon.

On Fri, Feb 14, 2014 at 11:27 AM, gmhwxi gmh...@gmail.comwrote:

Here is an interface for vectors:

http://www.ats-lang.org/LIBRARY/libats/gvector.html

On Friday, February 14, 2014 12:52:16 AM UTC-5, gmhwxi wrote:

In general, if the index n occurs in the type vector(a,
n), then the size (of the type int(n)) should not be
stored inside a vector (of the type vector(a, n)). A big
point in having dependent types is to allow a vector
and its size information to be stored separately.

On Friday, February 14, 2014 12:39:37 AM UTC-5, gmhwxi wrote:

When you say ‘allocate the vector on a stack’, do you
mean allocating
the arrayptr on stack?

On Thursday, February 13, 2014 11:20:33 PM UTC-5, chotu s wrote:

For review purpose I have written a very tiny code for
vectors in ats. If anyone can quickly go through it (whenever they get free
time) and comment on the points below will be great. I have tried the code
to be similar to examples given in “Effective ATS” .

Code is given here : Vectorshttps://bitbucket.org/chotu/ats-explore/src/534b279028e38488265860a5cac81820381c272d/lainats/vector.dats?at=master

  1. I want to know how to allocate the vector on a
    stack instead on a heap

  2. I want to know is vector_add function ok ?

  3. Is this how one would go about programming in ATS2

Any further comment is also welcome

Thanks


You received this message because you are subscribed to
the Google Groups “ats-lang-users” group.
To unsubscribe from this group and stop receiving emails
from it, send an email to ats-lang-user…@googlegroups.
com.
To post to this group, send email to
ats-l...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/2c3bcbb2-
cad6-46da-956c-b0da4c129450%40googlegroups.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...@googlegroups.com
.
To post to this group, send email to
ats-l...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/
CAAZxu4zZHWYAW2AD8sU6VVdsQ7Fk%3DGbG81JdpMV5ZYPzYurAsg%
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...@googlegroups.com.
To post to this group, send email to ats-lan…@googlegroups.
com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/57f1a0bb-f0
ba-4a06-95b3-15f988245530%40googlegroups.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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/3b808393-f6
96-4513-b065-f978e68e751b%40googlegroups.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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/58c3c8d5-
3127-4979-bd72-728e60714c4d%40googlegroups.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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/
CAAZxu4xy1fbQVOEusuYegR4_oirETTL6k-9JRxGCrYKpUvF9VA%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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/4514da67-3db8-4b9c-92fa-590d3d3a208a%40googlegroups.com
.

Allocating a vector of size n on stack for n that is unknown until run-time
is not really
a good practice. There is really very little you can gain but you do run a
big risk of stack overflow.On Friday, February 14, 2014 2:13:02 AM UTC-5, chotu s wrote:

Thanks for reply.

I meant something as given here :

Redirecting to Google Groups

That is I have abstract type vector and when I create a vector the amount
of space need to store its content is taken from stack instead of heap. I
want something like this :

val vect = make_local_vector_of_size_n (n)

I assume that this will be again implementation dependent right ?

On Fri, Feb 14, 2014 at 11:09 AM, gmhwxi <gmh...@gmail.com <javascript:>>wrote:

When you say ‘allocate the vector on a stack’, do you mean allocating
the arrayptr on stack?

On Thursday, February 13, 2014 11:20:33 PM UTC-5, chotu s wrote:

For review purpose I have written a very tiny code for vectors in ats.
If anyone can quickly go through it (whenever they get free time) and
comment on the points below will be great. I have tried the code to be
similar to examples given in “Effective ATS” .

Code is given here : Vectorshttps://bitbucket.org/chotu/ats-explore/src/534b279028e38488265860a5cac81820381c272d/lainats/vector.dats?at=master

  1. I want to know how to allocate the vector on a stack instead on a
    heap

  2. I want to know is vector_add function ok ?

  3. Is this how one would go about programming in ATS2

Any further comment is also welcome

Thanks


You received this message because you are subscribed to the Google Groups
“ats-lang-users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to ats-lang...@googlegroups.com <javascript:>.
To post to this group, send email to ats-l...@googlegroups.com<javascript:>
.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/231c5688-dbf7-42d7-bb3e-27c04eb6868c%40googlegroups.com
.

You are welcome.

A good design should decouple the issue of memory allocation
and object initialization:

extern
fun vector_make_ngc{n:int}{l:addr} (bytes(n) @ l | ptr (l)): vector

var bytes = @100 // statically allocated stack memory of 100 bytes
val vector = vector_make_ngc (view@bytes | addr@bytes)

Take a look at:

http://www.ats-lang.org/LIBRARY/libats/qlist.html

The functions qstruct_objectify and qstruct_unobjectify may shed some light
on this.On Friday, February 14, 2014 10:56:05 AM UTC-5, chotu s wrote:

Thanks a “lot” guys , I’ll read all the suggestions and links tomorrow(as
it is late here) and will ask related question after that.

Regarding stack allocation , what I had in mind was small size and
temporary arrays whose size is known at compile time , some thing like val
v = make_local_vector_n(n) , where n is known at compile time.

I think stack allocation idea came to me from the udacity parallel
programming competition where allocating main memory on gpu was costly(if I
remember correctly) , but they had different types of memory layer so one
can also use the fast shared memory whose capacity ranged from 64K to
256K(subject to correction).

Thanks for great suggestions.

On Fri, Feb 14, 2014 at 8:50 PM, gmhwxi <gmh...@gmail.com <javascript:>>wrote:

Actually, most people do not realize that a real danger with alloca is
that tail-recursion,
which should be done in constant space, may easily cause stack-overflow
when it is coupled
with stack-allocation. The issue is very similar to inlining a function
that calls alloca.

On Friday, February 14, 2014 10:09:12 AM UTC-5, Brandon Barker wrote:

Thanks, also here’s some related discussion http://stackoverflow.com/
questions/1018853/why-is-alloca-not-considered-good-practice.
On Feb 14, 2014 9:43 AM, “gmhwxi” gmh...@gmail.com wrote:

You can use alloca to allocate memory on stack at run-time.
Here is an example I did:

https://github.com/githwxi/ATS-Postiats/blob/master/doc/
EXAMPLE/ATS-QA-LIST/alloca.dats

On Friday, February 14, 2014 8:23:49 AM UTC-5, Brandon Barker wrote:

For stack allocation my impression is that you allocate it as a tuple:
See this page and the next page:
http://www.ats-lang.org/DOCUMENT/INTPROGINATS/HTML/x273.html

I don’t know how to write a function to allocate a tuple of arbitrary
size, however.

Brandon Barker
brand...@gmail.com

On Fri, Feb 14, 2014 at 2:16 AM, chotu s cho...@gmail.com wrote:

Thanks I’ll take a look soon.

On Fri, Feb 14, 2014 at 11:27 AM, gmhwxi gmh...@gmail.com wrote:

Here is an interface for vectors:

http://www.ats-lang.org/LIBRARY/libats/gvector.html

On Friday, February 14, 2014 12:52:16 AM UTC-5, gmhwxi wrote:

In general, if the index n occurs in the type vector(a, n), then
the size (of the type int(n)) should not be
stored inside a vector (of the type vector(a, n)). A big point in
having dependent types is to allow a vector
and its size information to be stored separately.

On Friday, February 14, 2014 12:39:37 AM UTC-5, gmhwxi wrote:

When you say ‘allocate the vector on a stack’, do you mean
allocating
the arrayptr on stack?

On Thursday, February 13, 2014 11:20:33 PM UTC-5, chotu s wrote:

For review purpose I have written a very tiny code for vectors in
ats. If anyone can quickly go through it (whenever they get free time) and
comment on the points below will be great. I have tried the code to be
similar to examples given in “Effective ATS” .

Code is given here : Vectorshttps://bitbucket.org/chotu/ats-explore/src/534b279028e38488265860a5cac81820381c272d/lainats/vector.dats?at=master

  1. I want to know how to allocate the vector on a stack instead
    on a heap

  2. I want to know is vector_add function ok ?

  3. Is this how one would go about programming in ATS2

Any further comment is also welcome

Thanks


You received this message because you are subscribed to the Google
Groups “ats-lang-users” group.
To unsubscribe from this group and stop receiving emails from it,
send an email to ats-lang...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/2c3bcbb2-ca
d6-46da-956c-b0da4c129450%40googlegroups.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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/
msgid/ats-lang-users/CAAZxu4zZHWYAW2AD8sU6VVdsQ7Fk%3DGbG81JdpM
V5ZYPzYurAsg%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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/
msgid/ats-lang-users/57f1a0bb-f0ba-4a06-95b3-15f988245530%
40googlegroups.com.

Here is an interface for vectors:

http://www.ats-lang.org/LIBRARY/libats/gvector.htmlOn Friday, February 14, 2014 12:52:16 AM UTC-5, gmhwxi wrote:

In general, if the index n occurs in the type vector(a, n), then the size
(of the type int(n)) should not be
stored inside a vector (of the type vector(a, n)). A big point in having
dependent types is to allow a vector
and its size information to be stored separately.

On Friday, February 14, 2014 12:39:37 AM UTC-5, gmhwxi wrote:

When you say ‘allocate the vector on a stack’, do you mean allocating
the arrayptr on stack?

On Thursday, February 13, 2014 11:20:33 PM UTC-5, chotu s wrote:

For review purpose I have written a very tiny code for vectors in ats.
If anyone can quickly go through it (whenever they get free time) and
comment on the points below will be great. I have tried the code to be
similar to examples given in “Effective ATS” .

Code is given here : Vectorshttps://bitbucket.org/chotu/ats-explore/src/534b279028e38488265860a5cac81820381c272d/lainats/vector.dats?at=master

  1. I want to know how to allocate the vector on a stack instead on a
    heap

  2. I want to know is vector_add function ok ?

  3. Is this how one would go about programming in ATS2

Any further comment is also welcome

Thanks

I can’t seem to compile example :

#include “share/atspre_define.hats”
#include “share/atspre_staload.hats”

extern
fun
vector_make_ngc{n:int}{l:addr} (bytes(n) @ l | ptr (l)): void

implement main0 () = {
var bytes = @[byte]100 // statically allocated stack memory of 100
bytes
val () = vector_make_ngc (view@bytes | addr@bytes)
}On Sat, Feb 15, 2014 at 8:27 PM, gmhwxi gmh...@gmail.com wrote:

implement main0 () = {
var bytes = @[char]100

}

On Saturday, February 15, 2014 5:23:51 AM UTC-5, chotu s wrote:

I can’t seem to compile the code for :

#include “share/atspre_define.hats”
#include “share/atspre_staload.hats”
staload UN = “prelude/SATS/unsafe.sats”

implement main0 () = {
var bytes = @100
}

Or did you meant :

var bytes = @[byte][100]

On Fri, Feb 14, 2014 at 9:48 PM, gmhwxi gmh...@gmail.com wrote:

You are welcome.

A good design should decouple the issue of memory allocation
and object initialization:

extern
fun vector_make_ngc{n:int}{l:addr} (bytes(n) @ l | ptr (l)): vector

var bytes = @100 // statically allocated stack memory of 100 bytes
val vector = vector_make_ngc (view@bytes | addr@bytes)

Take a look at:

http://www.ats-lang.org/LIBRARY/libats/qlist.html

The functions qstruct_objectify and qstruct_unobjectify may shed some
light on this.

On Friday, February 14, 2014 10:56:05 AM UTC-5, chotu s wrote:

Thanks a “lot” guys , I’ll read all the suggestions and links
tomorrow(as it is late here) and will ask related question after that.

Regarding stack allocation , what I had in mind was small size and
temporary arrays whose size is known at compile time , some thing like val
v = make_local_vector_n(n) , where n is known at compile time.

I think stack allocation idea came to me from the udacity parallel
programming competition where allocating main memory on gpu was costly(if I
remember correctly) , but they had different types of memory layer so one
can also use the fast shared memory whose capacity ranged from 64K to
256K(subject to correction).

Thanks for great suggestions.

On Fri, Feb 14, 2014 at 8:50 PM, gmhwxi gmh...@gmail.com wrote:

Actually, most people do not realize that a real danger with alloca is
that tail-recursion,
which should be done in constant space, may easily cause
stack-overflow when it is coupled
with stack-allocation. The issue is very similar to inlining a
function that calls alloca.

On Friday, February 14, 2014 10:09:12 AM UTC-5, Brandon Barker wrote:

Thanks, also here’s some related discussion http://stackoverflow.com/
questions/1018853/why-is-alloca-not-considered-good-practice.
On Feb 14, 2014 9:43 AM, “gmhwxi” gmh...@gmail.com wrote:

You can use alloca to allocate memory on stack at run-time.
Here is an example I did:

https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAM
PLE/ATS-QA-LIST/alloca.dats

On Friday, February 14, 2014 8:23:49 AM UTC-5, Brandon Barker wrote:

For stack allocation my impression is that you allocate it as a
tuple:
See this page and the next page:
http://www.ats-lang.org/DOCUMENT/INTPROGINATS/HTML/x273.html

I don’t know how to write a function to allocate a tuple of
arbitrary size, however.

Brandon Barker
brand...@gmail.com

On Fri, Feb 14, 2014 at 2:16 AM, chotu s cho...@gmail.com wrote:

Thanks I’ll take a look soon.

On Fri, Feb 14, 2014 at 11:27 AM, gmhwxi gmh...@gmail.com wrote:

Here is an interface for vectors:

http://www.ats-lang.org/LIBRARY/libats/gvector.html

On Friday, February 14, 2014 12:52:16 AM UTC-5, gmhwxi wrote:

In general, if the index n occurs in the type vector(a, n), then
the size (of the type int(n)) should not be
stored inside a vector (of the type vector(a, n)). A big point
in having dependent types is to allow a vector
and its size information to be stored separately.

On Friday, February 14, 2014 12:39:37 AM UTC-5, gmhwxi wrote:

When you say ‘allocate the vector on a stack’, do you mean
allocating
the arrayptr on stack?

On Thursday, February 13, 2014 11:20:33 PM UTC-5, chotu s wrote:

For review purpose I have written a very tiny code for vectors
in ats. If anyone can quickly go through it (whenever they get free time)
and comment on the points below will be great. I have tried the code to be
similar to examples given in “Effective ATS” .

Code is given here : Vectorshttps://bitbucket.org/chotu/ats-explore/src/534b279028e38488265860a5cac81820381c272d/lainats/vector.dats?at=master

  1. I want to know how to allocate the vector on a stack
    instead on a heap

  2. I want to know is vector_add function ok ?

  3. Is this how one would go about programming in ATS2

Any further comment is also welcome

Thanks


You received this message because you are subscribed to the
Google Groups “ats-lang-users” group.
To unsubscribe from this group and stop receiving emails from it,
send an email to ats-lang...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/2c3bcbb2-ca
d6-46da-956c-b0da4c129450%40googlegroups.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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/CAAZxu4zZHW
YAW2AD8sU6VVdsQ7Fk%3DGbG81JdpMV5ZYPzYurAsg%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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/57f1a0bb-f0
ba-4a06-95b3-15f988245530%40googlegroups.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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/
msgid/ats-lang-users/3b808393-f696-4513-b065-f978e68e751b%
40googlegroups.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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/58c3c8d5-3127-4979-bd72-728e60714c4d%40googlegroups.com
.

You are right, I was just curious to get a better idea of what was
happening (if it existed).

I’m not really sure why what you are doing doesn’t typecheck, but here is a
version that does:

#include “share/atspre_define.hats”
#include “share/atspre_staload.hats”

staload “prelude/basics_sta.sats”
staload UN = “prelude/SATS/unsafe.sats”

extern
fun
vector_make_ngc{n:int}{l:addr} (!bytes(n) @ l | ptr (l)): void

implement main0 () = {
var mybytes = @[byte]100 // statically allocated stack memory of 100
bytes

val (pf2, fpf2 | p2) = $UN.ptr0_vtake{bytes(100)}(addr@mybytes)
val () = vector_make_ngc (pf2 | p2)
prval() = fpf2(pf2)

}On Tuesday, February 18, 2014 8:58:28 AM UTC-5, chotu s wrote:

I don’t think I need a implementation of vector_make_ngc to compile the
code , I only want it to type check , but correct me if I am wrong.

On Tue, Feb 18, 2014 at 7:24 PM, Brandon Barker <brand...@gmail.com<javascript:> wrote:

Where is the implementation for vector_make_ngc?

Brandon Barker
brand...@gmail.com <javascript:>

On Tue, Feb 18, 2014 at 8:43 AM, chotu s <cho...@gmail.com <javascript:> wrote:

I can’t seem to compile example :

#include “share/atspre_define.hats”
#include “share/atspre_staload.hats”

extern
fun
vector_make_ngc{n:int}{l:addr} (bytes(n) @ l | ptr (l)): void

implement main0 () = {
var bytes = @[byte]100 // statically allocated stack memory of 100
bytes
val () = vector_make_ngc (view@bytes | addr@bytes)
}

On Sat, Feb 15, 2014 at 8:27 PM, gmhwxi <gmh...@gmail.com <javascript:>>wrote:

implement main0 () = {
var bytes = @[char]100

}

On Saturday, February 15, 2014 5:23:51 AM UTC-5, chotu s wrote:

I can’t seem to compile the code for :

#include “share/atspre_define.hats”
#include “share/atspre_staload.hats”
staload UN = “prelude/SATS/unsafe.sats”

implement main0 () = {
var bytes = @100
}

Or did you meant :

var bytes = @[byte][100]

On Fri, Feb 14, 2014 at 9:48 PM, gmhwxi gmh...@gmail.com wrote:

You are welcome.

A good design should decouple the issue of memory allocation
and object initialization:

extern
fun vector_make_ngc{n:int}{l:addr} (bytes(n) @ l | ptr (l)): vector

var bytes = @100 // statically allocated stack memory of 100 bytes
val vector = vector_make_ngc (view@bytes | addr@bytes)

Take a look at:

http://www.ats-lang.org/LIBRARY/libats/qlist.html

The functions qstruct_objectify and qstruct_unobjectify may shed some
light on this.

On Friday, February 14, 2014 10:56:05 AM UTC-5, chotu s wrote:

Thanks a “lot” guys , I’ll read all the suggestions and links
tomorrow(as it is late here) and will ask related question after that.

Regarding stack allocation , what I had in mind was small size and
temporary arrays whose size is known at compile time , some thing like val
v = make_local_vector_n(n) , where n is known at compile time.

I think stack allocation idea came to me from the udacity parallel
programming competition where allocating main memory on gpu was costly(if I
remember correctly) , but they had different types of memory layer so one
can also use the fast shared memory whose capacity ranged from 64K to
256K(subject to correction).

Thanks for great suggestions.

On Fri, Feb 14, 2014 at 8:50 PM, gmhwxi gmh...@gmail.com wrote:

Actually, most people do not realize that a real danger with alloca
is that tail-recursion,
which should be done in constant space, may easily cause
stack-overflow when it is coupled
with stack-allocation. The issue is very similar to inlining a
function that calls alloca.

On Friday, February 14, 2014 10:09:12 AM UTC-5, Brandon Barker wrote:

Thanks, also here’s some related discussion
c - Why is the use of alloca() not considered good practice? - Stack Overflow
-considered-good-practice.
On Feb 14, 2014 9:43 AM, “gmhwxi” gmh...@gmail.com wrote:

You can use alloca to allocate memory on stack at run-time.
Here is an example I did:

https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAM
PLE/ATS-QA-LIST/alloca.dats

On Friday, February 14, 2014 8:23:49 AM UTC-5, Brandon Barker wrote:

For stack allocation my impression is that you allocate it as a
tuple:
See this page and the next page:
http://www.ats-lang.org/DOCUMENT/INTPROGINATS/HTML/x273.html

I don’t know how to write a function to allocate a tuple of
arbitrary size, however.

Brandon Barker
brand...@gmail.com

On Fri, Feb 14, 2014 at 2:16 AM, chotu s cho...@gmail.comwrote:

Thanks I’ll take a look soon.

On Fri, Feb 14, 2014 at 11:27 AM, gmhwxi gmh...@gmail.comwrote:

Here is an interface for vectors:

http://www.ats-lang.org/LIBRARY/libats/gvector.html

On Friday, February 14, 2014 12:52:16 AM UTC-5, gmhwxi wrote:

In general, if the index n occurs in the type vector(a, n),
then the size (of the type int(n)) should not be
stored inside a vector (of the type vector(a, n)). A big
point in having dependent types is to allow a vector
and its size information to be stored separately.

On Friday, February 14, 2014 12:39:37 AM UTC-5, gmhwxi wrote:

When you say ‘allocate the vector on a stack’, do you mean
allocating
the arrayptr on stack?

On Thursday, February 13, 2014 11:20:33 PM UTC-5, chotu s wrote:

For review purpose I have written a very tiny code for
vectors in ats. If anyone can quickly go through it (whenever they get free
time) and comment on the points below will be great. I have tried the code
to be similar to examples given in “Effective ATS” .

Code is given here : Vectorshttps://bitbucket.org/chotu/ats-explore/src/534b279028e38488265860a5cac81820381c272d/lainats/vector.dats?at=master

  1. I want to know how to allocate the vector on a stack
    instead on a heap

  2. I want to know is vector_add function ok ?

  3. Is this how one would go about programming in ATS2

Any further comment is also welcome

Thanks


You received this message because you are subscribed to the
Google Groups “ats-lang-users” group.
To unsubscribe from this group and stop receiving emails from
it, send an email to ats-lang...@googlegroups.com.
To post to this group, send email to ats-lan…@googlegroups.
com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/2c3bcbb2-ca
d6-46da-956c-b0da4c129450%40googlegroups.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...@googlegroups.com.
To post to this group, send email to ats-lan…@googlegroups.
com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/CAAZxu4zZHW
YAW2AD8sU6VVdsQ7Fk%3DGbG81JdpMV5ZYPzYurAsg%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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/57f1a0bb-f0
ba-4a06-95b3-15f988245530%40googlegroups.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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/
msgid/ats-lang-users/3b808393-f696-4513-b065-f978e68e751b%
40googlegroups.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...@googlegroups.com <javascript:>.
To post to this group, send email to ats-l...@googlegroups.com<javascript:>
.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/58c3c8d5-3127-4979-bd72-728e60714c4d%40googlegroups.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...@googlegroups.com <javascript:>.
To post to this group, send email to ats-l...@googlegroups.com<javascript:>
.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/CAAZxu4xy1fbQVOEusuYegR4_oirETTL6k-9JRxGCrYKpUvF9VA%40mail.gmail.com
.

Also:

  1. I don’t think you need the first staload I had
  2. If you replace the identifier ‘mybytes’ with ‘bytes’ you will run in to
    trouble.On Tuesday, February 18, 2014 9:47:15 AM UTC-5, Brandon Barker wrote:

You are right, I was just curious to get a better idea of what was
happening (if it existed).

I’m not really sure why what you are doing doesn’t typecheck, but here is
a version that does:

#include “share/atspre_define.hats”
#include “share/atspre_staload.hats”

staload “prelude/basics_sta.sats”
staload UN = “prelude/SATS/unsafe.sats”

extern
fun
vector_make_ngc{n:int}{l:addr} (!bytes(n) @ l | ptr (l)): void

implement main0 () = {
var mybytes = @[byte]100 // statically allocated stack memory of 100
bytes

val (pf2, fpf2 | p2) = $UN.ptr0_vtake{bytes(100)}(addr@mybytes)
val () = vector_make_ngc (pf2 | p2)
prval() = fpf2(pf2)

}

On Tuesday, February 18, 2014 8:58:28 AM UTC-5, chotu s wrote:

I don’t think I need a implementation of vector_make_ngc to compile the
code , I only want it to type check , but correct me if I am wrong.

On Tue, Feb 18, 2014 at 7:24 PM, Brandon Barker brand...@gmail.comwrote:

Where is the implementation for vector_make_ngc?

Brandon Barker
brand...@gmail.com

On Tue, Feb 18, 2014 at 8:43 AM, chotu s cho...@gmail.com wrote:

I can’t seem to compile example :

#include “share/atspre_define.hats”
#include “share/atspre_staload.hats”

extern
fun
vector_make_ngc{n:int}{l:addr} (bytes(n) @ l | ptr (l)): void

implement main0 () = {
var bytes = @[byte]100 // statically allocated stack memory of
100 bytes
val () = vector_make_ngc (view@bytes | addr@bytes)
}

On Sat, Feb 15, 2014 at 8:27 PM, gmhwxi gmh...@gmail.com wrote:

implement main0 () = {
var bytes = @[char]100

}

On Saturday, February 15, 2014 5:23:51 AM UTC-5, chotu s wrote:

I can’t seem to compile the code for :

#include “share/atspre_define.hats”
#include “share/atspre_staload.hats”
staload UN = “prelude/SATS/unsafe.sats”

implement main0 () = {
var bytes = @100
}

Or did you meant :

var bytes = @[byte][100]

On Fri, Feb 14, 2014 at 9:48 PM, gmhwxi gmh...@gmail.com wrote:

You are welcome.

A good design should decouple the issue of memory allocation
and object initialization:

extern
fun vector_make_ngc{n:int}{l:addr} (bytes(n) @ l | ptr (l)): vector

var bytes = @100 // statically allocated stack memory of 100
bytes
val vector = vector_make_ngc (view@bytes | addr@bytes)

Take a look at:

http://www.ats-lang.org/LIBRARY/libats/qlist.html

The functions qstruct_objectify and qstruct_unobjectify may shed
some light on this.

On Friday, February 14, 2014 10:56:05 AM UTC-5, chotu s wrote:

Thanks a “lot” guys , I’ll read all the suggestions and links
tomorrow(as it is late here) and will ask related question after that.

Regarding stack allocation , what I had in mind was small size and
temporary arrays whose size is known at compile time , some thing like val
v = make_local_vector_n(n) , where n is known at compile time.

I think stack allocation idea came to me from the udacity parallel
programming competition where allocating main memory on gpu was costly(if I
remember correctly) , but they had different types of memory layer so one
can also use the fast shared memory whose capacity ranged from 64K to
256K(subject to correction).

Thanks for great suggestions.

On Fri, Feb 14, 2014 at 8:50 PM, gmhwxi gmh...@gmail.com wrote:

Actually, most people do not realize that a real danger with
alloca is that tail-recursion,
which should be done in constant space, may easily cause
stack-overflow when it is coupled
with stack-allocation. The issue is very similar to inlining a
function that calls alloca.

On Friday, February 14, 2014 10:09:12 AM UTC-5, Brandon Barker wrote:

Thanks, also here’s some related discussion
c - Why is the use of alloca() not considered good practice? - Stack Overflow
-considered-good-practice.
On Feb 14, 2014 9:43 AM, “gmhwxi” gmh...@gmail.com wrote:

You can use alloca to allocate memory on stack at run-time.
Here is an example I did:

https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAM
PLE/ATS-QA-LIST/alloca.dats

On Friday, February 14, 2014 8:23:49 AM UTC-5, Brandon Barker wrote:

For stack allocation my impression is that you allocate it as a
tuple:
See this page and the next page:
http://www.ats-lang.org/DOCUMENT/INTPROGINATS/HTML/x273.html

I don’t know how to write a function to allocate a tuple of
arbitrary size, however.

Brandon Barker
brand...@gmail.com

On Fri, Feb 14, 2014 at 2:16 AM, chotu s cho...@gmail.comwrote:

Thanks I’ll take a look soon.

On Fri, Feb 14, 2014 at 11:27 AM, gmhwxi gmh...@gmail.comwrote:

Here is an interface for vectors:

http://www.ats-lang.org/LIBRARY/libats/gvector.html

On Friday, February 14, 2014 12:52:16 AM UTC-5, gmhwxi wrote:

In general, if the index n occurs in the type vector(a, n),
then the size (of the type int(n)) should not be
stored inside a vector (of the type vector(a, n)). A big
point in having dependent types is to allow a vector
and its size information to be stored separately.

On Friday, February 14, 2014 12:39:37 AM UTC-5, gmhwxi wrote:

When you say ‘allocate the vector on a stack’, do you mean
allocating
the arrayptr on stack?

On Thursday, February 13, 2014 11:20:33 PM UTC-5, chotu s wrote:

For review purpose I have written a very tiny code for
vectors in ats. If anyone can quickly go through it (whenever they get free
time) and comment on the points below will be great. I have tried the code
to be similar to examples given in “Effective ATS” .

Code is given here : Vectorshttps://bitbucket.org/chotu/ats-explore/src/534b279028e38488265860a5cac81820381c272d/lainats/vector.dats?at=master

  1. I want to know how to allocate the vector on a stack
    instead on a heap

  2. I want to know is vector_add function ok ?

  3. Is this how one would go about programming in ATS2

Any further comment is also welcome

Thanks


You received this message because you are subscribed to the
Google Groups “ats-lang-users” group.
To unsubscribe from this group and stop receiving emails from
it, send an email to ats-lang...@googlegroups.com.
To post to this group, send email to ats-lan…@googlegroups.
com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/2c3bcbb2-ca
d6-46da-956c-b0da4c129450%40googlegroups.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...@googlegroups.com.
To post to this group, send email to ats-lan…@googlegroups.
com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/CAAZxu4zZHW
YAW2AD8sU6VVdsQ7Fk%3DGbG81JdpMV5ZYPzYurAsg%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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com
.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/57f1a0bb-f0
ba-4a06-95b3-15f988245530%40googlegroups.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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/3b808393-
f696-4513-b065-f978e68e751b%40googlegroups.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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/58c3c8d5-3127-4979-bd72-728e60714c4d%40googlegroups.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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/CAAZxu4xy1fbQVOEusuYegR4_oirETTL6k-9JRxGCrYKpUvF9VA%40mail.gmail.com
.

I don’t think I need a implementation of vector_make_ngc to compile the
code , I only want it to type check , but correct me if I am wrong.On Tue, Feb 18, 2014 at 7:24 PM, Brandon Barker brandon...@gmail.comwrote:

Where is the implementation for vector_make_ngc?

Brandon Barker
brandon...@gmail.com

On Tue, Feb 18, 2014 at 8:43 AM, chotu s chot...@gmail.com wrote:

I can’t seem to compile example :

#include “share/atspre_define.hats”
#include “share/atspre_staload.hats”

extern
fun
vector_make_ngc{n:int}{l:addr} (bytes(n) @ l | ptr (l)): void

implement main0 () = {
var bytes = @[byte]100 // statically allocated stack memory of 100
bytes
val () = vector_make_ngc (view@bytes | addr@bytes)
}

On Sat, Feb 15, 2014 at 8:27 PM, gmhwxi gmh...@gmail.com wrote:

implement main0 () = {
var bytes = @[char]100

}

On Saturday, February 15, 2014 5:23:51 AM UTC-5, chotu s wrote:

I can’t seem to compile the code for :

#include “share/atspre_define.hats”
#include “share/atspre_staload.hats”
staload UN = “prelude/SATS/unsafe.sats”

implement main0 () = {
var bytes = @100
}

Or did you meant :

var bytes = @[byte][100]

On Fri, Feb 14, 2014 at 9:48 PM, gmhwxi gmh...@gmail.com wrote:

You are welcome.

A good design should decouple the issue of memory allocation
and object initialization:

extern
fun vector_make_ngc{n:int}{l:addr} (bytes(n) @ l | ptr (l)): vector

var bytes = @100 // statically allocated stack memory of 100 bytes
val vector = vector_make_ngc (view@bytes | addr@bytes)

Take a look at:

http://www.ats-lang.org/LIBRARY/libats/qlist.html

The functions qstruct_objectify and qstruct_unobjectify may shed some
light on this.

On Friday, February 14, 2014 10:56:05 AM UTC-5, chotu s wrote:

Thanks a “lot” guys , I’ll read all the suggestions and links
tomorrow(as it is late here) and will ask related question after that.

Regarding stack allocation , what I had in mind was small size and
temporary arrays whose size is known at compile time , some thing like val
v = make_local_vector_n(n) , where n is known at compile time.

I think stack allocation idea came to me from the udacity parallel
programming competition where allocating main memory on gpu was costly(if I
remember correctly) , but they had different types of memory layer so one
can also use the fast shared memory whose capacity ranged from 64K to
256K(subject to correction).

Thanks for great suggestions.

On Fri, Feb 14, 2014 at 8:50 PM, gmhwxi gmh...@gmail.com wrote:

Actually, most people do not realize that a real danger with alloca
is that tail-recursion,
which should be done in constant space, may easily cause
stack-overflow when it is coupled
with stack-allocation. The issue is very similar to inlining a
function that calls alloca.

On Friday, February 14, 2014 10:09:12 AM UTC-5, Brandon Barker wrote:

Thanks, also here’s some related discussion
c - Why is the use of alloca() not considered good practice? - Stack Overflow
-considered-good-practice.
On Feb 14, 2014 9:43 AM, “gmhwxi” gmh...@gmail.com wrote:

You can use alloca to allocate memory on stack at run-time.
Here is an example I did:

https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAM
PLE/ATS-QA-LIST/alloca.dats

On Friday, February 14, 2014 8:23:49 AM UTC-5, Brandon Barker wrote:

For stack allocation my impression is that you allocate it as a
tuple:
See this page and the next page:
http://www.ats-lang.org/DOCUMENT/INTPROGINATS/HTML/x273.html

I don’t know how to write a function to allocate a tuple of
arbitrary size, however.

Brandon Barker
brand...@gmail.com

On Fri, Feb 14, 2014 at 2:16 AM, chotu s cho...@gmail.comwrote:

Thanks I’ll take a look soon.

On Fri, Feb 14, 2014 at 11:27 AM, gmhwxi gmh...@gmail.comwrote:

Here is an interface for vectors:

http://www.ats-lang.org/LIBRARY/libats/gvector.html

On Friday, February 14, 2014 12:52:16 AM UTC-5, gmhwxi wrote:

In general, if the index n occurs in the type vector(a, n),
then the size (of the type int(n)) should not be
stored inside a vector (of the type vector(a, n)). A big point
in having dependent types is to allow a vector
and its size information to be stored separately.

On Friday, February 14, 2014 12:39:37 AM UTC-5, gmhwxi wrote:

When you say ‘allocate the vector on a stack’, do you mean
allocating
the arrayptr on stack?

On Thursday, February 13, 2014 11:20:33 PM UTC-5, chotu s wrote:

For review purpose I have written a very tiny code for
vectors in ats. If anyone can quickly go through it (whenever they get free
time) and comment on the points below will be great. I have tried the code
to be similar to examples given in “Effective ATS” .

Code is given here : Vectorshttps://bitbucket.org/chotu/ats-explore/src/534b279028e38488265860a5cac81820381c272d/lainats/vector.dats?at=master

  1. I want to know how to allocate the vector on a stack
    instead on a heap

  2. I want to know is vector_add function ok ?

  3. Is this how one would go about programming in ATS2

Any further comment is also welcome

Thanks


You received this message because you are subscribed to the
Google Groups “ats-lang-users” group.
To unsubscribe from this group and stop receiving emails from
it, send an email to ats-lang...@googlegroups.com.
To post to this group, send email to ats-lan…@googlegroups.
com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/2c3bcbb2-ca
d6-46da-956c-b0da4c129450%40googlegroups.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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com
.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/CAAZxu4zZHW
YAW2AD8sU6VVdsQ7Fk%3DGbG81JdpMV5ZYPzYurAsg%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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/57f1a0bb-f0
ba-4a06-95b3-15f988245530%40googlegroups.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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/
msgid/ats-lang-users/3b808393-f696-4513-b065-f978e68e751b%
40googlegroups.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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/58c3c8d5-3127-4979-bd72-728e60714c4d%40googlegroups.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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/CAAZxu4xy1fbQVOEusuYegR4_oirETTL6k-9JRxGCrYKpUvF9VA%40mail.gmail.com
.

In general, if the index n occurs in the type vector(a, n), then the size
(of the type int(n)) should not be
stored inside a vector (of the type vector(a, n)). A big point in having
dependent types is to allow a vector
and its size information to be stored separately.On Friday, February 14, 2014 12:39:37 AM UTC-5, gmhwxi wrote:

When you say ‘allocate the vector on a stack’, do you mean allocating
the arrayptr on stack?

On Thursday, February 13, 2014 11:20:33 PM UTC-5, chotu s wrote:

For review purpose I have written a very tiny code for vectors in ats. If
anyone can quickly go through it (whenever they get free time) and comment
on the points below will be great. I have tried the code to be similar to
examples given in “Effective ATS” .

Code is given here : Vectorshttps://bitbucket.org/chotu/ats-explore/src/534b279028e38488265860a5cac81820381c272d/lainats/vector.dats?at=master

  1. I want to know how to allocate the vector on a stack instead on a heap

  2. I want to know is vector_add function ok ?

  3. Is this how one would go about programming in ATS2

Any further comment is also welcome

Thanks

Thanks a “lot” guys , I’ll read all the suggestions and links tomorrow(as
it is late here) and will ask related question after that.

Regarding stack allocation , what I had in mind was small size and
temporary arrays whose size is known at compile time , some thing like val
v = make_local_vector_n(n) , where n is known at compile time.

I think stack allocation idea came to me from the udacity parallel
programming competition where allocating main memory on gpu was costly(if I
remember correctly) , but they had different types of memory layer so one
can also use the fast shared memory whose capacity ranged from 64K to
256K(subject to correction).

Thanks for great suggestions.On Fri, Feb 14, 2014 at 8:50 PM, gmhwxi gmh...@gmail.com wrote:

Actually, most people do not realize that a real danger with alloca is
that tail-recursion,
which should be done in constant space, may easily cause stack-overflow
when it is coupled
with stack-allocation. The issue is very similar to inlining a function
that calls alloca.

On Friday, February 14, 2014 10:09:12 AM UTC-5, Brandon Barker wrote:

Thanks, also here’s some related discussion http://stackoverflow.com/
questions/1018853/why-is-alloca-not-considered-good-practice.
On Feb 14, 2014 9:43 AM, “gmhwxi” gmh...@gmail.com wrote:

You can use alloca to allocate memory on stack at run-time.
Here is an example I did:

https://github.com/githwxi/ATS-Postiats/blob/master/doc/
EXAMPLE/ATS-QA-LIST/alloca.dats

On Friday, February 14, 2014 8:23:49 AM UTC-5, Brandon Barker wrote:

For stack allocation my impression is that you allocate it as a tuple:
See this page and the next page:
http://www.ats-lang.org/DOCUMENT/INTPROGINATS/HTML/x273.html

I don’t know how to write a function to allocate a tuple of arbitrary
size, however.

Brandon Barker
brand...@gmail.com

On Fri, Feb 14, 2014 at 2:16 AM, chotu s cho...@gmail.com wrote:

Thanks I’ll take a look soon.

On Fri, Feb 14, 2014 at 11:27 AM, gmhwxi gmh...@gmail.com wrote:

Here is an interface for vectors:

http://www.ats-lang.org/LIBRARY/libats/gvector.html

On Friday, February 14, 2014 12:52:16 AM UTC-5, gmhwxi wrote:

In general, if the index n occurs in the type vector(a, n), then the
size (of the type int(n)) should not be
stored inside a vector (of the type vector(a, n)). A big point in
having dependent types is to allow a vector
and its size information to be stored separately.

On Friday, February 14, 2014 12:39:37 AM UTC-5, gmhwxi wrote:

When you say ‘allocate the vector on a stack’, do you mean
allocating
the arrayptr on stack?

On Thursday, February 13, 2014 11:20:33 PM UTC-5, chotu s wrote:

For review purpose I have written a very tiny code for vectors in
ats. If anyone can quickly go through it (whenever they get free time) and
comment on the points below will be great. I have tried the code to be
similar to examples given in “Effective ATS” .

Code is given here : Vectorshttps://bitbucket.org/chotu/ats-explore/src/534b279028e38488265860a5cac81820381c272d/lainats/vector.dats?at=master

  1. I want to know how to allocate the vector on a stack instead
    on a heap

  2. I want to know is vector_add function ok ?

  3. Is this how one would go about programming in ATS2

Any further comment is also welcome

Thanks


You received this message because you are subscribed to the Google
Groups “ats-lang-users” group.
To unsubscribe from this group and stop receiving emails from it,
send an email to ats-lang...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/
msgid/ats-lang-users/2c3bcbb2-cad6-46da-956c-b0da4c129450%40go
oglegroups.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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/
msgid/ats-lang-users/CAAZxu4zZHWYAW2AD8sU6VVdsQ7Fk%3DGbG81JdpM
V5ZYPzYurAsg%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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/
msgid/ats-lang-users/57f1a0bb-f0ba-4a06-95b3-15f988245530%
40googlegroups.com.

Here is some code for doing stack allocation of a vector:

(* ****** ****** *)

abstype vector(l:addr, n:int)

(* ****** ****** *)

extern
fun vector_make_ngc
{l:addr}{n:int} (b0ytes(n) @ l | ptr l): vector(l, n)
extern
fun vector_unmake_ngc
{l:addr}{n:int} (vector(l, n)): (bytes(n) @ l | ptr l)

(* ****** ****** *)

implement
main0 () =
{
var mybuf = @[byte]100
val myvec = vector_make_ngc (view@mybuf | addr@mybuf)
val (pf | p) = vector_unmake_ngc (myvec)
prval () = view@mybuf := pf
}

(* ****** ****** *)On Tuesday, February 18, 2014 10:12:47 AM UTC-5, chotu s wrote:

Thanks. It compiles now. I’ll study the code.

On Tue, Feb 18, 2014 at 8:19 PM, Brandon Barker <brand...@gmail.com<javascript:> wrote:

Also:

  1. I don’t think you need the first staload I had
  2. If you replace the identifier ‘mybytes’ with ‘bytes’ you will run in
    to trouble.

On Tuesday, February 18, 2014 9:47:15 AM UTC-5, Brandon Barker wrote:

You are right, I was just curious to get a better idea of what was
happening (if it existed).

I’m not really sure why what you are doing doesn’t typecheck, but here
is a version that does:

#include “share/atspre_define.hats”
#include “share/atspre_staload.hats”

staload “prelude/basics_sta.sats”
staload UN = “prelude/SATS/unsafe.sats”

extern
fun
vector_make_ngc{n:int}{l:addr} (!bytes(n) @ l | ptr (l)): void

implement main0 () = {
var mybytes = @[byte]100 // statically allocated stack memory of
100 bytes

val (pf2, fpf2 | p2) = $UN.ptr0_vtake{bytes(100)}(addr@mybytes)
val () = vector_make_ngc (pf2 | p2)
prval() = fpf2(pf2)

}

On Tuesday, February 18, 2014 8:58:28 AM UTC-5, chotu s wrote:

I don’t think I need a implementation of vector_make_ngc to compile
the code , I only want it to type check , but correct me if I am wrong.

On Tue, Feb 18, 2014 at 7:24 PM, Brandon Barker brand...@gmail.comwrote:

Where is the implementation for vector_make_ngc?

Brandon Barker
brand...@gmail.com

On Tue, Feb 18, 2014 at 8:43 AM, chotu s cho...@gmail.com wrote:

I can’t seem to compile example :

#include “share/atspre_define.hats”
#include “share/atspre_staload.hats”

extern
fun
vector_make_ngc{n:int}{l:addr} (bytes(n) @ l | ptr (l)): void

implement main0 () = {
var bytes = @[byte]100 // statically allocated stack memory of
100 bytes
val () = vector_make_ngc (view@bytes | addr@bytes)
}

On Sat, Feb 15, 2014 at 8:27 PM, gmhwxi gmh...@gmail.com wrote:

implement main0 () = {
var bytes = @[char]100

}

On Saturday, February 15, 2014 5:23:51 AM UTC-5, chotu s wrote:

I can’t seem to compile the code for :

#include “share/atspre_define.hats”
#include “share/atspre_staload.hats”
staload UN = “prelude/SATS/unsafe.sats”

implement main0 () = {
var bytes = @100
}

Or did you meant :

var bytes = @[byte][100]

On Fri, Feb 14, 2014 at 9:48 PM, gmhwxi gmh...@gmail.com wrote:

You are welcome.

A good design should decouple the issue of memory allocation
and object initialization:

extern
fun vector_make_ngc{n:int}{l:addr} (bytes(n) @ l | ptr (l)): vector

var bytes = @100 // statically allocated stack memory of 100
bytes
val vector = vector_make_ngc (view@bytes | addr@bytes)

Take a look at:

http://www.ats-lang.org/LIBRARY/libats/qlist.html

The functions qstruct_objectify and qstruct_unobjectify may shed
some light on this.

On Friday, February 14, 2014 10:56:05 AM UTC-5, chotu s wrote:

Thanks a “lot” guys , I’ll read all the suggestions and links
tomorrow(as it is late here) and will ask related question after that.

Regarding stack allocation , what I had in mind was small size
and temporary arrays whose size is known at compile time , some thing like
val v = make_local_vector_n(n) , where n is known at compile time.

I think stack allocation idea came to me from the udacity
parallel programming competition where allocating main memory on gpu was
costly(if I remember correctly) , but they had different types of memory
layer so one can also use the fast shared memory whose capacity ranged from
64K to 256K(subject to correction).

Thanks for great suggestions.

On Fri, Feb 14, 2014 at 8:50 PM, gmhwxi gmh...@gmail.com wrote:

Actually, most people do not realize that a real danger with
alloca is that tail-recursion,
which should be done in constant space, may easily cause
stack-overflow when it is coupled
with stack-allocation. The issue is very similar to inlining a
function that calls alloca.

On Friday, February 14, 2014 10:09:12 AM UTC-5, Brandon Barker wrote:

Thanks, also here’s some related discussion
c - Why is the use of alloca() not considered good practice? - Stack Overflow
-considered-good-practice.
On Feb 14, 2014 9:43 AM, “gmhwxi” gmh...@gmail.com wrote:

You can use alloca to allocate memory on stack at run-time.
Here is an example I did:

https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAM
PLE/ATS-QA-LIST/alloca.dats

On Friday, February 14, 2014 8:23:49 AM UTC-5, Brandon Barker wrote:

For stack allocation my impression is that you allocate it as
a tuple:
See this page and the next page:
http://www.ats-lang.org/DOCUMENT/INTPROGINATS/HTML/x273.html

I don’t know how to write a function to allocate a tuple of
arbitrary size, however.

Brandon Barker
brand...@gmail.com

On Fri, Feb 14, 2014 at 2:16 AM, chotu s cho...@gmail.comwrote:

Thanks I’ll take a look soon.

On Fri, Feb 14, 2014 at 11:27 AM, gmhwxi gmh...@gmail.comwrote:

Here is an interface for vectors:

http://www.ats-lang.org/LIBRARY/libats/gvector.html

On Friday, February 14, 2014 12:52:16 AM UTC-5, gmhwxi wrote:

In general, if the index n occurs in the type vector(a,
n), then the size (of the type int(n)) should not be
stored inside a vector (of the type vector(a, n)). A big
point in having dependent types is to allow a vector
and its size information to be stored separately.

On Friday, February 14, 2014 12:39:37 AM UTC-5, gmhwxi wrote:

When you say ‘allocate the vector on a stack’, do you
mean allocating
the arrayptr on stack?

On Thursday, February 13, 2014 11:20:33 PM UTC-5, chotu s wrote:

For review purpose I have written a very tiny code for
vectors in ats. If anyone can quickly go through it (whenever they get free
time) and comment on the points below will be great. I have tried the code
to be similar to examples given in “Effective ATS” .

Code is given here : Vectorshttps://bitbucket.org/chotu/ats-explore/src/534b279028e38488265860a5cac81820381c272d/lainats/vector.dats?at=master

  1. I want to know how to allocate the vector on a stack
    instead on a heap

  2. I want to know is vector_add function ok ?

  3. Is this how one would go about programming in ATS2

Any further comment is also welcome

Thanks


You received this message because you are subscribed to the
Google Groups “ats-lang-users” group.
To unsubscribe from this group and stop receiving emails
from it, send an email to ats-lang...@googlegroups.com
.
To post to this group, send email to
ats-l...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/2c3bcbb2-
cad6-46da-956c-b0da4c129450%40googlegroups.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...@googlegroups.com.
To post to this group, send email to
ats-l...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/CAAZxu4zZHW
YAW2AD8sU6VVdsQ7Fk%3DGbG81JdpMV5ZYPzYurAsg%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...@googlegroups.com.
To post to this group, send email to ats-lan…@googlegroups.
com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/57f1a0bb-f0
ba-4a06-95b3-15f988245530%40googlegroups.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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/3b808393-f6
96-4513-b065-f978e68e751b%40googlegroups.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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/58c3c8d5-
3127-4979-bd72-728e60714c4d%40googlegroups.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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/
msgid/ats-lang-users/CAAZxu4xy1fbQVOEusuYegR4_
oirETTL6k-9JRxGCrYKpUvF9VA%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...@googlegroups.com <javascript:>.
To post to this group, send email to ats-l...@googlegroups.com<javascript:>
.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/4514da67-3db8-4b9c-92fa-590d3d3a208a%40googlegroups.com
.

Actually, most people do not realize that a real danger with alloca is that
tail-recursion,
which should be done in constant space, may easily cause stack-overflow
when it is coupled
with stack-allocation. The issue is very similar to inlining a function
that calls alloca.On Friday, February 14, 2014 10:09:12 AM UTC-5, Brandon Barker wrote:

Thanks, also here’s some related discussion
c - Why is the use of alloca() not considered good practice? - Stack Overflow.

On Feb 14, 2014 9:43 AM, “gmhwxi” <gmh...@gmail.com <javascript:>> wrote:

You can use alloca to allocate memory on stack at run-time.
Here is an example I did:

https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAMPLE/ATS-QA-LIST/alloca.dats

On Friday, February 14, 2014 8:23:49 AM UTC-5, Brandon Barker wrote:

For stack allocation my impression is that you allocate it as a tuple:
See this page and the next page:
http://www.ats-lang.org/DOCUMENT/INTPROGINATS/HTML/x273.html

I don’t know how to write a function to allocate a tuple of arbitrary
size, however.

Brandon Barker
brand...@gmail.com

On Fri, Feb 14, 2014 at 2:16 AM, chotu s cho...@gmail.com wrote:

Thanks I’ll take a look soon.

On Fri, Feb 14, 2014 at 11:27 AM, gmhwxi gmh...@gmail.com wrote:

Here is an interface for vectors:

http://www.ats-lang.org/LIBRARY/libats/gvector.html

On Friday, February 14, 2014 12:52:16 AM UTC-5, gmhwxi wrote:

In general, if the index n occurs in the type vector(a, n), then the
size (of the type int(n)) should not be
stored inside a vector (of the type vector(a, n)). A big point in
having dependent types is to allow a vector
and its size information to be stored separately.

On Friday, February 14, 2014 12:39:37 AM UTC-5, gmhwxi wrote:

When you say ‘allocate the vector on a stack’, do you mean allocating
the arrayptr on stack?

On Thursday, February 13, 2014 11:20:33 PM UTC-5, chotu s wrote:

For review purpose I have written a very tiny code for vectors in
ats. If anyone can quickly go through it (whenever they get free time) and
comment on the points below will be great. I have tried the code to be
similar to examples given in “Effective ATS” .

Code is given here : Vectorshttps://bitbucket.org/chotu/ats-explore/src/534b279028e38488265860a5cac81820381c272d/lainats/vector.dats?at=master

  1. I want to know how to allocate the vector on a stack instead on
    a heap

  2. I want to know is vector_add function ok ?

  3. Is this how one would go about programming in ATS2

Any further comment is also welcome

Thanks


You received this message because you are subscribed to the Google
Groups “ats-lang-users” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to ats-lang...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/
msgid/ats-lang-users/2c3bcbb2-cad6-46da-956c-b0da4c129450%
40googlegroups.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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/
msgid/ats-lang-users/CAAZxu4zZHWYAW2AD8sU6VVdsQ7Fk%
3DGbG81JdpMV5ZYPzYurAsg%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...@googlegroups.com <javascript:>.
To post to this group, send email to ats-l...@googlegroups.com<javascript:>
.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/57f1a0bb-f0ba-4a06-95b3-15f988245530%40googlegroups.com
.

Thanks. It compiles now. I’ll study the code.On Tue, Feb 18, 2014 at 8:19 PM, Brandon Barker brandon...@gmail.comwrote:

Also:

  1. I don’t think you need the first staload I had
  2. If you replace the identifier ‘mybytes’ with ‘bytes’ you will run in to
    trouble.

On Tuesday, February 18, 2014 9:47:15 AM UTC-5, Brandon Barker wrote:

You are right, I was just curious to get a better idea of what was
happening (if it existed).

I’m not really sure why what you are doing doesn’t typecheck, but here is
a version that does:

#include “share/atspre_define.hats”
#include “share/atspre_staload.hats”

staload “prelude/basics_sta.sats”
staload UN = “prelude/SATS/unsafe.sats”

extern
fun
vector_make_ngc{n:int}{l:addr} (!bytes(n) @ l | ptr (l)): void

implement main0 () = {
var mybytes = @[byte]100 // statically allocated stack memory of
100 bytes

val (pf2, fpf2 | p2) = $UN.ptr0_vtake{bytes(100)}(addr@mybytes)
val () = vector_make_ngc (pf2 | p2)
prval() = fpf2(pf2)

}

On Tuesday, February 18, 2014 8:58:28 AM UTC-5, chotu s wrote:

I don’t think I need a implementation of vector_make_ngc to compile the
code , I only want it to type check , but correct me if I am wrong.

On Tue, Feb 18, 2014 at 7:24 PM, Brandon Barker brand...@gmail.comwrote:

Where is the implementation for vector_make_ngc?

Brandon Barker
brand...@gmail.com

On Tue, Feb 18, 2014 at 8:43 AM, chotu s cho...@gmail.com wrote:

I can’t seem to compile example :

#include “share/atspre_define.hats”
#include “share/atspre_staload.hats”

extern
fun
vector_make_ngc{n:int}{l:addr} (bytes(n) @ l | ptr (l)): void

implement main0 () = {
var bytes = @[byte]100 // statically allocated stack memory of
100 bytes
val () = vector_make_ngc (view@bytes | addr@bytes)
}

On Sat, Feb 15, 2014 at 8:27 PM, gmhwxi gmh...@gmail.com wrote:

implement main0 () = {
var bytes = @[char]100

}

On Saturday, February 15, 2014 5:23:51 AM UTC-5, chotu s wrote:

I can’t seem to compile the code for :

#include “share/atspre_define.hats”
#include “share/atspre_staload.hats”
staload UN = “prelude/SATS/unsafe.sats”

implement main0 () = {
var bytes = @100
}

Or did you meant :

var bytes = @[byte][100]

On Fri, Feb 14, 2014 at 9:48 PM, gmhwxi gmh...@gmail.com wrote:

You are welcome.

A good design should decouple the issue of memory allocation
and object initialization:

extern
fun vector_make_ngc{n:int}{l:addr} (bytes(n) @ l | ptr (l)): vector

var bytes = @100 // statically allocated stack memory of 100
bytes
val vector = vector_make_ngc (view@bytes | addr@bytes)

Take a look at:

http://www.ats-lang.org/LIBRARY/libats/qlist.html

The functions qstruct_objectify and qstruct_unobjectify may shed
some light on this.

On Friday, February 14, 2014 10:56:05 AM UTC-5, chotu s wrote:

Thanks a “lot” guys , I’ll read all the suggestions and links
tomorrow(as it is late here) and will ask related question after that.

Regarding stack allocation , what I had in mind was small size and
temporary arrays whose size is known at compile time , some thing like val
v = make_local_vector_n(n) , where n is known at compile time.

I think stack allocation idea came to me from the udacity parallel
programming competition where allocating main memory on gpu was costly(if I
remember correctly) , but they had different types of memory layer so one
can also use the fast shared memory whose capacity ranged from 64K to
256K(subject to correction).

Thanks for great suggestions.

On Fri, Feb 14, 2014 at 8:50 PM, gmhwxi gmh...@gmail.com wrote:

Actually, most people do not realize that a real danger with
alloca is that tail-recursion,
which should be done in constant space, may easily cause
stack-overflow when it is coupled
with stack-allocation. The issue is very similar to inlining a
function that calls alloca.

On Friday, February 14, 2014 10:09:12 AM UTC-5, Brandon Barker wrote:

Thanks, also here’s some related discussion
c - Why is the use of alloca() not considered good practice? - Stack Overflow
-considered-good-practice.
On Feb 14, 2014 9:43 AM, “gmhwxi” gmh...@gmail.com wrote:

You can use alloca to allocate memory on stack at run-time.
Here is an example I did:

https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAM
PLE/ATS-QA-LIST/alloca.dats

On Friday, February 14, 2014 8:23:49 AM UTC-5, Brandon Barker wrote:

For stack allocation my impression is that you allocate it as
a tuple:
See this page and the next page:
http://www.ats-lang.org/DOCUMENT/INTPROGINATS/HTML/x273.html

I don’t know how to write a function to allocate a tuple of
arbitrary size, however.

Brandon Barker
brand...@gmail.com

On Fri, Feb 14, 2014 at 2:16 AM, chotu s cho...@gmail.comwrote:

Thanks I’ll take a look soon.

On Fri, Feb 14, 2014 at 11:27 AM, gmhwxi gmh...@gmail.comwrote:

Here is an interface for vectors:

http://www.ats-lang.org/LIBRARY/libats/gvector.html

On Friday, February 14, 2014 12:52:16 AM UTC-5, gmhwxi wrote:

In general, if the index n occurs in the type vector(a, n),
then the size (of the type int(n)) should not be
stored inside a vector (of the type vector(a, n)). A big
point in having dependent types is to allow a vector
and its size information to be stored separately.

On Friday, February 14, 2014 12:39:37 AM UTC-5, gmhwxi wrote:

When you say ‘allocate the vector on a stack’, do you mean
allocating
the arrayptr on stack?

On Thursday, February 13, 2014 11:20:33 PM UTC-5, chotu s wrote:

For review purpose I have written a very tiny code for
vectors in ats. If anyone can quickly go through it (whenever they get free
time) and comment on the points below will be great. I have tried the code
to be similar to examples given in “Effective ATS” .

Code is given here : Vectorshttps://bitbucket.org/chotu/ats-explore/src/534b279028e38488265860a5cac81820381c272d/lainats/vector.dats?at=master

  1. I want to know how to allocate the vector on a stack
    instead on a heap

  2. I want to know is vector_add function ok ?

  3. Is this how one would go about programming in ATS2

Any further comment is also welcome

Thanks


You received this message because you are subscribed to the
Google Groups “ats-lang-users” group.
To unsubscribe from this group and stop receiving emails
from it, send an email to ats-lang...@googlegroups.com.
To post to this group, send email to
ats-l...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/2c3bcbb2-ca
d6-46da-956c-b0da4c129450%40googlegroups.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...@googlegroups.com.
To post to this group, send email to ats-lan…@googlegroups.
com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/CAAZxu4zZHW
YAW2AD8sU6VVdsQ7Fk%3DGbG81JdpMV5ZYPzYurAsg%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...@googlegroups.com.
To post to this group, send email to ats-lan…@googlegroups.
com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/57f1a0bb-f0
ba-4a06-95b3-15f988245530%40googlegroups.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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/3b808393-f6
96-4513-b065-f978e68e751b%40googlegroups.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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/
msgid/ats-lang-users/58c3c8d5-3127-4979-bd72-728e60714c4d%
40googlegroups.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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/
msgid/ats-lang-users/CAAZxu4xy1fbQVOEusuYegR4_
oirETTL6k-9JRxGCrYKpUvF9VA%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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/4514da67-3db8-4b9c-92fa-590d3d3a208a%40googlegroups.com
.

So how do I determine the number of elements in arrayptr array.

One way I think I could determine the total size in bytes of an array and
then divide size of individual type , but how do I do this ?
Or you are asking to pass “n” the size of vector to functions that need it.

ThanksOn Fri, Feb 14, 2014 at 11:22 AM, gmhwxi gmh...@gmail.com wrote:

In general, if the index n occurs in the type vector(a, n), then the size
(of the type int(n)) should not be
stored inside a vector (of the type vector(a, n)). A big point in having
dependent types is to allow a vector
and its size information to be stored separately.

On Friday, February 14, 2014 12:39:37 AM UTC-5, gmhwxi wrote:

When you say ‘allocate the vector on a stack’, do you mean allocating
the arrayptr on stack?

On Thursday, February 13, 2014 11:20:33 PM UTC-5, chotu s wrote:

For review purpose I have written a very tiny code for vectors in ats.
If anyone can quickly go through it (whenever they get free time) and
comment on the points below will be great. I have tried the code to be
similar to examples given in “Effective ATS” .

Code is given here : Vectorshttps://bitbucket.org/chotu/ats-explore/src/534b279028e38488265860a5cac81820381c272d/lainats/vector.dats?at=master

  1. I want to know how to allocate the vector on a stack instead on a
    heap

  2. I want to know is vector_add function ok ?

  3. Is this how one would go about programming in ATS2

Any further comment is also welcome

Thanks


You received this message because you are subscribed to the Google Groups
“ats-lang-users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/a2e3bd7e-44d5-4c25-a9a7-e6acfb2b07f0%40googlegroups.com
.

Thanks for reply.

I meant something as given here :

https://groups.google.com/forum/#!searchin/ats-lang-users/stack/ats-lang-users/IsCGSd6aZHw/EVS5gXxbL-cJ

That is I have abstract type vector and when I create a vector the amount
of space need to store its content is taken from stack instead of heap. I
want something like this :

val vect = make_local_vector_of_size_n (n)

I assume that this will be again implementation dependent right ?On Fri, Feb 14, 2014 at 11:09 AM, gmhwxi gmh...@gmail.com wrote:

When you say ‘allocate the vector on a stack’, do you mean allocating
the arrayptr on stack?

On Thursday, February 13, 2014 11:20:33 PM UTC-5, chotu s wrote:

For review purpose I have written a very tiny code for vectors in ats. If
anyone can quickly go through it (whenever they get free time) and comment
on the points below will be great. I have tried the code to be similar to
examples given in “Effective ATS” .

Code is given here : Vectorshttps://bitbucket.org/chotu/ats-explore/src/534b279028e38488265860a5cac81820381c272d/lainats/vector.dats?at=master

  1. I want to know how to allocate the vector on a stack instead on a heap

  2. I want to know is vector_add function ok ?

  3. Is this how one would go about programming in ATS2

Any further comment is also welcome

Thanks


You received this message because you are subscribed to the Google Groups
“ats-lang-users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/231c5688-dbf7-42d7-bb3e-27c04eb6868c%40googlegroups.com
.