Hi all,
I'm trying to understand higher-order programming in ATS better, but I keep running into errors when my lambdas use linear resources. Here's a small example that doesn't compile:
extern fn {a,b:vt@ype} map_vt {n:nat} {e:eff} (
l: !list_vt(a, n), f: !(!a) -<cloptr,e> b
):<!wrt,e> list_vt(b, n)
fn prefix_sums {n:nat} (l: !list_vt(int, n)): list_vt(int, n) =
let
var acc: int = 0
val f = lam(x: !int): int =<cloptr,!wrt> (acc := acc + x; acc)
val result = map_vt(l, f)
val () = cloptr_free{void}($UNSAFE.castvwtp0(f))
in result end
Compiling this gives an error saying that proof search for the view at 'acc' failed.
So, my questions are:
1. Why is this failing to compile, and how can I fix it? (Ideally without threading through an 'env' view parameter to all the closures.)
2. Is there a way to avoid the UNSAFE cast?
3. Would there be a way to do it with a stack allocated closure?
Thanks!
-Mark