Created
September 5, 2015 21:53
-
-
Save master-q/eef527421f32c0b7441b to your computer and use it in GitHub Desktop.
no_cast_cloptr.dats
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include | |
"share/atspre_staload.hats" | |
// | |
(* ****** ****** *) | |
fun{ | |
a:t@ype}{b:vt@ype | |
} list_map_cloptr{n:int} | |
( | |
xs: list (a, n), f: !(a) -<cloptr1> b | |
) : list_vt (b, n) = | |
( | |
case+ xs of | |
| list_nil () => list_vt_nil () | |
| list_cons (x, xs) => list_vt_cons (f (x), list_map_cloptr<a><b> (xs, f)) | |
) | |
(* ****** ****** *) | |
implement | |
main0 () = | |
{ | |
// | |
val xs = | |
$list{int}(0, 1, 2, 3, 4) | |
// | |
val len = list_length (xs) | |
// | |
val f = lam (x: int): int =<cloptr1> x * len | |
val ys = | |
list_map_cloptr<int><int> (xs, f) | |
val () = cloptr_free($UNSAFE.castvwtp0{cloptr(void)}(f)) | |
// | |
val () = println! ("xs = ", xs) // xs = 0, 1, 2, 3, 4 | |
val () = println! ("ys = ", ys) // ys = 0, 5, 10, 15, 20 | |
// | |
val ((*freed*)) = list_vt_free (ys) | |
// | |
} (* end of [main0] *) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment