So, I found the issue with my code. Here is a version of my previous code which passes type checking:
- - vtypedef pointer_in_rec(a:vt@ype) = [l:addr] @{ pointer=(a @ l, mfree_gc_v(l) | ptr l) } - vtypedef pointer_in_rec2(a:vt@ype) = [l:addr] @{ pointer=(unit_p, unit_p | ptr l) } - - fn{a:vt@ype} get_pointer_in_rec ( x: !pointer_in_rec(a) >> pointer_in_rec2(a)): a = let - val (pfat, pfgc | p) = x.pointer - val ret = !p - val () = ptr_free(pfgc, pfat | p) - in - ret - end I originally got this working with t@ype, but then I found that it also worked with vt@ype. I don't know if this makes a difference, since Artyom said that the function duplicates the value it gets by dereferencing the pointer. I should test this more in the future, but for now I've provided my working solution. Thanks, Artyom! You're awesome! :) On Monday, November 2, 2020 at 11:23:07 PM UTC-5 d4v3y_5c0n3s wrote: > Thanks for the reply, I really appreciate the help. I'll try this > suggestion out tomorrow. One question though: if I use the t@ype sort, can > I still store a vt@ype within the pointer? > > On Monday, November 2, 2020 at 3:24:09 PM UTC-5 artyom.s...@gmail.com > wrote: > >> >> 2 лист. 2020 р. о 20:40 d4v3y_5c0n3s <tmj...@gmail.com> пише: >> >> Hey, so, I'm trying to figure out how to make an accessor to a type that >> I've created in a personal project. The type resembles the following: >> >> >> - vtypedef pointer_in_rec = [a:vt@ype][l:addr] @{ pointer=(a @ l, >> mfree_gc_v(l) | ptr l) } >> >> I think that [a] should be a type parameter: >> >> vtypedef pointer_in_rec (a: t@ype) = [l:addr] (a @ l, mfree_gc_v l | ptr >> l) >> >> What I'm trying to do, is create a function which takes in the type >> "pointer_in_rec" via call-by-value, and returns the vt@ype that is stored >> at the pointer position. My current function interface for doing so is as >> follows: >> >> - fn{a:vt@ype} get_pointer_in_rec ( x: !pointer_in_rec ): a >> >> The above becomes: >> >> fun{a:t@ype} get_pointer_in_rec (x: !pointer_in_rec(a)): a >> >> The type [a] should be non-linear, since the function duplicates the >> value it gets by dereferencing the pointer. >> >> I've been experimenting for a while, and I've yet to find an example of >> this online. Please let me know if you have any questions, and I'll post >> any updates or things I discover. Thank you, I truly appreciate any help >> that can be given. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "ats-lang-users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to ats-lang-user...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/ats-lang-users/b47371b1-b316-4614-8783-9a090245eba7n%40googlegroups.com >> >> <https://groups.google.com/d/msgid/ats-lang-users/b47371b1-b316-4614-8783-9a090245eba7n%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> >> -- You received this message because you are subscribed to the Google Groups "ats-lang-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/a80e5763-ff84-4d64-84e9-170dc6a3df1fn%40googlegroups.com.