Как создать карту или хеш-таблицу со значением типа данных? - PullRequest
0 голосов
/ 29 мая 2018

Мне кажется, что я уже задавал этот вопрос и получил ответ раньше, но я не могу найти эти Q & A.

Хеш-таблицы и карты, как описано в учебнике ATS2 имеют недокументированные требования.Большая проблема состоит в том, что я не могу понять эти требования, увидев ошибки, которые возникают из-за их непредоставления.

Так, например, эта строка -> карта типа данных:

#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 способом, к которому я не готов.

1 Ответ

0 голосов
/ 29 мая 2018

Вам необходимо реализовать экземпляр fprint_val для печати 'example':

implement fprint_val<example>(out, x) = ...
...