Linker errors.
One possibility is that you implemented a function correctly with the implement
keyword but forgot to declare it elsewhere.
ATS may also have trouble if it is either installed in or being used from a symbolic link to a directory. Furthermore, be sure to have ATSHOME
and ATSHOMERELOC
set correctly. For example, if ATS was compiled in the directory /home/example/ats
, then add the following lines to the file ~/.bash_profile
.
export ATSHOME=/home/example/ats export ATSHOMERELOC=ATS-0.2.9
(If you are using a different version of ATS, replace the version number 0.2.9
with the appropriate version number in the above code.)
A termination metric is missing.
If you intended to define a recursive function, add a termination metric. If you don't want to include a termination metric, you can include the function effect !ntm
.
If you intended to define a non-recursive function, change fun
to fn
.
Return type versus function type.
You may get a typecheck error that looks something like this:
error(3): mismatch of static terms (tyleq): The needed term is: S2Ecst(bar) The actual term is: S2Efun(fun; 0; 0; S2Ecst(sstream); S2Ecst(bar))
This may be occurring because the typechecker is seeing a function's (or closure's) type rather than the function's return type. To avoid this, place the function call in parentheses and you should get the return type checked instead. For instance,
// this may not work val foo = ref<bar> myFun(baz) // but this should val foo = ref<bar> (myFun(baz))
This may be useful more generally when we need to have an expression evaluated before being combined with surrounding expressions.
Raising an exception without specifying a return type.
For example:
6132(line=264, offs=44) -- 6161(line=264, offs=73): error(3): sort mismatch: the sort of [s2V(2482)] is [t@ype], but the sort of its lower bound is [viewt@ype].
6132(line=264, offs=44) -- 6161(line=264, offs=73): error(3): mismatch of static terms (tyleq):
The needed term is: S2EVar(2482)
The actual term is: S2Euni(a(6); ; S2Evar(a(6)))
Even if you don't care about the value, you can return a void as part of a sequence expression, for example
val _ = ($raise AnException; ())
Not annotating a case or if-then-else expression
In general it is necessary to annotate a case or if expression (when exactly?) with a type. Note that in ATS (but not in ATS2) macdefs do not support types, so be careful with where you try to use a macdef. You may see an error like
The needed term is: S2EVar(3152)
The actual term is: S2Ecst(foo)
where you know foo is the type that you want for the case expression. Doing something like (case x of | ... | ...): foo will fix this problem.
In ATS2, such type annotation errors can (currently - pre ATS2 release) perhaps be more difficult to understand. Here is an example:
wclines_a2_dats.c: In function âloop_18â:
wclines_a2_dats.c:792:1: warning: implicit declaration of function âHITundefâ [-Wimplicit-function-declaration]
wclines_a2_dats.c:792:1: warning: implicit declaration of function âHSEs2expâ [-Wimplicit-function-declaration]
wclines_a2_dats.c:792:1: warning: implicit declaration of function âS2EVarâ [-Wimplicit-function-declaration]
wclines_a2_dats.c:792:1: error: expected â;â before âtmp44â
wclines_a2_dats.c:835:1: error: âtmp44â undeclared (first use in this function)
wclines_a2_dats.c:835:1: note: each undeclared identifier is reported only once for each function it appears in
error(1): fixity cannot be resolved.
This seems to typically be related to syntax errors. Examples may arise from accidentally using "-" as the negation sign for numeric expression (in ATS, "~" means negative, which is distinct from the minus sign "-").
Another example would be accidentally putting a space between the colon and the function annotation. For example, it should not be:
fun foo(...): <cloref> ...
Instead, remove the offending space so you don't get the fixity error above:
fun foo(...):<cloref>
Error(ccomp): the dynamic variable [foo] is not a function argument.
You may have forgotten to denote a function as a closure if you are assuming the function inherits some variables from its scope.
Error(2): the function argument cannot be ascribed refval types.
You have likely separated the function implementation from its definition, which is fine, but the implementation cannot always contain type specification for its arguments. If you need static variables available from your definition, e.g,
extern fun foo {n:nat} (x: int n): ...
then you can do something like this in your implementation to use "n":
implement foo {n} (x) = ...
warning(3): the constraint [S2Etyleq(0; S2EVar(2531), S2EVar(2532))] cannot be translated into a form accepted by the constraint solver.
error(3): unsolved constraint: C3STRprop(main; S2Etyleq(0; S2EVar(2531), S2EVar(2532)))
You may be (implicitly) using a dependent type where you assume a non-dependent type is in use: make it explicit. For example, you may not specify a function return type explicitly, and if you assume it is returning a string, it may actually be attempting to return string(n)
, which probably won't work if you haven't made use of dependent types elsewhere. Instead, specify myfun(...): string
.
Error(3): the dynamic expression is applied but its type is [S2Eapp(S2Ecst(string_int_type); S2Eint(5))].
This appears to be something akin to a parsing error: please check to make sure you didn't leave out an infix operator or have some other syntactical error in your code.
Error(3): there is no type for the dynamic variable [foo].
You may get this if the variable foo has already been consumed, for instance, if you try to use foo more than once in a linear function.
Error(3): the dynamic variable [Foo] is required to be mutable for supporting call-by-reference.
You probably should define the variable with var
instead of val
.
Error(3): the static application needs fewer arguments.
You may be attempting to pass static arguments to a polymorphic function using template syntax instead of the correct syntax for polymorphic functions.
// incorrect val amap = linmap_make_nil<string,int> () // correct val amap = linmap_make_nil {string, int} ()
Error(3): mismatch of static terms (tyleq):
The needed term is: S2Ecst(GREXP)
The actual term is: S2Edatconptr(GRgenes; S2Evar(s(11171)))
Here is an example of right and wrong code for this in the context
of a case expression:
// incorrect | GRgenes(!s) => ($raise InvalidCase; "") // correct | GRgenes(!s) => (fold@ e0; $raise InvalidCase; "")
In this case, we forgot to fold@
a linear value. S2Edatconptr
is the hint that something involving fold@
may be needed.
Wiki: Frequently asked questions
Wiki: Home
Anonymous