
Reference is class which generalizes references and monads they exists in. It means that IORef, STRef and others can be accessed by common interface. Currently it is of form: class Reference r m where 1. There was a proposal to rename the class to MonadRef or MonadReference. IMHO it would imply m -> r functional dependency and therefore disallow the instances for both MVar IO and IORef IO 2. Should the functional dependencies or type famillies be introduced? Personally I don't think so as I would like to allow all of the following: - IORef IO - MVar IO - IORef (ContT IO) - MVar (ContT IO) Any feedback mostly welcome. Regards PS. Darcs repository will be available soon

On Mon, Sep 6, 2010 at 11:55 PM, Maciej Piechotka
Reference is class which generalizes references and monads they exists in. It means that IORef, STRef and others can be accessed by common interface.
Currently it is of form:
class Reference r m where
1. There was a proposal to rename the class to MonadRef or MonadReference. IMHO it would imply m -> r functional dependency and therefore disallow the instances for both MVar IO and IORef IO
2. Should the functional dependencies or type famillies be introduced? Personally I don't think so as I would like to allow all of the following:
- IORef IO - MVar IO - IORef (ContT IO) - MVar (ContT IO)
Any feedback mostly welcome.
Regards PS. Darcs repository will be available soon
_______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
I've played with a somewhat similar idea: darcs get http://code.haskell.org/~basvandijk/code/only-read-or-write-vars API Docs + Hyperlinked source: http://code.haskell.org/~basvandijk/code/only-read-or-write-vars/doc/html/on... This is not released (yet) because I'm unsure about the design. Especially, I'm unsure whether parameterizing Readable with α is a good idea: class Readable v m α | v → m where read ∷ v → m α and whether parameterizing Writable with α and β is a good idea: class Writable v α m β | v → m where write ∷ v → α → m β They do allow some Regards, Bas

On Tue, Sep 7, 2010 at 2:15 AM, Bas van Dijk
They do allow some
now finishing my sentence... The parameterization of α and β in Readable and Writable do allow some nice instances like: instance Readable (TMVar α) STM (Maybe α) where read = TMVar.tryTakeTMVar instance Writable (TMVar α) α STM Bool where write = TMVar.tryPutTMVar instance Writable (Chan α) (End α) IO () where write t = Chan.unGetChan t ∘ unEnd -- | Writing @End x@ to a 'Chan' or 'TChan' writes @x@ to the end of the channel -- instead of to the front. Also see 'unGetChan' and 'unGetTChan'. newtype End α = End {unEnd ∷ α} Regards, Bas

On Tue, 2010-09-07 at 02:15 +0200, Bas van Dijk wrote:
On Mon, Sep 6, 2010 at 11:55 PM, Maciej Piechotka
wrote: Reference is class which generalizes references and monads they exists in. It means that IORef, STRef and others can be accessed by common interface.
Currently it is of form:
class Reference r m where
1. There was a proposal to rename the class to MonadRef or MonadReference. IMHO it would imply m -> r functional dependency and therefore disallow the instances for both MVar IO and IORef IO
2. Should the functional dependencies or type famillies be introduced? Personally I don't think so as I would like to allow all of the following:
- IORef IO - MVar IO - IORef (ContT IO) - MVar (ContT IO)
Any feedback mostly welcome.
Regards PS. Darcs repository will be available soon
_______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
I've played with a somewhat similar idea:
darcs get http://code.haskell.org/~basvandijk/code/only-read-or-write-vars
API Docs + Hyperlinked source: http://code.haskell.org/~basvandijk/code/only-read-or-write-vars/doc/html/on...
This is not released (yet) because I'm unsure about the design.
Especially, I'm unsure whether parameterizing Readable with α is a good idea:
class Readable v m α | v → m where read v → m α
and whether parameterizing Writable with α and β is a good idea:
class Writable v α m β | v → m where write v → α → m β
They do allow some some nice instances like:
instance Readable (TMVar α) STM (Maybe α) where read = TMVar.tryTakeTMVar
instance Writable (TMVar α) α STM Bool where write = TMVar.tryPutTMVar
instance Writable (Chan α) (End α) IO () where write t = Chan.unGetChan t unEnd
-- | Writing @End x@ to a 'Chan' or 'TChan' writes @x@ to the end of
First I'd like to say sorry for error in cafe mailing list address. The whole e-mail is included above. the channel
-- instead of to the front. Also see 'unGetChan' and 'unGetTChan'. newtype End α = End {unEnd α}
Regards,
Bas
I guess they are to some extend like Foldable to FoldableLL and possibly describing different aspects. Yours seems to be a bit like StateVar[1] generalized for different monads. Support for ptr & others is additional bonus. I wanted clear 1-1 mapping with references - i.e. basic 2 operations with added third for 'atomic' support. For example one of unmentioned law is that: write r x >> read r === write r x >> return r -- If it's only thread write r x >> write r y === write r y -- If it's only thread read r >> read r === read r read r >>= write r === id -- If it's only thread read r >>= const f === f -- If it's only thread? In fact I guess each on them could be used as RULES as IMHO each case in which it is not necessary true it is undeterministic anyway. While Chan is clearly writable and readable it cannot be considered a reference - it do have it purposes but they are usually different then references. To sum up - I would not be willing to use Readable/Writable in place of Reference but I don't say they don't have their purposes. PS. I took the liberty of continuing sentence. [1] http://hackage.haskell.org/package/StateVar-1.0.0.0
participants (2)
-
Bas van Dijk
-
Maciej Piechotka