Re: error messages

54 views
Skip to first unread message

Timmy Jose

unread,
Aug 3, 2020, 10:21:51 AM8/3/20
to ats-lang-users

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

Timmy Jose

unread,
Aug 3, 2020, 10:22:57 AM8/3/20
to ats-lang-users
I meant `bool` instead of `void`.

Hongwei Xi

unread,
Aug 3, 2020, 10:43:45 AM8/3/20
to ats-lan...@googlegroups.com
There is a COMMA following 'false' that should be removed.

BTW, the syntax of ATS is heavily influenced by Standard ML.

--
You received this message because you are subscribed to the Google Groups "ats-lang-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/71b5daaa-c80b-42d6-983a-72d8ab59b0ean%40googlegroups.com.

Hongwei Xi

unread,
Aug 3, 2020, 10:57:47 AM8/3/20
to ats-lan...@googlegroups.com
By the way, an ifcase-expression should be used in place of the case-expression
in your code. Also, I would like to point out that templates are a shining feature of ATS :)

######

datatype
bstree(a:t@ype) =
| E of ()
| B of (bstree(a), a, bstree(a))

fun
{a:t@ype}
bstree_search
(
 t0: bstree(a),
 k0: a

) : bool =
case+ t0 of
| E () => false
| B (t1, k, t2) =>
  let
  val sgn =
  gcompare_val_val<a>(k0, k)
  in
  ifcase

  | sgn < 0 => bstree_search (t1, k0)
  | sgn > 0 => bstree_search (t2, k0)
  | _ (* else *) => true
  end

Timmy Jose

unread,
Aug 3, 2020, 11:31:06 AM8/3/20
to ats-lang-users
Thank you! That solved the problem indeed.

The error messages though were not very helpful here. I'm slowly building up an intuition on what might be wrong in my programs by encountering errors, but the error messages can definitely undergo a huger improvement! :-)

Timmy Jose

unread,
Aug 3, 2020, 11:35:54 AM8/3/20
to ats-lang-users
That looks very interesting!

Yes, I'm still ploughing through the basic tutorial (I plan to complete all the tutorials in order), and it's been quite enjoyable so far. And you're absolutely right, the syntax reminds me a lot of ML (I have experience with OCaml rather than ML/SML, but still!). I can't wait till I reach the dependent and linear types section.

As an aside, I saw the message about ATS3 and your explicit aims of making ATS production-ready. This is very heartening news indeed. I had given ATS a go a couple of years back, and was quickly deterred by how different it was even from other functional-oriented languages. However, I'm having a much smoother time this time around, and
hope to be able to contribute towards this effort of making ATS3 production-viable. I think it is a very unique and powerful language, and quite logical as well. I just hope that ATS3 is not that different from ATS2 ... hahaha.

Thanks for the help! :-)

Richard

unread,
Aug 3, 2020, 1:03:46 PM8/3/20
to ats-lang-users
Hi Timmy,

Here is a tool that displays the compiler error messages in a more consumable way: https://github.com/sparverius/ats-acc.

Hope it helps!

- Richard

Timmy Jose

unread,
Aug 3, 2020, 2:39:44 PM8/3/20
to ats-lang-users
Hello Richard

That looks very promising. In fact, that looks exactly like what I need right now. Thank you for sharing the tool! :-)

Cheers,

Timmy

Timmy Jose

unread,
Aug 4, 2020, 1:45:51 AM8/4/20
to ats-lang-users
Hey Richard,

I tried out the acc wrapper with my code samples, and it works very nicely indeed - the formatting is superb, and showing the actual line where the error was triggered is extremely helpful. Such a simple tool, and yet it has made life much easier! :-)

Best,

Timmy
Reply all
Reply to author
Forward
0 new messages