1

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!

Community
  • 1
  • 1
gatoatigrado
  • 16,580
  • 18
  • 81
  • 143
  • http://hackage.haskell.org/package/rmonad – n. m. could be an AI Aug 31 '11 at 04:57
  • @n.m. Sorry, I guess SO only found the duplicate after I added the tags ... they should put the tag field before the description so the "possible duplicates" would get filtered better. Please add the rmonad link to the other question, it is very useful! – gatoatigrado Aug 31 '11 at 06:21

0 Answers0