Skip to content

Instantly share code, notes, and snippets.

@master-q
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save master-q/e20a3832922958422287 to your computer and use it in GitHub Desktop.
Save master-q/e20a3832922958422287 to your computer and use it in GitHub Desktop.
夏のプログラミング・シンポジウム 2014 での質問
(* コンパイルNG: let valでも線形型が消費されてしまう *)
#include "share/atspre_staload.hats"
implement main0 () = {
val l1 = list_vt_make_pair<int> (1, 2)
val l2 = l1
val () = let val l3 = l2 in println! l3 end
val () = free l2
}
(*
$ patscc -DATS_MEMALLOC_LIBC -o sample_list sample_list.dats
exec(patsopt --output sample_list_dats.c --dynamic sample_list.dats)
Hello from ATS2(ATS/Postiats)!
The 1st translation (fixity) of [sample_list.dats] is successfully completed!
The 2nd translation (binding) of [sample_list.dats] is successfully completed!
/home/kiwamu/tmp/sample_list.dats: 127(line=5, offs=12) -- 161(line=5, offs=46): error(3): the linear dynamic variable [l3$3449(-1)] needs to be consumed but it is preserved with the type [S2Eapp(S2Ecst(list_vt0ype_int_vtype); S2Einvar(S2EVar(4096)), S2EVar(4097))] instead.
*)
(* コンパイルOK: valすると線形型が消費される *)
#include "share/atspre_staload.hats"
implement main0 () = {
val l1 = list_vt_make_pair<int> (1, 2)
val l2 = l1
val () = println! l2
val () = free l2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment