[GHC] #4517: Add Data.Functor.Backwards to transformers

Ross Paterson ross at soi.city.ac.uk
Sat Nov 20 20:19:46 EST 2010

On Sat, Nov 20, 2010 at 05:25:23PM -0500, roconnor at theorem.ca wrote:
> Data.Functor.Backwards is a wrapper for functors that allow Foldable,
> Traversable, and Applicative functors to be operated backwards.  It is
> similar to Dual for Monoids.  The Applicative instance runs effects in
> reversed order.  The Foldable instance folds from right to left, The
> Traversable instance traverses from right to left.

It probably should also have an Alternative instance.  I expect that
wouldn't reverse the order of alternatives:

instance (Alternative f) => Alternative (Backwards f) where
    empty = Backwards empty
    Backwards x <|> Backwards y = Backwards (x <|> y)

More information about the Libraries mailing list