Superficially this sounds a lot like Rust's FnOnce. Is there a relation there?
Edit: Actually it sounds like linear functions are more about using their arguments once, internally, as opposed to themselves being called once. So perhaps not. Still would appreciate any further commentary by someone with a better grasp on things than I have.
So can you work around that requirement by just going:
if false
then <use my type>
else <do my things>
Technically it is used exactly once, but really it will never be used.. -- Using Haskell-like syntax, '-o' is linear arrow, i.e. lollipop
foo : Int -o Int -o Int
foo x y = if y < 0 then x else 0Types marked with `#[must_use]` in Rust are pretty close to linear types. But must_use is a lint rather than being integrated with the type system.
An other issue with must_use is that it just requires use not “consumption” of the value, so if, say, you print it the lint is satisfied. Meaning it’s an issue for resources you’d want to be linear e.g. resources which really should be explicitly terminated because the termination can fail.
Since linear types are a separate opt-in feature you'd probably need (as far as I understand) you'd need separate printers anyway, so you could probably "cheat" them in. Though I think the sort of structures you'd want to be linear would generally not be amenable to print-debugging anyway.
- Consuming a value of a data type exactly once means evaluating it to head normal form exactly once, discriminating on its tag any number of times, then consuming its fields exactly once
- Consuming a function exactly once means applying it and consuming its result exactly once
https://github.com/ghc-proposals/ghc-proposals/blob/master/p...
Direct support could be nice, though.
[1]: http://okmij.org/ftp/Computation/lightweight-static-guarante...
See https://www.reddit.com/r/haskell/comments/gtnayl/whats_the_s... for a recent update.