ekmett / adjunctions

Simple adjunctions
http://hackage.haskell.org/package/adjunctions
Other
44 stars 27 forks source link

Exploit the (_ *> as = as) property of Representables in Co #64

Closed Icelandjack closed 4 years ago

Icelandjack commented 4 years ago

Edward says here:

For any Functor that is representable, .. you build a 'zipping' applicative that is isomorphic to reader. For that you can show that (m *> _ = m) and (_ <* m = m). So (<*) and (*>) are O(1) while the (<*>) pays for every point used.

It seems the order he drops things is flipped, in any case I propose we make use of this and define

instance Representable f => Applicative (Co f) where
 ..

 (*>) :: Co f a -> Co f b -> Co f b
 _ *> bs = bs

 (<*) :: Co f a -> Co f b -> Co f a
 as <* _ = as
RyanGlScott commented 4 years ago

Sounds reasonable to me! Care to make a pull request?

ekmett commented 4 years ago

Merged