Closed prakhar1989 closed 8 years ago
Usages of TAny
in type-checker -
[]
has a type TList(TAny)
.{}
has a type TMap(TAny,TAny)
.TAny
. This has been added only to satisfy the type-checker and it is unreachable since {}
is recognized by the parser as MapLit
and not a Block
.TAny
to a value which is not explicitly annotated in the program. Once the type is resolved, the environment is updated with the correct type.TAny
is used while building up a generic map in a generic function. E.g. [T, U, Z]
are all assigned to be T -> TAny
. Check the resolve
function for more details.val range = /\(start: num, end: num): list num => {
if start >= end then []
else start :: range(start+1, end);
};
val rev = /\(xs: list num): list num => {
val aux = /\(acc: list num, ys: list num): list num => {
if empty?(ys) then acc
else aux(hd(ys) :: acc, tl(ys));
};
aux([], xs);
};
The following code raises the type-checking error -
Type error: expected value of type 'list any', got a value of type 'list string' instead
Fix this by being liberal in type-checking
TAny
types.