4

例如,如何构造一个包含所有数字的列表:0、1、2、3、4、5、6、7、8 和 9。

4

4 回答 4

1

你可以用val xs = ($list {int} (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)).

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

于 2016-10-20T21:21:41.023 回答
0

对于 list0 值,您可以执行

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

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

val some_int_list = g0ofg1($list{int}(0, 9, 8, 7, 3, 4))
于 2017-09-28T00:09:09.643 回答
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)
于 2016-10-22T08:30:07.190 回答
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)
于 2016-10-20T22:33:44.657 回答