On Sun, Jan 9, 2011 at 10:11 PM, Lennart Augustsson
<lenn...@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
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to