[Haskell-cafe] Adding Ord constraint to instance Monad Set?
S. Alexander Jacobson
haskell at alexjacobson.com
Tue Mar 30 17:11:21 EST 2004
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'
Since I obviously can't modify the class
declaration for Monad, the question arises:
How does one add (Orb b) to the instance method '>>='?
(Aside: it be really nice if the error messages
suggested textual changes or at least provide
sample syntax in addition to the conceptual
recommendation.)
-Alex-
PS I assume the reason that Set is not declared as
a Monad in Data.Set is oversight rather than
incompatibility....
PPS I want to thank everyone who has been
taking the time to answer all of my questions.
I'll try to collect my various learnings into a
useful beginners page once I reach the point where
I think I can create a useful document.
_________________________________________________________________
S. Alexander Jacobson mailto:me at alexjacobson.com
tel:917-770-6565 http://alexjacobson.com
More information about the Haskell-Cafe
mailing list