Proposal: merge either into transformers

Ross Paterson ross at soi.city.ac.uk
Sun Dec 9 02:24:36 CET 2012


On Sat, Dec 08, 2012 at 10:55:45PM +0000, Henning Thielemann wrote:
> 
> On Fri, 7 Dec 2012, Edward Kmett wrote:
> 
> > I will be sad to see those instances go, but I'm also +1
> 
> How about:
> 
> import Prelude hiding (Show, showsPrec)
> import qualified Prelude as P
> 
> class Show m where
>    showsPrec :: (P.Show e, P.Show a) => Int -> m (Either e a) -> ShowS
> 
> instance (Show m, P.Show e, P.Show a) => P.Show (EitherT e m a) where
>    showsPrec d (EitherT m) = showParen (d > 10) $
>      showString "EitherT " . showsPrec 11 m

A more economical variation on this idea would be to lift these classes
to functors, e.g.

class ShowF f where
    showsPrecF :: Show a => Int -> f a -> ShowS

instance (ShowF m, Show e, Show a) => Show (EitherT e m a) where
    showsPrec d (EitherT m) = showParen (d > 10) $
        showString "EitherT " . showsPrecF 11 m

instance (ShowF m, Show e) => ShowF (EitherT e m) where
    showsPrecF = showsPrec



More information about the Libraries mailing list