Hello,
I've been trying to learn ATS from the official tutorials, and while I like the language so far, and think that it is quite logical (if different from many other languages in the same categories), one thing that keeps annoying me is getting some strange error messages.
For instance, why is this a problem:
fun
bstree_search (
t0: bstree,
k0: string
): bool =
case+ t0 of
| E () => false,
| B (t1, k, t2) =>
let val sgn = compare (k0, k)
in case+ 0 of
| _ when sgn < 0 => bstree_search (t1, k0)
| _ when sgn > 0 => bstree_search (t2, k0)
| _ => true
end
I would expect that the return types of all sub-expressions are `void` anyway, so why does the compiler complain:
$ patscc -DATS_MEMALLOC_LIBC -o bst bst.dats && ./bst
/Users/z0ltan/dev/study/ats/introduction_to_programming_in_ats/chapter4/bst.dats: 1022(line=53, offs=22) -- 1023(line=53, offs=23): error(parsing): the token is discarded.
/Users/z0ltan/dev/study/ats/introduction_to_programming_in_ats/chapter4/bst.dats: 1096(line=56, offs=9) -- 1098(line=56, offs=11): error(parsing): the token is discarded.
exit(ATS): uncaught exception: _2home_2hwxi_2Research_2ATS_2dPostiats_2src_2pats_error_2esats__FatalErrorExn(1025)
The ATS FAQ recommends wrapping expressions with parentheses for such errors, but doing so in this case does not get rid of the errors, and secondly why is that even needed?
Right now, this is the biggest thing that keeps tripping me up - seemingly random "token discarded" error messages as well as some strange "} keyword needed" error message etc. Experimenting randomly seems to fix them most times, but is there any reason to this madness?
Can anyone give me general guidelines to avoid seeing these sort of trivial errors?
Best,
Timmy