Sorry, I didn't get a chance to read this post until now. If you use a (linear) FILEptr to create a linear stream (of chars), then the FILEptr is "buried" inside the stream and thus it can no longer be accessed.
>>My solution was to essentially combine the view for the file pointer and the stream into a single type, and thus requiring both to be freed at once. To me, this seems to be the only type-safe solution (as the alternative you mentioned above must make use of some unsafe features). --Hongwei On Sunday, October 17, 2021 at 9:14:04 AM UTC-4 d4v3y_5c0n3s wrote: > Okay, so looking back I should have provided more details in the last > post, as it does not explain the issues I was encountering etc. I posted > it right before I went to bed, and that's why I rushed it. > Anyways, I wanted to explain how I solved my problem so that others > could learn. Basically, I was using ATS' built-in libc binding to open and > read a file. The pointer for the file was a linear type, I wasn't using > the prelude's non-linear file type. What my code did is read characters to > a 'stream_vt' with the 'getc' function until it reached the end of the > file. I also planned to have other functions that would discard parts of > the stream I didn't need so that I could turn the values I needed into > other values (AKA, typical file-parsing stuff.) The problem came when I > needed to close the file. Despite the use of linear types, freeing the > file pointer would not prevent the stream from being access due to its > laziness. My solution was to essentially combine the view for the file > pointer and the stream into a single type, and thus requiring both to be > freed at once. > Moral of the story? Linear types are amazing, one of the reasons I > love ATS, but they are *not* a silver bullet. They too are limited by > what can be statically inferred by the compiler, and effects such as lazy > values cannot be predicted by the compiler. I hope someone was able to > learn something from my post, and let me know if you have any questions. > > On Monday, October 4, 2021 at 9:17:38 PM UTC-4 d4v3y_5c0n3s wrote: > >> >> What the title says. Basically, I want to use a solution that: >> - does not require GC >> - uses the type system to prevent the user from freeing the file before >> they are done with the lazy evaluation >> - is not too inconvenient for the user to use >> Let me know if you need an example of what I'm talking about. >> > -- 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/4264b891-e9e1-403e-8e4a-ca3057ba8657n%40googlegroups.com.