[Haskell-cafe] Set monad

Sebastian Fischer fischer at nii.ac.jp
Wed Jan 12 15:11:32 CET 2011


On Sun, Jan 9, 2011 at 10:11 PM, Lennart Augustsson
<lennart at augustsson.net>wrote:

> That looks like it looses the efficiency of the underlying representation.
>

Yes, I don't think one can retain that cleanly without using restricted
monads to exclude things like

    liftM ($42) (mplus (return pred) (return succ))

or just

    liftM ($42) (return pred)

Maybe one can hack something to achieve

    mplus :: Ord a => Set a -> Set a -> Set a
    mplus a b = Set (\k -> S.union (a >>- ret) (b >>- ret) `bind` k)
      where
        ret = S.singleton
        bind = flip Data.Foldable.foldMap

    mplus :: not (Ord a) => Set a -> Set a -> Set a
    mplus a b = Set (\k -> S.union (a >>- k) (b >>- k))

using overloading with undecidable instances (?) (and defining a Monoid
instance for the Set monad in terms of the MonadPlus instance)

Reminds me of instance chains.. [1]

Sebastian

[1]: http://portal.acm.org/citation.cfm?id=1863596
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110112/78e1268a/attachment.htm>


More information about the Haskell-Cafe mailing list