[Haskell-cafe] Monad instance for Data.Set

Henning Thielemann lemming at henning-thielemann.de
Sun Mar 30 16:09:41 EDT 2008


On Tue, 25 Mar 2008, Ryan Ingram wrote:

>> settest :: S.Set Int
>> settest = runSetM $ do
>>    x <- mplus (mplus mzero (return 2)) (mplus (return 2) (return 3))
>>    return (x+3)
>> -- fromList [5,6]
>
> What this does under the hood is treat the computation on each element of the
> set separately, except at programmer-specified synchronization points where
> the computation result is required to be a member of the Ord typeclass.

It's like working in the List monad mainly, collapsing duplicates from 
time to time, right?


More information about the Haskell-Cafe mailing list