5

I am trying to use the funset_avltree library, but the compiler generates invalid C code. I am using ATS/Postiats version 0.2.10.

My code is fairly straightforward:

(* ast.sats *)
staload "libats/SATS/funset_avltree.sats"

datatype ast =
  | ast_var of string

fun free_vars (ast : ast) :<> set string
(* ast.dats *)
#include "share/atspre_staload.hats"
staload "./ast.sats"
staload "libats/SATS/funset_avltree.sats"
dynload "libats/DATS/funset_avltree.dats"

implement free_vars (ast : ast) : set string =
  case+ ast of
  | ast_var name => funset_sing name

The compiler output, however, is rather confusing:

ast_dats.c:359:51: warning: implicit declaration of function 'S2EVar' is invalid
      in C99 [-Wimplicit-function-declaration]
ATSINSmove(tmpret0, PMVtmpltcstmat[0](funset_sing<S2EVar(4713)>)(tmp1)) ;
                                                  ^

ast_dats.c:359:39: error: use of undeclared identifier 'funset_sing'
ATSINSmove(tmpret0, PMVtmpltcstmat[0](funset_sing<S2EVar(4713)>)(tmp1)) ;
                                      ^

ast_dats.c:359:64: error: expected expression
ATSINSmove(tmpret0, PMVtmpltcstmat[0](funset_sing<S2EVar(4713)>)(tmp1)) ;
                                                               ^

I get similar errors with funset and funset_listord. I must be missing something trivial. Do I need to include something or pass some flag to the compiler?

2 Answers2

3

the root cause is you didn't statically load AVL tree templates provided by the library.

In the error message, PMVtmpltcstmat usually indicates something is wrong with templates. It is usually the case that programmers forget to include the templates, or forget to supply template variables. You are the first case.

Please add this line,

staload _ = "libats/DATS/funset_avltree.dats"

to statically load templates, and make them available to the compiler. See an working example here, https://glot.io/snippets/eiu6f3dd2r


Besides, dynload is needed when you have "global" values that needs evaluation. In your case, you do not need to dynload the avl tree library. Also, in your own file ast.dats, there is no such global value. You can define

#define ATS_DYNLOADFLAG 0

to tell compiler not to generate dynamic loading code for ast.dats.

Steinway Wu
  • 1,288
  • 1
  • 12
  • 18
  • Hi, thank you. I didn't know you had to staload dats files with template definitions. I couldn't find this in the book "Introduction to Programming in ATS". –  Sep 27 '16 at 15:05
  • You're welcome. The template system is fairly new. I think the author is still finishing relevant chapters. – Steinway Wu Sep 27 '16 at 15:45
  • 1
    @rightfold, I visited your site. It is really nice that you keep a documentation about ATS. I just want to bring to your attention that http://discourse.ats-lang.org/c/documentation is official and is planned to include more and more user contributed documentations. And your contribution is very welcomed. Thanks. – Steinway Wu Sep 29 '16 at 16:35
0

Here is an example in ATSLIB:

https://github.com/githwxi/ATS-Postiats/blob/master/libats/ML/HATS/myfunset.hats

There is a chapter on functional sets and maps in the following book:

http://ats-lang.sourceforge.net/DOCUMENT/ATS2TUTORIAL/HTML/HTMLTOC/book1.html

It is currently Chapter 12:

http://ats-lang.sourceforge.net/DOCUMENT/ATS2TUTORIAL/HTML/HTMLTOC/c514.html

Hongwei Xi
  • 895
  • 1
  • 5
  • 10