Remove Foldable from Traversable (was Haskell Foldable Wats)

Herbert Valerio Riedel hvr at gnu.org
Thu Feb 25 11:47:45 UTC 2016


On 2016-02-25 at 12:12:33 +0100, Jeremy wrote:

[...]

> Index Int wrote
>> And given that `Traversable` gives a rise to a `Foldable` similarly to how
>> a `Monad` gives a rise to an `Applicative`, it is the same stupid mistake
>> not to reflect this relation in the type system.
>
> The Monad definition actually uses the Applicative instance. Traversable
> makes no use of Foldable.

What do you mean by that exactly?


Haskell 2010 defines the `Monad` class as:

  class  Monad m  where
    return  :: a -> m a

    (>>=) :: m a -> (a -> m b) -> m b

    (>>) :: m a -> m b -> m b
    m >> k  =  m >>= \_ -> k

    fail :: String -> m a
    fail = error


whereas with AMP+MRP+MFP we would end up with the following quite
minimal `Monad` class definition:

  class  Applicative m => Monad m  where
    (>>=) :: m a -> (a -> m b) -> m b

In neither case `Applicative`'s methods are used.


Maybe a better example you could argue is that the `Ord` class
*currently* uses its `Eq` superclass to support its default
implementation of `compare`. But other than that you could just as
easily define an `Ord` class which does not use `(==)` in any of its
default method implementations, and therefore would exhibit a redundant
superclass constraint on `Eq`. But even then I guess nobody would want
to remove the `Eq` superclass from `Ord` either?


More information about the Libraries mailing list