Proposal: Move the instances from Control.Monad.Instances into GHC.Base

I propose that we move the contents of Control.Monad.Instances into GHC.Base where they will be picked up and distributed by the Prelude. Discussion deadline: 2 weeks from now (November 24) == Current State == Control.Monad.Instances is currently the canonical source for the following orphan instances, which involve prelude types, but which were not thought of at the time Haskell 98 was written. instance Functor ((->) r) where fmap = (.)instance Monad ((->) r) where return = const f >>= k = \ r -> k (f r) rinstance Functor ((,) a) where fmap f (x,y) = (x, f y)instance Functor (Either a) where fmap _ (Left x) = Left x fmap f (Right y) = Right (f y) == The Issues == When using almost any library, you wind up transitively importing Control.Applicative, which imports Control.Monad.Instances and brings them into scope, so realistically any attempt the user might make to define his own version of these instances is doomed to failure and pain upon linking with the larger Haskell ecosystem. == Proposed Enhancement == Control.Monad.Instances has been around for years, so experienced users have always had access to grab these but the main impact of hiding them in Control.Monad.Instances from a POSIWIDhttp://en.wikipedia.org/wiki/The_purpose_of_a_system_is_what_it_does perspective is to confuse newbies. The potential impact of just doing this right is less than the impact of changing Num, so I'd say we should just do it, and make Control.Monad.Instances an empty stub that exists just to avoid breaking code, and which can be used to support any other missing instances for Prelude types in the future which _can't_ be merged such as the missing instance Monoid e => Monad ((,) e) where return a = (a, mempty) (w,a) >>= k = (mappend w w', b) where (w',b) = k a which I'll propose separately. This would also let us be less careful about importing Control.Applicative in modules that get fed to the Prelude, which would be an important step in any eventual refactoring of the Monad class hierarchy to include Applicative anyways. -Edward

On 12 November 2011 21:12, Edward Kmett
I propose that we move the contents of Control.Monad.Instances into GHC.Base
+1 In your proposal you don't explicitly mention the Monad instance for Either. I assume you also want to move that instance. Small implementation detail: the Functor and Monad instances for Either should be moved to Data.Either since that module defines the Either type and imports GHC.Base. Thanks for proposing this! Bas

Edward Kmett wrote:
I propose that we move the contents of Control.Monad.Instances into GHC.Base... ...and make Control.Monad.Instances an empty stub that exists just to avoid breaking code, and which can be used to support any other missing instances for Prelude types in the future...
+1 This implies that your proposal also includes removing the import of Control.Monad.Instances from Control.Applicative. But you did not explicitly say so. Is this correct? If there is anywhere else in the base libraries where Control.Monad.Instances is imported, presumably that import should also be removed. Are we 100% certain that no other such import exists? Thanks, Yitz

On 13 November 2011 12:21, Yitzchak Gale
If there is anywhere else in the base libraries where Control.Monad.Instances is imported, presumably that import should also be removed. Are we 100% certain that no other such import exists?
A quick grep shows that Control.Monad.Fix also imports Control.Monad.Instances because it defines: class (Monad m) => MonadFix m where ... instance MonadFix ((->) r) where ... instance MonadFix (Either e) where ... Of course the import can be removed safely. Speaking about MonadFix: What about adding this instance to Control.Monad.Fix: instance Monoid w => MonadFix ((,) w) where mfix f = let m = f (snd m) in m ? Bas

On 12 November 2011 21:12, Edward Kmett
I propose that we move the contents of Control.Monad.Instances into GHC.Base where they will be picked up and distributed by the Prelude.
Discussion deadline: 2 weeks from now (November 24)
Hi Edward, It looks like your proposal didn't receive any objections so I assume it's accepted. I took the liberty to create a ticket and patch: http://hackage.haskell.org/trac/ghc/ticket/5685 Cheers, Bas
participants (4)
-
Bas van Dijk
-
Brent Yorgey
-
Edward Kmett
-
Yitzchak Gale