Proposal: add $> to Data.Functor

Data.Functor has <$> and <$, but not $>, which should be a flipped version of <$, analogous to <*>, <*, and *> in Control.Applicative. I was astonished to see that Data.Functor doesn't have it so I had to write it myself. Then I looked on hackage and found it defined in comonad package (also re-exported from semigroupoids). One (seemingly unmaintained, last version Apr 2012) package named iterIO has it, too. infixl 4 $> -- | Replace the contents of a functor uniformly with a constant value. ($>) :: Functor f => f b -> a -> f a ($>) = flip (<$) I propose to add this to Data.Functor; mostly because I think users expect it there (again by analogy with Applicative), even though it is trivial to write (but then writing <$ is trivial, too). Cheers Ben -- "Make it so they have to reboot after every typo." -- Scott Adams

On 2013-12-08 at 02:06:26 +0100, Ben Franksen wrote:
Data.Functor has <$> and <$, but not $>, which should be a flipped version of <$, analogous to <*>, <*, and *> in Control.Applicative. I was astonished to see that Data.Functor doesn't have it so I had to write it myself. Then I looked on hackage and found it defined in comonad package (also re-exported from semigroupoids). One (seemingly unmaintained, last version Apr 2012) package named iterIO has it, too.
infixl 4 $> -- | Replace the contents of a functor uniformly with a constant value. ($>) :: Functor f => f b -> a -> f a ($>) = flip (<$)
I propose to add this to Data.Functor; mostly because I think users expect it there (again by analogy with Applicative), even though it is trivial to write (but then writing <$ is trivial, too).
fyi, this has been suggested a few months ago as part of http://comments.gmane.org/gmane.comp.lang.haskell.libraries/18952 and as a matter of fact has been already implemented in base-4.7.0.0: https://github.com/ghc/packages-base/blob/master/Data/Functor.hs#L36-L40 Cheers, hvr

Data.Functor has <$> and <$, but not $>, which should be a flipped version of <$, analogous to <*>, <*, and *> in Control.Applicative.
Whoa there, it's not at all analogous. Your wording is almost suggesting that <* is a flipped *>, but beyond that, they are uncomparable to begin with. Applicative functors: (<*>) :: Applicative f => f (a -> b) -> f a -> f b (<*) :: Applicative f => f a -> f b -> f a (*>) :: Applicative f => f a -> f b -> f b Removing the `f` in the first position, you'd get an honest analogue for any functor: (<$>) :: Functor f => (a -> b) -> f a -> f b (<$) :: Functor f => a -> f b -> f a ($>) :: Functor f => a -> f b -> f b Here, I don't see how ($>) could be anything else than `const id`. Or am I missing something here?

($>) is analogous to (*>) not by dropping the f in the first position, but
the f in the second, as proposed.
(*>) :: Applicative f => f a -> f b -> f b
($>) :: Functor f => f a -> b -> f b
It is unfortunate that (*>) is not equivalent to (flip (<*)), but it is a
special case where breaking the "flipped characters" convention is useful
for the sake of Applicative's convention to gather effects from left to
right. It is nice that ($>) adheres to the flipped characters convention as
well as being analogous to (*>).
-- Dan Burton
On Sun, Dec 8, 2013 at 9:22 AM, Stijn van Drongelen
Data.Functor has <$> and <$, but not $>, which should be a flipped version of <$, analogous to <*>, <*, and *> in Control.Applicative.
Whoa there, it's not at all analogous. Your wording is almost suggesting that <* is a flipped *>, but beyond that, they are uncomparable to begin with.
Applicative functors:
(<*>) :: Applicative f => f (a -> b) -> f a -> f b (<*) :: Applicative f => f a -> f b -> f a (*>) :: Applicative f => f a -> f b -> f b
Removing the `f` in the first position, you'd get an honest analogue for any functor:
(<$>) :: Functor f => (a -> b) -> f a -> f b (<$) :: Functor f => a -> f b -> f a ($>) :: Functor f => a -> f b -> f b
Here, I don't see how ($>) could be anything else than `const id`.
Or am I missing something here?
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries

Herbert Valerio Riedel wrote:
On 2013-12-08 at 02:06:26 +0100, Ben Franksen wrote:
Data.Functor has <$> and <$, but not $>, which should be a flipped version of <$, analogous to <*>, <*, and *> in Control.Applicative. I was astonished to see that Data.Functor doesn't have it so I had to write it myself. Then I looked on hackage and found it defined in comonad package (also re-exported from semigroupoids). One (seemingly unmaintained, last version Apr 2012) package named iterIO has it, too.
infixl 4 $> -- | Replace the contents of a functor uniformly with a constant value. ($>) :: Functor f => f b -> a -> f a ($>) = flip (<$)
I propose to add this to Data.Functor; mostly because I think users expect it there (again by analogy with Applicative), even though it is trivial to write (but then writing <$ is trivial, too).
fyi, this has been suggested a few months ago as part of
http://comments.gmane.org/gmane.comp.lang.haskell.libraries/18952
and as a matter of fact has been already implemented in base-4.7.0.0:
https://github.com/ghc/packages-base/blob/master/Data/Functor.hs#L36-L40
Thanks, I'm glad the proposal has been obsoleted in this way. Count it as a +1 after the fact ;-) Cheers Ben -- "Make it so they have to reboot after every typo." -- Scott Adams
participants (5)
-
Ben Franksen
-
Dan Burton
-
Herbert Valerio Riedel
-
John Wiegley
-
Stijn van Drongelen