On 13-Sep-2000, kirstin reese <[EMAIL PROTECTED]> 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

Basically there is no way to do this in Haskell.
About the best you can do is to create your own `EqMonad' class,
which is like `Monad' except that it has an `Eq a' constraint
on the type variable.  Then use `EqMonad' instead of `Monad'.
You can't use the `do' syntax, and you can't reuse the library
routines that work on Monads.

-- 
Fergus Henderson <[EMAIL PROTECTED]>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger [EMAIL PROTECTED]        |     -- the last words of T. S. Garp.

Reply via email to