Adding (??) into Data.Functor

Hi all, I often come up using this snippet: map ($ a) l with l :: [a -> b] In Control.Lens, there's a nice combinator for that, (??) : l ?? a I think it'd be great to include that in Data.Functor, because it's a very common use case.

I too find such a function useful and deserving a place in the "base", however I don't think that it's a good idea to make it an operator, especially such a misleading one. I bet that I'm hardly alone in perception of question marks as of indicator of a questionable data (e.g., Maybe), but in no way of lists or functions. Therefore I suggest to instead consider some verbal name for it. E.g., "mapApp" or "mapf" (as an opposite to "fmap"). Also, since the variable input of this combinator seems to be on the functor side I suggest to inverse the arguments order order, i.e.: mapf :: a -> f (a -> b) -> f b This way it'll target composition. And since it's a combinator over functions it's a pretty important thing. E.g.: mapf 2 . map (*) $ [1..10] So, +1 for the combinator, -1 for the proposed name and arguments order .

By the way, your original example (`l ?? a`) can already be written as `l
<*> pure a` using the Applicative. So a new operator wouldn't gain that
much.
2014-02-17 0:42 GMT+04:00 Nikita Volkov
I too find such a function useful and deserving a place in the "base", however I don't think that it's a good idea to make it an operator, especially such a misleading one. I bet that I'm hardly alone in perception of question marks as of indicator of a questionable data (e.g., Maybe), but in no way of lists or functions. Therefore I suggest to instead consider some verbal name for it. E.g., "mapApp" or "mapf" (as an opposite to "fmap").
Also, since the variable input of this combinator seems to be on the functor side I suggest to inverse the arguments order order, i.e.:
mapf :: a -> f (a -> b) -> f b
This way it'll target composition. And since it's a combinator over functions it's a pretty important thing. E.g.:
mapf 2 . map (*) $ [1..10]
So, +1 for the combinator, -1 for the proposed name and arguments order .

I know the pure case, and it's not really what we expect I guess. For list,
pure embed the value in a list and do combinatorial computations between
the two lists, whereas map ($ a) just maps the value over the list (faster
I guess).
I'm okay about your two points : let's make it a verbal function, and use a
-> f (a -> b) -> f b as signature.
Now, mapf sounds a bit cryptic I guess. Something like applyOn, onTo, or
something like that would be clearer IMHO.
On Sun, Feb 16, 2014 at 9:48 PM, Nikita Volkov
By the way, your original example (`l ?? a`) can already be written as `l <*> pure a` using the Applicative. So a new operator wouldn't gain that much.
2014-02-17 0:42 GMT+04:00 Nikita Volkov
: I too find such a function useful and deserving a place in the "base",
however I don't think that it's a good idea to make it an operator, especially such a misleading one. I bet that I'm hardly alone in perception of question marks as of indicator of a questionable data (e.g., Maybe), but in no way of lists or functions. Therefore I suggest to instead consider some verbal name for it. E.g., "mapApp" or "mapf" (as an opposite to "fmap").
Also, since the variable input of this combinator seems to be on the functor side I suggest to inverse the arguments order order, i.e.:
mapf :: a -> f (a -> b) -> f b
This way it'll target composition. And since it's a combinator over functions it's a pretty important thing. E.g.:
mapf 2 . map (*) $ [1..10]
So, +1 for the combinator, -1 for the proposed name and arguments order .

I am a -1 on both proposals, i.e., on having a special map for the "apply to a fixed argument" case. On 16.02.2014 21:42, Nikita Volkov wrote:
Also, since the variable input of this combinator seems to be on the functor side I suggest to inverse the arguments order order, i.e.:
mapf :: a -> f (a -> b) -> f b
This way it'll target composition. And since it's a combinator over functions it's a pretty important thing. E.g.: mapf 2 . map (*) $ [1..10]
I'd simply write map (2 *) [1..10] Cheers, Andreas -- Andreas Abel <>< Du bist der geliebte Mensch. Depeartment of Computer Science and Engineering Chalmers and Gothenburg University, Sweden andreas.abel@gu.se http://www2.tcs.ifi.lmu.de/~abel/

This is a special case you mentionned there; it's not about lists, it's
about Functor. And applying a function with fmap using ($) is quite ugly.
On Mon, Feb 17, 2014 at 9:41 AM, Andreas Abel
I am a -1 on both proposals, i.e., on having a special map for the "apply to a fixed argument" case.
On 16.02.2014 21:42, Nikita Volkov wrote:
Also, since the variable input of this combinator seems to be on the functor side I suggest to inverse the arguments order order, i.e.:
mapf :: a -> f (a -> b) -> f b
This way it'll target composition. And since it's a combinator over functions it's a pretty important thing. E.g.: mapf 2 . map (*) $ [1..10]
I'd simply write
map (2 *) [1..10]
Cheers, Andreas
-- Andreas Abel <>< Du bist der geliebte Mensch.
Depeartment of Computer Science and Engineering Chalmers and Gothenburg University, Sweden
andreas.abel@gu.se http://www2.tcs.ifi.lmu.de/~abel/

I am also -1 on adding it to Data.Functor despite having written it for
lens.
On Mon, Feb 17, 2014 at 3:41 AM, Andreas Abel
I am a -1 on both proposals, i.e., on having a special map for the "apply to a fixed argument" case.
On 16.02.2014 21:42, Nikita Volkov wrote:
Also, since the variable input of this combinator seems to be on the functor side I suggest to inverse the arguments order order, i.e.:
mapf :: a -> f (a -> b) -> f b
This way it'll target composition. And since it's a combinator over functions it's a pretty important thing. E.g.: mapf 2 . map (*) $ [1..10]
I'd simply write
map (2 *) [1..10]
Cheers, Andreas
-- Andreas Abel <>< Du bist der geliebte Mensch.
Depeartment of Computer Science and Engineering Chalmers and Gothenburg University, Sweden
andreas.abel@gu.se http://www2.tcs.ifi.lmu.de/~abel/ _______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries

Would (<$$>) be a sensible name? To match (<**>) from Control.Applicative (<$$>) :: Functor f => a -> f (a -> b) -> f b I don't really feel the need for such a function, though. On a related note, the documentation for (<**>) is pretty bad. It says "A variant of <*> with the arguments reversed." but that doesn't make it clear that the function is different from `flip (<*>)`. Twan On 16/02/14 19:51, Dimitri Sabadie wrote:
Hi all,
I often come up using this snippet: map ($ a) l with l :: [a -> b]
In Control.Lens, there’s a nice combinator for that, (??) :
l ?? a
I think it’d be great to include that in Data.Functor, because it’s a very common use case.
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries

On Mon, Feb 17, 2014 at 8:21 PM, Twan van Laarhoven
Would (<$$>) be a sensible name? To match (<**>) from Control.Applicative
(<$$>) :: Functor f => a -> f (a -> b) -> f b
I don't really feel the need for such a function, though.
On a related note, the documentation for (<**>) is pretty bad. It says "A variant of <*> with the arguments reversed." but that doesn't make it clear that the function is different from `flip (<*>)`.
Is the current definition not equivalent to `flip (<*>)` though?
Twan
On 16/02/14 19:51, Dimitri Sabadie wrote:
Hi all,
I often come up using this snippet: map ($ a) l with l :: [a -> b]
In Control.Lens, there's a nice combinator for that, (??) :
l ?? a
I think it'd be great to include that in Data.Functor, because it's a very common use case.
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries
-- Sincerely yours, -- Daniil

On 17/02/14 17:29, Daniil Frumin wrote:
On Mon, Feb 17, 2014 at 8:21 PM, Twan van Laarhoven
wrote: Would (<$$>) be a sensible name? To match (<**>) from Control.Applicative
(<$$>) :: Functor f => a -> f (a -> b) -> f b
I don't really feel the need for such a function, though.
On a related note, the documentation for (<**>) is pretty bad. It says "A variant of <*> with the arguments reversed." but that doesn't make it clear that the function is different from `flip (<*>)`.
Is the current definition not equivalent to `flip (<*>)` though?
It is defined as (<**>) = liftA2 (flip ($)) So it does not flip the order of effects. Twan

Oh, I forgot about the effect order,
sorry for hijacking the thread.
On Mon, Feb 17, 2014 at 8:43 PM, Twan van Laarhoven
On 17/02/14 17:29, Daniil Frumin wrote:
On Mon, Feb 17, 2014 at 8:21 PM, Twan van Laarhoven
wrote: Would (<$$>) be a sensible name? To match (<**>) from Control.Applicative
(<$$>) :: Functor f => a -> f (a -> b) -> f b
I don't really feel the need for such a function, though.
On a related note, the documentation for (<**>) is pretty bad. It says "A variant of <*> with the arguments reversed." but that doesn't make it clear that the function is different from `flip (<*>)`.
Is the current definition not equivalent to `flip (<*>)` though?
It is defined as
(<**>) = liftA2 (flip ($))
So it does not flip the order of effects.
Twan
-- Sincerely yours, -- Daniil

FWIW The reason it is called (??) is to make it look like a placeholder.
foo ?? bar makes a function to replace the ?? placeholder.
It is somewhat more readable than an infixed `flip`.
Given my druthers l'd have kept the name (?) for this in lens rather than
let it devolve to (??), but too many people complained about taking a name
they were already using as (?) was the first operator added to lens without
a word frequency search against hackage first. The number of collisions it
had in practice was rather high.
It was added to lens because a lot of users were asking for variants of a
lot of the lens named combinators that swapped the second and third
arguments, so they could compose more nicely. By adding one name, (??) we
were able to deflect all of those requests.
Given creative use of multiple (??)'s you can use it to shuffle any
argument to last position, but that violates the 'place holder' intuition.
It has the more general type of Stefan Ljungstrand"s version of flip from
lambdabot, because, well, everything in lens tries to be as general as
possible, but the fact that it works for all functors is more or less an
accident that only a few users seem to exploit.
The major uses folks seem to put it to is to shuffle the arguments for
things like runState, etc. to put the monadic action last.
runState ?? myState $ do
...
is a lot less noisy than surrounding the whole do in quotes or giving a
name to the action
I remain slightly against adding it to a place like Data.Functor because I
don't like randomly stealing operator names and for most applications flip
is more clear as the named combinator conveys intuition about its purpose.
It fits into the lens ecosystem where I'm willing to assume a great deal of
time invested in understanding local idioms, but I feel it is a poor fit
for the larger ecosystem for those reasons.
-Edward
On Mon, Feb 17, 2014 at 11:21 AM, Twan van Laarhoven
Would (<$$>) be a sensible name? To match (<**>) from Control.Applicative
(<$$>) :: Functor f => a -> f (a -> b) -> f b
I don't really feel the need for such a function, though.
On a related note, the documentation for (<**>) is pretty bad. It says "A variant of <*> with the arguments reversed." but that doesn't make it clear that the function is different from `flip (<*>)`.
Twan
On 16/02/14 19:51, Dimitri Sabadie wrote:
Hi all,
I often come up using this snippet: map ($ a) l with l :: [a -> b]
In Control.Lens, there’s a nice combinator for that, (??) :
l ?? a
I think it’d be great to include that in Data.Functor, because it’s a very common use case.
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries
participants (6)
-
Andreas Abel
-
Daniil Frumin
-
Dimitri Sabadie
-
Edward Kmett
-
Nikita Volkov
-
Twan van Laarhoven