On Wed, Nov 7, 2018 at 9:17 AM Mark Thom <
markjor...@gmail.com> wrote:
> I know that pf is a linear resource, and it needs to be consumed somehow.. how do I make it happen?
> If I don't touch v after the call to ptr_set0 (ie. if I remove the final println!), the program will compile.. which also makes
> no sense given what I think I know about linear resources in ATS.
The line that assigns the view@ to 'pf' is borrowing the view and
assigning it to 'pf'. It needs to be "given back", which both consumes
the proof (the 'pf') and restores the 'view@':
var v: int = 5
prval pf = view@(v)
val _ = ptr_set0(pf | addr@(v), 3)
prval () = view@(v) := pf
This idiom was used a lot in ATS1 and I think ATS2 made it so in some
cases it wasn't needed. After changing this I hit an issue with
overloading in println:
the symbol [print] cannot be resolved due to too many matches:
D2ITMcst(print_option) of 0
D2ITMcst(print_list_vt) of 0
This seems to be something to do with the type that ATS has assigned
to 'v' being changed after the proof usage. I cheated by using
'cast2int(v)' from unsafe.sats to get it to compile but hopefully
someone knows a better way.
--
http://bluishcoder.co.nz