Possible Duplicate:
Restricting a monad to a type class
I want to write a Set monad that's similar to the List monad. However, this can't be done because Set requires its types to be ordered. Is there a way to create a monad that only takes values in a particular typeclass (say, Ord)? The code I want to write is
instance Monad Set.Set where
return a = Set.singleton a
-- set α, function (α -> set β)
xs >>= f = Set.fold
(\x s -> Set.union s (f x))
Set.empty
xs
Thanks in advance!