[Haskell-cafe] The container problem

Dan Weston westondan at imageworks.com
Fri Sep 26 18:50:51 EDT 2008

More specifically, although a set is a perfectly good (lowercase) 
functor, Set is not a (Haskell) Functor.

Set's map has an Ord constraint, but the Functor type constructor is 
parametric over *all* types, not just that proper subset of them that 
have a total ordering.

But see attempts to fix this:



Jonathan Cast wrote:
> On Fri, 2008-09-26 at 15:25 -0700, Jason Dusek wrote:
>> Can someone explain, why is it that Set can not be a Monad?
> It can't even be a functor (which all monads are).  You can't implement
>     fmap (+) $ Set.fromList [1, 2, 3]
> with Data.Set, because you can't order functions of type Integer ->
> Integer in a non-arbitrary way.  So you can't have a balanced binary
> tree of them in a non-arbitrary way, either.  Something like
>     fmap putStrLn $ Set.fromList ["Hello", "world"]
> is similar.
> Since Data.Set is implemented in Haskell, it can only use facilities
> available to Haskell libraries.  So it can't work for arbitrary
> elements; but a Functor instance requires that it does work.

More information about the Haskell-Cafe mailing list