Hacker News new | past | comments | ask | show | jobs | submit login

How does closeFile get implemented? That is, how do you consume a linear type without having to either pass it to another function or return it?

Does every linear value ultimately have to be passed to an extern function that doesn’t follow the linear typing rules?




I would assume destructuring comes into play: https://austral-lang.org/spec/spec.html#stmt-let-destructure

Whatever underlying value would be moved out of the linear record by destructuring (and thus consuming) it, then released via the underlying platform's operation (e.g. close(2), CloseHandle, ...)

edit: from the linked section, it looks like field access is a linear operation:

> when you have a linear record type, you can’t extract the value of a linear field from it, because it consumes the record as a whole, and leaves unconsumed any other linear fields in the record

so for a "newtype" (a single field wrapper type) you can just access the one field, maybe.


A linear type is an annotation on another thing to opt into semantics checking. The linear file probably has an integer file handle hidden insider it.

As long as there is interface/implementation separation, no interface that gives you the underlying handle and not enough reflection in the language to dig it out, you're solid.

Open and close must both be on the inside of the implementation so can breach the abstraction.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: