-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Linear Array type with unrestricted gets? #422
Comments
Wouldn't %0 introduce order of evaluation problems for the places using in place mutation? |
The order of evaluation is always clear. In the example I wrote, |
I don't see how it's clear, wouldn't something like this be allowed? -- x :: X %1
-- observe0 :: X %0 -> B
-- modify1 :: X %1 -> X
let a = observe0 x
b = observe0 x
x' = modify1 x
c = observe0 x
in (a,b,x',c) Even if let bindings were sequential (which isn't what I typically expect from Haskell code but may be a fact with strict bindings?) there's a problem if either observe0 or modify1 are lazy or if c is allowed, assuming observe reads what modify mutates |
|
That's not intuitive to me at all to both make order of evaluation relevant and have the compiler silently re-arrange uses, plus what if there is something polymorphic in multiplicity and the compiler can't dispatch on whether something is 0 or not? It seems more like a band-aid. The way I would expect %0 to work, not useless but far less broadly applicable, is that the order doesn't matter at all unless you are using seq/undefined (as in regular Haskell) and if you have these %0 operations for your type then any of your %1 operations better not modify anything they observe. |
It is perfectly intuitive. It is just exactly what would happen without linear typing. The only difference is now, it's possible to reuse memory. |
Maybe in another language (though I don't know any that would re-arrange when order matters like that) but it's not exactly what would happen in Haskell, and linear types and ST both already allow re-using memory. Is it so bad to use a linear state monad instead to enforce the order? If you use QualifiedDo or an indexed state monad you can make certain things like extracting the state more convenient. |
Yes, it is exactly what would happen in Haskell. The only difference is how the memory is handled. No monads required. |
In the example above, getting the tuple out of the result does not cause any of the mutation or observation to actually occur if observe0 or modify1 returns a lifted type (which it will since it is being placed in an ordinary haskell tuple). |
Originally posted by @aspiwack in #318 (comment)
So, how did this shake out in the end? Does linear haskell have linear Array types with nonlinear unrestricted gets? If not, I'd like to make this a feature request for this. This idea could extend to other read-only ops, allowing potentially large bodies of code to access a large object without requiring linear typing in it. I am thinking about code patterns like this:
where
State
is large,act
is not linear andmutate
is.The text was updated successfully, but these errors were encountered: