This seems like a dangerous change to make. First, we are presuming that
no one will want to put something without Eq defined in an Ivar, which
seems really unfortunate. What if Ivars holding functions would be useful?
It also seems quite quirky in that in some cases this would be shallow
equality, but in other cases it could be deep equality that forces
computation. Would this be an issue for infinite lists? Naively trying
to check equality on a pair of infinite lists in ghci:
Prelude> let x = cycle [5,120]
Prelude> x == x
*hangs*
So it seems like requiring Eq and actually doing the check on a
double-put invalidates programs that rely on laziness in this way.
~ Aaron Todd
On 09/08/2013 03:28 PM, Simon Marlow wrote:
> Hmm, I'm not terribly keen on this. Apart from breaking the API, it
> feels like the implementation is leaking into the types. Is this really
> the only way to do it?
>
> How much code do we have that is overloaded on the Par class? It's just
> monad-par-extras, right?
>
> Cheers,
> Simon
>
> On 08/09/13 19:30, Ryan Newton wrote:
>> We're getting close to releasing our LVar library which lockfree
>> monotonic sets, maps, vectors in addition to IVars.
>>
>> The LVar implementation (termed LVish and found here
>> <
https://github.com/iu-parfunc/lvars/tree/master/haskell-prototype>)
>> is also a valid Par monad, and we should expect it to have a ParIVar
>> instance, as found here
>> <
https://github.com/iu-parfunc/lvars/blob/667b3938809cddf2aaf6da8ca1cb4650f6a1de33/haskell-prototype/Data/LVar/IVar.hs#L142>.
>>
>> There's a small hitch though. The current LVish scheduler depends on
>> the */idempotence/* of all actions in the monad, and it will repeat
>> actions with low probability. Thus we cannot make the same decision
>> we did with the first crop of monad-par schedulers -- that a second
>> put is always an error, even if you put the same value.
>>
>> But to detect a repeated put of the same value, we need an Eq
>> constraint on several operations:
>>
>> put_ :: Eq a => ivar a -> a -> m ()
>>
>>
>> *Does anyone object to adding this Eq constraint in the ParIVar class
>> (a breaking change)? *Note that this will not affect anyone that
>> imports Control.Monad.Par directly---rather than the generic
>> interface---which is probably everyone.
>> By the way, this does not inhibit storing IVars in IVars. Instead we
>> simply add an Eq instance for IVars similar to that for
>>
>>
>> -Ryan
>>
>>
>> P.S. There are a couple advantages of LVish vis a vis monad-par
>> presently:
>>
>>
>> * It uses the 's' parameter, avoiding that big omission in the first
>> monad-par that can lead to segfaults.
>> * It waits for all workers properly before exiting a runPar. We had
>> played fast and loose with that in some monad-par schedulers,
>> resulting in sloppiness in when exceptions crop up and possible
>> nondeterminism if the process exits just before a worker would
>> have hit an exception.
>>
>