Adding Applicative/Functor instances to all Monads in GHC

David Luposchainsky dluposchainsky at
Fri May 17 20:32:09 CEST 2013


> [Maybe] this would be better discussed on the ghc-devs@ list
I thought that as well, but SPJ said this might be a better place, as it
mostly concerns the base libraries. Since the discussion started here, I
think we shouldn't change lists. (Maybe if individual problems arise
those could be discussed individually over there.)

>> The idea behind this is making GHC future-proof for changing Applicative
>> to be a superclass of Monad.
> I don't think that it helps with this, for 2 reasons:
> 1. The next time someone adds a Monad, the chances are that they will
>    not think to add the other instances

That's a valid point. However, I think most people are aware of the
issue, so that most fresh code is created appropriately. This is of
course just idealistic speculation.

One thing I could imagine would be adding a compiler warning for missing
Applicative instances, but then again, this is beyond the scope of this
proposal (and my Haskell abilities).

The manual way of ensuring no non-Applicatives are introduced is of
course manual checking, which is a very easy task ("move Applicative to
Prelude, fix complaints, move Applicative back"). (Luckily, this is
within my abilities) :-)

> 2. You can't build GHC version X with GHC version Y, where Y > X.
>    Therefore should Applicative become a superclass of Monad, any GHC
>    that has that change would not be able to compile older GHCs (which
>    perhaps are missing Applicative instances) anyway.
I think this is actually an argument in favour of adding the instances.
If the new hierarchy is introduced, old versions will fail to compile,
yes, but only unless they have the instances in them already!
Suppose 7.8 includes all instances as proposed, and we're going up to
7.14 in a couple of years, and 8.0 introduces the new hierarchy.
Everything down to 7.8 will be compilable by 8.0, and most importantly
7.8 will in turn be able to compile GHC < 7.8. From how I see it, adding
the instances is the only possible way of not breaking backwards
compatibility completely, and doing so earlier simplifies the process.


More information about the Libraries mailing list