Skip to content

Frequently asked questions

rodolphito edited this page Dec 12, 2019 · 19 revisions

Why does my code typecheck but not compile?

There could be several reasons, but please note specially the one in the compiler errors article referring to share/atspre_staload.hats.

ATS library code is GPLv3, so does this mean my compiled code also must be GPLv3?**

Short answer: No.

Long answer: Think of the ATS2 compiler (ATS/Postiats) as if it were GCC.

If one uses GCC to generate object code from C source one owns, then one owns the generated object code. Then if you use ATS/Postiats to generate C code from ATS source you own, then you own the generated C code.

Longer answer:

ATSLIB is primarily used to generate C code, and the generated C code, which is owned by the author of its ATS source, can be compiled as long as the header files (that is, CATS-files) in ATS2-Postiats-include are available. Currently, ATS2-Postiats-include-0.1.1.tgz is released separately under a BSD-like license. Related to this, the preferred way to write portable ATS code should avoid using -latslib to generate executables.

Another analogy is taken from a GNU-related site:

Question: Can I use GPL-covered editors such as GNU Emacs to develop non-free programs? Can I use GPL-covered tools such as GCC to compile them? (#CanIUseGPLToolsForNF)

Answer: Yes, because the copyright on the editors and tools does not cover the code you write. Using them does not place any restrictions, legally, on the license you use for your code. Some programs copy parts of themselves into the output for technical reasons—for example, Bison copies a standard parser program into its output file. In such cases, the copied text in the output is covered by the same license that covers it in the source code. Meanwhile, the part of the output which is derived from the program's input inherits the copyright status of the input. As it happens, Bison can also be used to develop non-free programs. This is because we decided to explicitly permit the use of the Bison standard parser program in Bison output files without restriction. We made the decision because there were other tools comparable to Bison which already permitted use for non-free programs.

Where can I find information on common pitfalls? Where can I ask newbie questions about writing ATS code?

First, read one of the official tutorials. Second, these ATS programming tips may be helpful. Third, there is a Google group, ats-lang-users for asking any kind of question, no matter how trivial, including slightly off-topic or less general-interest issues. Fourth, some of the discussions on the SourceForge mailing list archive may also prove instructive. Fifth, for other community resources, see the official community page.

For information about (the sometimes opaque) ATS error messages, see error messages on this wiki.

If you are not highly practiced with functional programming, it may be best to learn some Standard ML before learning ATS. The aid of SML textbook(s) or introductory ATS notes may be helpful.

Where can I find tutorials?

See tutorials on this wiki, or the Effective ATS series (also on git). Also see the answer to the previous question.

Where can I find some code or algorithm examples?

Several examples can be found here (ATS1).

Where can I find a reference or documentation?

For ATS, there is an unofficial (and incomplete) reference available (source). ATS2 has automatically generated library documentation. See the homepage on this wiki for links to wiki pages containing further documentation.

I'm getting type errors or unsolved constraints, but everything looks right. What might I be doing wrong?

Probably many things. Dependent types involve constraints; make sure you are using the right type at every step and not accidentally mixing similar types. There are many similar types in ATS (including functions with similar types) used for dealing with slightly different situations. We recommend avoiding heavy use of dependent types when starting out in order to avoid finding yourself in a situation with unsolved constraints that is very difficult to resolve. However, if and case expressions likely need to be annotated with types in general.

If you use emacs, consider using ATS Flymake as a possible measure to avoid such problems in the first place.

For examples of what can go wrong and some solutions see the following examples.

Finally, for some guidance on understanding certain errors, see error messages on this wiki.

I have two different types being used together in the same data structure, and they typecheck! Is this a bug?

After perhaps being exposed to the rigor of dependent types, one may occasionally be surprised: but the short answer is it probably isn't a bug. Here is an example where list0 will accept multiple values, each with a distinct type, as inputs (for example, strings, floats, or ints). Here is an example with templates. The notion has to do with "subtypes", and specifically, how ATS defines subtypes. This should not be a problem in ATS2, and is one of the major reasons for ATS2.

What are dependent types?

A dependent type is a type that depends on a value. As a simple example in ATS, int (5) is a type such that all integers belonging to it are equal to 5 (so it is in fact a singleton type).

What are linear types?

Linear types make use of linear logic. The notion of linear types may be explained as viewing variables as resources that are consumed by expressions, which allows for static resource tracking. For example, if you consider the expression (a or b), you've produced a new expression but you've destroyed a and b. This is useful for dealing with memory allocation safely and efficiently, for instance. For more information, see the ATS book, the Wikipedia article on linear types, or linear types on this wiki.

Is there a Windows version of ATS?

Not for the near future, at least. However, you can install ATS on top of Cygwin using the same build instructions as for other platforms.

You can also try ATS2 using this experimental online tool, or try using a virtual machine (see building and installing ATS).

How do I define an enumerated type à la Ada?

Say you want to define an enumerated type where items are represented by non-sequential numbers: define the base type to be used, then use macdef to assign a representation value for each item. See Enumerations on ats.lang.users.

How do I quickly search/investigate the prelude library?

Near to everything with ATS, ends to rely on this library. There's an on‑line HTML page, with colourization, which help to have a look at all of its content: ATSPRE, all in one.

How to quickly build SOMETHING using ATS source code?

Sometimes, Travis-CI setting file is useful when you want a remote, standardized, build environment. Just edit the code, push the code (if you didn't edit directly on git), and let Travis do the build. Please see the Travis-CI website, if you aren't familiar with Travis-CI.

What does `mac#', 'ext#', etc mean in FFI definitions?

Example definitions might be:

extern fun fact (n: int): int = "mac#fact"
extern fun fact2 (n: int): int = "ext#fact2"
extern fun fact3 (n: int): int = "sta#fact3"
extern fun fact4 (n: int): int = "mac#"

From Interaction with C:

  • mac# indicates that the function is treated like a macro in C. The fact function above can be called without its prototype being declared first. The ATS compiler will not generate the C prototype for the function in the generated C code. It is expected that fact is usually implemented in C and probably has a prototype from an included header already.
  • ext# indicates that fact2 is a global C function and must have a prototype declared. The ATS compiler will generate this prototype in the C code. This is useful if the fact function is implemented in ATS via inline C.
  • sta# indicates that fact3 is a static C function. ATS will generate a prototype in the C code for a static C function.
  • If a name follows the # then this name will be used in the C code for the function. If no name after # exists then the name of the ATS function is used as the C name.

If a % follows the # (ie. mac#%) then the name used in the C code for the function is the ATS name prefixed by the expansion of the macro ATS_EXTERN_PREFIX. For example:

// The external C name generated for the function is `myprefix_fact5`.
#define ATS_EXTERN_PREFIX myprefix_
extern fun fact5 (n: int): int = "mac#%"
Clone this wiki locally