# Staload dats files

**URL:** <https://discourse.ats-lang.org/t/staload-dats-files/22>\
**Category:** Google Group\
**Created:** [March 20, 2016, 6:08pm UTC](https://discourse.ats-lang.org/t/staload-dats-files/22 "2016-03-20T18:08:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zhiqiang\_Ren](https://avatars.discourse-cdn.com/v4/letter/z/9fc29f/32.png) [@Zhiqiang\_Ren](https://discourse.ats-lang.org/u/Zhiqiang_Ren)\
**Post date:** [March 20, 2016, 6:08pm UTC](https://discourse.ats-lang.org/t/staload-dats-files/22/1 "2016-03-20T18:08:21Z")

</div>

Maybe this question has been asked before. If so, a link to former question  
is highly appreciated. Thanks ahead of time.

When we use template feature in ATS, we would usually use `staload _ = "xxx.dats"` to load the template definition into the current file. Let’s  
assume the following situation.

File `a1.sats` and `a1.dats` contain template code for certain  
functionality. File `a2.sats` and `a2.dats` contain template code for other  
functionality. File `b.sats` and `b.dats` contain template code, which uses  
the templates defined in a1 and a2. The main file `c.dats` uses the  
templates defined in b.

Apparently, `b.dats` must contain  
staload "a1.sats"  
staload "a2.sats"  
Q1. Is it true that if `b.dats` contains only function templates, then  
there is no need to do `staload _ = "a1.dats"` or `staload _ = "a2.dats" in`b.dats`at all? Q2. Going still further, do we need to use patscc and gcc to compile`b.sats`and`b.dats` and link the results into the final executable?

It seems that `c.dats` must contain the following  
staload \_ = "b.dats"  
staload \_ = "a1.dats"  
staload \_ = "a2.dats"  
Otherwise, we would see errors when compiling the C file generated from  
`c.dats`. (Type checking `c.dats` has no problem.)

Q3. Is it true that we need to go through the chain of dependency and  
staload all the related dats file in c.dats?  
Q4. If those function templates in `b.dats` which are used in `c.dats` only  
depend on those function templates defined in `a1.dats`, is it true that we  
can omit `staload _ = a2.dats` in `c.dats`?

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [March 20, 2016, 6:31pm UTC](https://discourse.ats-lang.org/t/staload-dats-files/22/2 "2016-03-20T18:31:33Z")

</div>

There is a basic rule you can follow to understand all of this:

Say you want compile a file foo.dats into object code. Then all the  
templates needed in foo.dats, either directly or indirectly, should be  
made accessible to the compiler (patsopt).

Answer to Q1:

There is no need  
for ‘statload \_ = ???.dats’ because you never compile b.dats.

Answer to Q2:  
No, you do not (unless you define exception constructors in b.sats or  
b.dats).

Answer to Q3: yes, you need

Answer to Q4:  
Yes, you can omit.  
Including files that are not needed is harmless; trying to get “exact”  
sets of file you need is not very meaningful in practice.On Sunday, March 20, 2016 at 2:08:22 PM UTC-4, Zhiqiang Ren wrote:

> Maybe this question has been asked before. If so, a link to former  
> question is highly appreciated. Thanks ahead of time.
> 
> When we use template feature in ATS, we would usually use `staload _ = "xxx.dats"` to load the template definition into the current file. Let’s  
> assume the following situation.
> 
> File `a1.sats` and `a1.dats` contain template code for certain  
> functionality. File `a2.sats` and `a2.dats` contain template code for other  
> functionality. File `b.sats` and `b.dats` contain template code, which uses  
> the templates defined in a1 and a2. The main file `c.dats` uses the  
> templates defined in b.
> 
> Apparently, `b.dats` must contain  
> staload “a1.sats”  
> staload “a2.sats”  
> Q1. Is it true that if `b.dats` contains only function templates, then  
> there is no need to do `staload _ = "a1.dats"` or `staload _ = "a2.dats" in `b.dats`at all? Q2. Going still further, do we need to use patscc and gcc to compile `b.sats`and`b.dats` and link the results into the final executable?
> 
> It seems that `c.dats` must contain the following  
> staload \_ = “b.dats”  
> staload \_ = “a1.dats”  
> staload \_ = “a2.dats”  
> Otherwise, we would see errors when compiling the C file generated from  
> `c.dats`. (Type checking `c.dats` has no problem.)
> 
> Q3. Is it true that we need to go through the chain of dependency and  
> staload all the related dats file in c.dats?  
> Q4. If those function templates in `b.dats` which are used in `c.dats`  
> only depend on those function templates defined in `a1.dats`, is it true  
> that we can omit `staload _ = a2.dats` in `c.dats`?
