Skip to content

Instantly share code, notes, and snippets.

@master-q
Created September 5, 2015 21:53
Show Gist options
  • Save master-q/eef527421f32c0b7441b to your computer and use it in GitHub Desktop.
Save master-q/eef527421f32c0b7441b to your computer and use it in GitHub Desktop.
no_cast_cloptr.dats
#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