[GHC] #4517: Add Data.Functor.Backwards to transformers
dave at zednenem.com
Sun Nov 21 12:45:08 EST 2010
On Sun, Nov 21, 2010 at 6:00 AM, Ross Paterson <ross at soi.city.ac.uk> wrote:
> 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.
Aside from the distinction between Reverse and Backward, yes.
>> 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?
Yes. For Reverse, the Functor, Applicative, and Monad instances just
lift the instances of the underlying type. (In fact, I'm not sure why
I wrote them out instead of using newtype deriving.)
Dave Menendez <dave at zednenem.com>
More information about the Libraries