On Wed, Sep 13, 2000 at 11:48:24PM -0400, kirstin reese wrote:
> Surely this is obvious, but I cannot figure out how to properly deal with
> class constraints and monads. For instance, when trying
>
> instance Monad Set.Set where
> xs >>= f = Set.unionSet (Set.map f xs)
> return x = Set.single x
> fail s = Set.empty
>
> hugs complains that it "Cannot justify constraints in instance member
> binding" for >>=. unionSet type is Eq a => Set (Set a) -> Set a
I have the same problem in similar situations. What I'm attempting to
do is somehow lift the class-constraining computations out of the
monad. For instance, I was doing something on the order of using
some naive aggregation (like List.++) in the monad definition so it
could be fully polymorphic, and then doing other things outside
that definition to restore the natural set properties. This is
obviously less than ideal, and I'm hoping to discover or hear of other
techniques for dealing with this sort of situation in a cleaner manner.
Good luck,
Bill
--
<craving> Weak coffee is only fit for lemmas.
--