[Haskell-cafe] Adding Ord constraint to instance Monad Set?

Benjamin Franksen benjamin.franksen at bessy.de
Wed Mar 31 10:53:50 EST 2004


On Wednesday 31 March 2004 08:48, Wolfgang Jeltsch wrote:
> Am Mittwoch, 31. März 2004 03:11 schrieb Benjamin Franksen:
> > >    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)> [...]
> >
> > [...]
> >
> > Now, as i think a little more about it, i believe what you want to
> > do makes no sense. The monad operation '>>=' works on monads over
> > *different* 'element' (i.e. argument) types (look at the type of
> > '>>='). Your implementation only works if argument types are the
> > same. I can't see how this can be generalized to different argument
> > types even if both are instances of class Ord.
>
> I disagree.  AFAICS, his implementation also works with different
> element types.  Am I overlooking something?

No, you are right. I failed to notice the call to mapSet. Sorry for the 
confusion.

Ben



More information about the Haskell-Cafe mailing list