What is the syntax for constructing a list-value in ATS?

时间:2016-10-20 18:46:58

标签: ats

For instance, how can I construct a list consisting of all the digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9.

4 个答案:

答案 0 :(得分:1)

您可以使用val xs = ($list {int} (0, 1, 2, 3, 4, 5, 6, 7, 8, 9))构建它。

使用此代码时,请确保通过将-DATS_MEMALLOC_LIBC传递给编译器来指定正确的内存分配函数。

答案 1 :(得分:0)

如果您通过atscc2js编译为JavaScript,那么您需要构建 列表如下:

val ds =
  0::1::2::3::4::5::6::7::8::9::nil{int}()
// end of [val]

它也适用于定位C.

还有这类东西的组合器。例如,

val ds = (10).list_map(TYPE{int})(lam(i) => i)
val ds = list_tabulate_cloref<int>(10, lam i => i)

答案 2 :(得分:0)

您可以在emacs模式下找到特殊的文字:

https://github.com/githwxi/ATS-Postiats/blob/653af81715cf6bfbd1d2cd5ece1e88c8c3912b4a/utils/emacs/ats2-mode.el#L287

(defvar ats-special-keywords
  '("$arrpsz" "$arrptrsize" "$delay" "$ldelay" "$effmask" "$effmask_ntm" "$effmask_exn" "$effmask_ref"
    "$effmask_wrt" "$effmask_all" "$extern" "$extkind" "$extype" "$extype_struct" "$extval" "$lst"
    "$lst_t" "$lst_vt" "$list" "$list_t" "$list_vt" "$rec" "$rec_t" "$rec_vt"
    "$record" "$record_t" "$record_vt" "$tup" "$tup_t" "$tup_vt" "$tuple" "$tuple_t"
    "$tuple_vt" "$raise" "$showtype" "$myfilename" "$mylocation" "$myfunction" "#assert" "#define"
    "#elif" "#elifdef" "#elifndef" "#else" "#endif" "#error" "#if" "#ifdef"
    "#ifndef" "#print" "#then" "#undef" "#include" "#staload" "#dynload" "#require"))

如果您找到一些关键字,您可以轻松地知道如何在doc / EXAMPLE /目录中使用它:

$ git clone https://github.com/githwxi/ATS-Postiats.git
$ cd ATS-Postiats/doc/EXAMPLE
$ grep -r "\$list" . | head
./MISC/word-chain.dats:  $list{word}("", "")
./MISC/word-chain.dats:  $list{word}("", "")
./MISC/mysendmailist.dats:$list{string}
./MISC/monad_list.dats:  $list{a}("this", "that", "a")
./MISC/monad_list.dats:  $list{a}("frog", "elephant", "thing")
./MISC/monad_list.dats:  $list{a}("walked", "treaded", "grows")
./MISC/monad_list.dats:  $list{a}("slowly", "quickly")
./ATSLF/CoYonedaLemma.dats:val myintlist0 = g0ofg1($list{int0}(I(1), I(0), I(1), I(0), I(0)))
./ATSLF/YonedaLemma.dats:  $list{bool}(True, False, True, False, False)
./ATS-QA-LIST/qa-list-2014-12-07.dats:$list{double}(0.111111, 0.222222, 0.333333)

答案 3 :(得分:0)

对于list0值,你可以

val xs = g0ofg1($list{T}(x1, ..., xn))

其中T是xs中元素的类型。例如,

val some_int_list = g0ofg1($list{int}(0, 9, 8, 7, 3, 4))