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:

http://okmij.org/ftp/Haskell/types.html#restricted-datatypes
http://www.randomhacks.net/articles/2007/03/15/data-set-monad-haskell-macros

Dan

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.

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to