Visualizing program construction

This is a continuation of a previous thread:
https://groups.google.com/forum/#!topic/ats-lang-users/o0qri15Oi5c The
thread title there is no longer relevant so I decided to switch to a new
thread.

Xiwei,

The reason I asked so many questions is that I have been having trouble
envisioning how a large program in which ATS may be a part of should be
structured. Maybe it is better to ask a more concrete question relevant to
ATS. Suppose we want to modularize ATS compiler infrastructure. Suppose
firstly we want to create a library that anyone can use to produce ATS
abstract syntax tree (AST of ATS :slight_smile: Because this will be a library that may
be used in long running applications, say a future REPL facility for ATS,
so a) GC dependency is not allowed (so anyone can use the library) and b)
leaking memory is not allowed (so long running applications can use it).
How would you go about structure the code base?

Haitao

Sorry about the misspelling of your first name!On Thursday, February 27, 2014 4:27:19 PM UTC-8, H Zhang wrote:

This is a continuation of a previous thread:
Redirecting to Google Groups The
thread title there is no longer relevant so I decided to switch to a new
thread.

Xiwei,

The reason I asked so many questions is that I have been having trouble
envisioning how a large program in which ATS may be a part of should be
structured. Maybe it is better to ask a more concrete question relevant to
ATS. Suppose we want to modularize ATS compiler infrastructure. Suppose
firstly we want to create a library that anyone can use to produce ATS
abstract syntax tree (AST of ATS :slight_smile: Because this will be a library that may
be used in long running applications, say a future REPL facility for ATS,
so a) GC dependency is not allowed (so anyone can use the library) and b)
leaking memory is not allowed (so long running applications can use it).
How would you go about structure the code base?

Haitao

Thanks the example helped me to see how a program can be structured. So
free_* are called manually?

Does this (in eval_exp) cause memory to be freed, or do these merely
consume the proof:

prval () = fpf (pf)

(pf | fpf) seems to ultimately come from UN.ptr_vtake, which is in turn:

//
// HX: only if you know what you are doing …
//
symintr ptr_vtake

castfn ptr0_vtake
{a:vt0p} (ptr):<> [l:addr] (a@l, a@l -<lin,prf> void | ptr l)
overload ptr_vtake with ptr0_vtake of 0

castfn ptr1_vtake
{a:vt0p}{l:addr} (ptr l):<> (a@l, a@l -<lin,prf> void | ptr l)
overload ptr_vtake with ptr1_vtake of 10

HaitaoOn Saturday, March 1, 2014 8:55:15 AM UTC-8, gmhwxi wrote:

In general, there are two styles.

If the abstract syntax tree is a genuine tree (that is, no sharing of
nodes), you can
can form a dataviewtype for such a tree. There are plenty examples like
this ATSLIB
(for instance, linmap_avltree).

If the abstract syntax tree needs to support sharing of codes, then you
probably want
to use reference-counted nodes. I did an example to illustrate this idea:

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

Abstract syntax trees are often not given linear types because there is
rarely a genuine need for
doing so. However, it make sense to use linear types for internally
generated trees. What is really
great about ATS is that you can start with non-linear types to get an
functioning implementation and
then rely on typechecking to guide you when you want to replace non-linear
types with linear types.

Unless you are already quite familiar with ATS, I would not suggest that
you start with linear datatypes.

On Saturday, March 1, 2014 12:38:35 AM UTC-5, H Zhang wrote:

To narrow the question even further, take the interface defined in
src/pats_hidynexp.sats (or a similar file) as an example. If one were to
use linear types what would the interface look like? Would the
implementation and instantiation of the types involved significantly change?

Haitao

On Thursday, February 27, 2014 4:27:19 PM UTC-8, H Zhang wrote:

This is a continuation of a previous thread:
Redirecting to Google Groups The
thread title there is no longer relevant so I decided to switch to a new
thread.

Hongwei,

The reason I asked so many questions is that I have been having trouble
envisioning how a large program in which ATS may be a part of should be
structured. Maybe it is better to ask a more concrete question relevant to
ATS. Suppose we want to modularize ATS compiler infrastructure. Suppose
firstly we want to create a library that anyone can use to produce ATS
abstract syntax tree (AST of ATS :slight_smile: Because this will be a library that may
be used in long running applications, say a future REPL facility for ATS,
so a) GC dependency is not allowed (so anyone can use the library) and b)
leaking memory is not allowed (so long running applications can use it).
How would you go about structure the code base?

Haitao

Hello Haitao,

To narrow the question even further, take the interface defined in
src/pats_hidynexp.sats (or a similar file) as an example. If one were to
use linear types what would the interface look like? Would the
implementation and instantiation of the types involved significantly change?

I think if hypat_node/hipat would be changed to dataviewtypes, that would
complicate their use (e.g., dealing with sharing would necessitate wrapping
of hypat_node into a reference-counted cell, e.g. see libats/refcount).
However, it seems like a mostly straightforward transformation to me.

Please see an example in ATS1https://github.com/githwxi/ATS-Lang/blob/master/utils/atslex/EXAMPLE/calc_r.lats.
Note that parsing/lexing is somewhat easy to handle with dataviewtypes
since there is no sharing between subtrees.

In general, there are two styles.

If the abstract syntax tree is a genuine tree (that is, no sharing of
nodes), you can
can form a dataviewtype for such a tree. There are plenty examples like
this ATSLIB
(for instance, linmap_avltree).

If the abstract syntax tree needs to support sharing of codes, then you
probably want
to use reference-counted nodes. I did an example to illustrate this idea:

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

Abstract syntax trees are often not given linear types because there is
rarely a genuine need for
doing so. However, it make sense to use linear types for internally
generated trees. What is really
great about ATS is that you can start with non-linear types to get an
functioning implementation and
then rely on typechecking to guide you when you want to replace non-linear
types with linear types.

Unless you are already quite familiar with ATS, I would not suggest that
you start with linear datatypes.On Saturday, March 1, 2014 12:38:35 AM UTC-5, H Zhang wrote:

To narrow the question even further, take the interface defined in
src/pats_hidynexp.sats (or a similar file) as an example. If one were to
use linear types what would the interface look like? Would the
implementation and instantiation of the types involved significantly change?

Haitao

On Thursday, February 27, 2014 4:27:19 PM UTC-8, H Zhang wrote:

This is a continuation of a previous thread:
Redirecting to Google Groups The
thread title there is no longer relevant so I decided to switch to a new
thread.

Hongwei,

The reason I asked so many questions is that I have been having trouble
envisioning how a large program in which ATS may be a part of should be
structured. Maybe it is better to ask a more concrete question relevant to
ATS. Suppose we want to modularize ATS compiler infrastructure. Suppose
firstly we want to create a library that anyone can use to produce ATS
abstract syntax tree (AST of ATS :slight_smile: Because this will be a library that may
be used in long running applications, say a future REPL facility for ATS,
so a) GC dependency is not allowed (so anyone can use the library) and b)
leaking memory is not allowed (so long running applications can use it).
How would you go about structure the code base?

Haitao

The link should now be:

https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAMPLE/ATS-QA-LIST/calc_refcnt.datsOn Saturday, March 1, 2014 11:55:15 AM UTC-5, gmhwxi wrote:

In general, there are two styles.

If the abstract syntax tree is a genuine tree (that is, no sharing of
nodes), you can
can form a dataviewtype for such a tree. There are plenty examples like
this ATSLIB
(for instance, linmap_avltree).

If the abstract syntax tree needs to support sharing of codes, then you
probably want
to use reference-counted nodes. I did an example to illustrate this idea:

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

Abstract syntax trees are often not given linear types because there is
rarely a genuine need for
doing so. However, it make sense to use linear types for internally
generated trees. What is really
great about ATS is that you can start with non-linear types to get an
functioning implementation and
then rely on typechecking to guide you when you want to replace non-linear
types with linear types.

Unless you are already quite familiar with ATS, I would not suggest that
you start with linear datatypes.

On Saturday, March 1, 2014 12:38:35 AM UTC-5, H Zhang wrote:

To narrow the question even further, take the interface defined in
src/pats_hidynexp.sats (or a similar file) as an example. If one were to
use linear types what would the interface look like? Would the
implementation and instantiation of the types involved significantly change?

Haitao

On Thursday, February 27, 2014 4:27:19 PM UTC-8, H Zhang wrote:

This is a continuation of a previous thread:
Redirecting to Google Groups The
thread title there is no longer relevant so I decided to switch to a new
thread.

Hongwei,

The reason I asked so many questions is that I have been having trouble
envisioning how a large program in which ATS may be a part of should be
structured. Maybe it is better to ask a more concrete question relevant to
ATS. Suppose we want to modularize ATS compiler infrastructure. Suppose
firstly we want to create a library that anyone can use to produce ATS
abstract syntax tree (AST of ATS :slight_smile: Because this will be a library that may
be used in long running applications, say a future REPL facility for ATS,
so a) GC dependency is not allowed (so anyone can use the library) and b)
leaking memory is not allowed (so long running applications can use it).
How would you go about structure the code base?

Haitao

Yes, ‘free’ needs to be called manually.

The following is a line of proof:

prval () = fpf (pf)

It is merely for proof management. There is no run-time action associated
with it.On Sunday, March 2, 2014 12:41:37 AM UTC-5, H Zhang wrote:

Thanks the example helped me to see how a program can be structured. So
free_* are called manually?

Does this (in eval_exp) cause memory to be freed, or do these merely
consume the proof:

prval () = fpf (pf)

(pf | fpf) seems to ultimately come from UN.ptr_vtake, which is in turn:

//
// HX: only if you know what you are doing …
//
symintr ptr_vtake

castfn ptr0_vtake
{a:vt0p} (ptr):<> [l:addr] (a@l, a@l -<lin,prf> void | ptr l)
overload ptr_vtake with ptr0_vtake of 0

castfn ptr1_vtake
{a:vt0p}{l:addr} (ptr l):<> (a@l, a@l -<lin,prf> void | ptr l)
overload ptr_vtake with ptr1_vtake of 10

Haitao

On Saturday, March 1, 2014 8:55:15 AM UTC-8, gmhwxi wrote:

In general, there are two styles.

If the abstract syntax tree is a genuine tree (that is, no sharing of
nodes), you can
can form a dataviewtype for such a tree. There are plenty examples like
this ATSLIB
(for instance, linmap_avltree).

If the abstract syntax tree needs to support sharing of codes, then you
probably want
to use reference-counted nodes. I did an example to illustrate this idea:

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

Abstract syntax trees are often not given linear types because there is
rarely a genuine need for
doing so. However, it make sense to use linear types for internally
generated trees. What is really
great about ATS is that you can start with non-linear types to get an
functioning implementation and
then rely on typechecking to guide you when you want to replace
non-linear types with linear types.

Unless you are already quite familiar with ATS, I would not suggest that
you start with linear datatypes.

On Saturday, March 1, 2014 12:38:35 AM UTC-5, H Zhang wrote:

To narrow the question even further, take the interface defined in
src/pats_hidynexp.sats (or a similar file) as an example. If one were to
use linear types what would the interface look like? Would the
implementation and instantiation of the types involved significantly change?

Haitao

On Thursday, February 27, 2014 4:27:19 PM UTC-8, H Zhang wrote:

This is a continuation of a previous thread:
Redirecting to Google Groups The
thread title there is no longer relevant so I decided to switch to a new
thread.

Hongwei,

The reason I asked so many questions is that I have been having trouble
envisioning how a large program in which ATS may be a part of should be
structured. Maybe it is better to ask a more concrete question relevant to
ATS. Suppose we want to modularize ATS compiler infrastructure. Suppose
firstly we want to create a library that anyone can use to produce ATS
abstract syntax tree (AST of ATS :slight_smile: Because this will be a library that may
be used in long running applications, say a future REPL facility for ATS,
so a) GC dependency is not allowed (so anyone can use the library) and b)
leaking memory is not allowed (so long running applications can use it).
How would you go about structure the code base?

Haitao

To narrow the question even further, take the interface defined in
src/pats_hidynexp.sats (or a similar file) as an example. If one were to
use linear types what would the interface look like? Would the
implementation and instantiation of the types involved significantly change?

HaitaoOn Thursday, February 27, 2014 4:27:19 PM UTC-8, H Zhang wrote:

This is a continuation of a previous thread:
Redirecting to Google Groups The
thread title there is no longer relevant so I decided to switch to a new
thread.

Hongwei,

The reason I asked so many questions is that I have been having trouble
envisioning how a large program in which ATS may be a part of should be
structured. Maybe it is better to ask a more concrete question relevant to
ATS. Suppose we want to modularize ATS compiler infrastructure. Suppose
firstly we want to create a library that anyone can use to produce ATS
abstract syntax tree (AST of ATS :slight_smile: Because this will be a library that may
be used in long running applications, say a future REPL facility for ATS,
so a) GC dependency is not allowed (so anyone can use the library) and b)
leaking memory is not allowed (so long running applications can use it).
How would you go about structure the code base?

Haitao

Thanks that was very helpful.

HaitaoOn Saturday, March 1, 2014 12:17:16 AM UTC-8, Artyom Shalkhakov wrote:

Hello Haitao,

On Saturday, March 1, 2014 11:38:35 AM UTC+6, H Zhang wrote:

To narrow the question even further, take the interface defined in
src/pats_hidynexp.sats (or a similar file) as an example. If one were to
use linear types what would the interface look like? Would the
implementation and instantiation of the types involved significantly change?

I think if hypat_node/hipat would be changed to dataviewtypes, that would
complicate their use (e.g., dealing with sharing would necessitate wrapping
of hypat_node into a reference-counted cell, e.g. see libats/refcount).
However, it seems like a mostly straightforward transformation to me.

Please see an example in ATS1https://github.com/githwxi/ATS-Lang/blob/master/utils/atslex/EXAMPLE/calc_r.lats.
Note that parsing/lexing is somewhat easy to handle with dataviewtypes
since there is no sharing between subtrees.

Haitao

On Thursday, February 27, 2014 4:27:19 PM UTC-8, H Zhang wrote:

This is a continuation of a previous thread:
Redirecting to Google Groups The
thread title there is no longer relevant so I decided to switch to a new
thread.

Hongwei,

The reason I asked so many questions is that I have been having trouble
envisioning how a large program in which ATS may be a part of should be
structured. Maybe it is better to ask a more concrete question relevant to
ATS. Suppose we want to modularize ATS compiler infrastructure. Suppose
firstly we want to create a library that anyone can use to produce ATS
abstract syntax tree (AST of ATS :slight_smile: Because this will be a library that may
be used in long running applications, say a future REPL facility for ATS,
so a) GC dependency is not allowed (so anyone can use the library) and b)
leaking memory is not allowed (so long running applications can use it).
How would you go about structure the code base?

Haitao