[Haskell-cafe] Adding Ord constraint to instance Monad Set?
iakd0 at clusterf.urz.uni-halle.de
Wed Mar 31 09:56:35 EST 2004
On Tue, 30 Mar 2004, S. Alexander Jacobson wrote:
> Following the declaration of "instance Monad "
> in the prelude, and puzzling over the absence of
> its equivalent from Data.Set, I naively typed:
> instance Monad Set where
> m >>= k = concatSets (mapSet k m)
> return x = unitSet x
> fail s = emptySet
> concatSets sets = foldl union emptySet (setToList sets)
> instance (Eq b,Ord b) => Ord (Set b) where
> compare set1 set2 = compare (setToList set1) (setToList set2)
> and got the following error:
> Could not deduce (Ord b) from the context (Monad Set)
> arising from use of `concatSets' at dbMeta3.hs:242
> Probable fix:
> Add (Ord b) to the class or instance method `>>='
> In the definition of `>>=': >>= m k = concatSets (mapSet k m)
> In the definition for method `>>='
> In the instance declaration for `Monad Set'
Surprisingly this is exact the same problem I posed in my mail "Context
for type parameters of type constructors" just before. I wanted to create
the class VectorSpace which is the analogon to Monad in your example. I'm
excited if the answers to your question will help me. :-)
More information about the Haskell-Cafe