我觉得我之前已经问过这个问题并得到了答案,但是我找不到Q& A。
ATS2 tutorial中记录的哈希表和地图具有未记录的要求。最大的问题是,我看不出那些要求,因为我们看不到因为没有提供错误而导致的错误。
所以例如这个字符串 - >数据类型映射:
#include "share/atspre_staload.hats"
#include "share/atspre_staload_libats_ML.hats"
datatype example = example of (string)
// commented: this doesn't change the error output
//fn fprint_example(out: FILEref, w: example): void = fprint!(out, "(not implemented)")
//overload fprint with fprint_example
local
typedef key = string
and itm = example
staload "libats/ML/SATS/funmap.sats"
in
#include "libats/ML/HATS/myfunmap.hats"
end
val test = myfunmap_nil()
implement main0() = ()
无法使用这些错误构建:
patscc -DATS_MEMALLOC_GCBDW -o test test.dats -latslib -lgc
test_dats.c:20972:54: warning: implicit declaration of function 'S2Ecst' is invalid in C99 [-Wimplicit-function-declaration]
ATSINSmove(tmp859__1, PMVtmpltcstmat[0](tostrptr_val<S2Ecst(example)>)(arg1)) ;
^
test_dats.c:20972:61: error: use of undeclared identifier 'example'
ATSINSmove(tmp859__1, PMVtmpltcstmat[0](tostrptr_val<S2Ecst(example)>)(arg1)) ;
^
test_dats.c:20972:41: error: use of undeclared identifier 'tostrptr_val'
ATSINSmove(tmp859__1, PMVtmpltcstmat[0](tostrptr_val<S2Ecst(example)>)(arg1)) ;
^
test_dats.c:20972:70: error: expected expression
ATSINSmove(tmp859__1, PMVtmpltcstmat[0](tostrptr_val<S2Ecst(example)>)(arg1)) ;
^
test_dats.c:20972:23: error: use of undeclared identifier 'PMVtmpltcstmat'
ATSINSmove(tmp859__1, PMVtmpltcstmat[0](tostrptr_val<S2Ecst(example)>)(arg1)) ;
^
1 warning and 4 errors generated.
make: *** [test] Error 1
所以似乎tostrptr_val<example>
未实现......
......此时,在形成这个问题的过程中,我找到了prelude / * / tostring,其中实现了这些东西。好。这让我
#include "share/atspre_staload.hats"
#include "share/atspre_staload_libats_ML.hats"
datatype example = example of (string)
fn tostrptr_example(ex: example):<!wrt> Strptr1 = $UNSAFE.castvwtp0{Strptr1}("not implemented")
fn tostring_example(ex: example):<> string = "not implemented"
fn fprint_example(out: FILEref, ex: example): void = fprint!(out, tostring_example(ex))
implement tostrptr_val<example> = tostrptr_example
implement tostring_val<example> = tostring_example
implement fprint_val<example> = fprint_example
local
typedef key = string
and itm = example
staload "libats/ML/SATS/funmap.sats"
in
#include "libats/ML/HATS/myfunmap.hats"
end
val test = myfunmap_nil()
implement main0() = ()
仍然无法编译:
patscc -DATS_MEMALLOC_GCBDW -o test test.dats -latslib -lgc
test_dats.c:20765:31: warning: implicit declaration of function 'fprint_example_5' is invalid in C99 [-Wimplicit-function-declaration]
ATSINSmove_void(tmpret822__1, fprint_example_5(env0, arg1)) ;
^
1 warning generated.
Undefined symbols for architecture x86_64:
"_fprint_example_5", referenced from:
_ATSLIB_056_libats_056_funmap_avltree__funmap_foreach__fwork__123__1 in test_dats-bd83ab.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [test] Error 1
我可以解释的是/libats/DATS/funmap_avltree.dats中的单个函数正以我未准备好的方式使用example
。
答案 0 :(得分:0)
您需要实现一个用于打印的fprint_val实例&#39;示例&#39;:
implement fprint_val<example>(out, x) = ...