
Hello, I've written a tiny package for restricting access to mutable variables to be read-only or write-only: http://code.haskell.org/~basvandijk/code/only-read-or-write-vars/ This is a Request For Comments, so any comments / patches / +1s / -1s about anything are more than welcome before I upload it to hackage (sometime this weekend). regards, Bas

http://code.haskell.org/~basvandijk/code/only-read-or-write-vars/
This is a Request For Comments, so any comments / patches / +1s / -1s about anything are more than welcome before I upload it to hackage (sometime this weekend).
+1 - I like it, I've used this technique in some private projects I wonder if this would be a place to add a function returning the pair of the read and write capabilities (for the lack of a better word) of a value. something like: rwPair:: v α -> (ReadOnly v α , WriteOnly v α) rwPair a = (readOnly a, writeOnly a) sorry for the lame name, but my name game is off today. This particular function comes handy when playing with passing channels or pointers around. It might be worth it to have a dedicated type for that as well. Vlado

On Fri, Mar 19, 2010 at 5:49 PM, vlado
+1 - I like it, I've used this technique in some private projects
Nice, I hope you can use this package.
I wonder if this would be a place to add a function returning the pair of the read and write capabilities (for the lack of a better word) of a value.
something like:
rwPair:: v α -> (ReadOnly v α , WriteOnly v α) rwPair a = (readOnly a, writeOnly a)
sorry for the lame name, but my name game is off today.
This particular function comes handy when playing with passing channels or pointers around. It might be worth it to have a dedicated type for that as well.
What would this dedicated type look like? BTW thanks for pointing me to pointers! Of course a Ptr is also a mutable variable so I've added instances for them. Thanks, Bas

I wonder if this would be a place to add a function returning the pair of the read and write capabilities (for the lack of a better word) of a value.
something like:
rwPair:: v α -> (ReadOnly v α , WriteOnly v α) rwPair a = (readOnly a, writeOnly a)
sorry for the lame name, but my name game is off today.
This particular function comes handy when playing with passing channels or pointers around. It might be worth it to have a dedicated type for that as well.
What would this dedicated type look like?
Something along the lines of * a type alias: type ReadWrite v α = (ReadOnly v α , WriteOnly v α) * or a data type: data ReadWrite v α = ReadWrite {reader:: ReadOnly v α, writer:: WriteOnly v α } The intent is to be able to recognise the available capabilities. Then we could write a Link type, which is the sum of all four possibilities and allowing pattern matching on capabilities. This is similar to links in pi-calculus. I'm not sure if a link type should be in your library though. My gut feeling is it should be in a separate library, which implements a trusted kernel, which guarantees linearity - i.e ReadOnly and WriteOnly to be used only once - either shallow, guaranteeing that the projection can be taken only once, or deep providing guarantees for 'proper' linearity. Sorry, I digress, that is a pet subject I've been playing with on and off.
BTW thanks for pointing me to pointers! Of course a Ptr is also a mutable variable so I've added instances for them. Pleasure to be of help, even if it was by accident
Cheers, Vlado
participants (2)
-
Bas van Dijk
-
vlado