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

Ross Paterson ross at soi.city.ac.uk
Sun Nov 21 06:00:21 EST 2010


On Sat, Nov 20, 2010 at 10:17:29PM -0500, David Menendez wrote:
> The key code is,
> 
> instance Applicative f => Applicative (Backward f) where
> 	pure = Backward . pure
> 	Backward f <*> Backward a = Backward (a <**> f)
> 
> instance Traversable f => Traversable (Reverse f) where
>     traverse f = fmap Reverse . runBackward . traverse (Backward . f)
> . getReverse

Yes, that's the same as Russell's code.

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

Don't you need an Applicative instance for that?


More information about the Libraries mailing list