Dimitri Sabadie | 16 Feb 19:51 2014
Picon

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.
_______________________________________________
Libraries mailing list
Libraries <at> haskell.org
http://www.haskell.org/mailman/listinfo/libraries
Nikita Volkov | 16 Feb 21:42 2014
Picon

Re: Adding (??) into Data.Functor

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 .
_______________________________________________
Libraries mailing list
Libraries <at> haskell.org
http://www.haskell.org/mailman/listinfo/libraries
Nikita Volkov | 16 Feb 21:48 2014
Picon

Re: Adding (??) into Data.Functor

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 <nikita.y.volkov <at> gmail.com>:
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 .

_______________________________________________
Libraries mailing list
Libraries <at> haskell.org
http://www.haskell.org/mailman/listinfo/libraries
Dimitri Sabadie | 16 Feb 22:17 2014
Picon

Re: Adding (??) into Data.Functor

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 <nikita.y.volkov <at> gmail.com> wrote:
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 <nikita.y.volkov <at> gmail.com>:

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 .


_______________________________________________
Libraries mailing list
Libraries <at> haskell.org
http://www.haskell.org/mailman/listinfo/libraries
Andreas Abel | 17 Feb 09:41 2014
Picon
Picon

Re: Adding (??) into Data.Functor

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 <at> gu.se
http://www2.tcs.ifi.lmu.de/~abel/
Dimitri Sabadie | 17 Feb 14:51 2014
Picon

Re: Adding (??) into Data.Functor

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 <abela <at> chalmers.se> wrote:
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 <at> gu.se
http://www2.tcs.ifi.lmu.de/~abel/

_______________________________________________
Libraries mailing list
Libraries <at> haskell.org
http://www.haskell.org/mailman/listinfo/libraries
Edward Kmett | 17 Feb 17:15 2014
Picon

Re: Adding (??) into Data.Functor

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 <abela <at> chalmers.se> wrote:
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 <at> gu.se
http://www2.tcs.ifi.lmu.de/~abel/
_______________________________________________
Libraries mailing list
Libraries <at> haskell.org
http://www.haskell.org/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
Libraries <at> haskell.org
http://www.haskell.org/mailman/listinfo/libraries
Twan van Laarhoven | 17 Feb 17:21 2014
Picon

Re: Adding (??) into Data.Functor

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 <at> haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
>

_______________________________________________
Libraries mailing list
Libraries <at> haskell.org
http://www.haskell.org/mailman/listinfo/libraries
Daniil Frumin | 17 Feb 17:29 2014
Picon

Re: Adding (??) into Data.Functor

On Mon, Feb 17, 2014 at 8:21 PM, Twan van Laarhoven <twanvl <at> gmail.com> 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?

>
> 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 <at> haskell.org
>> http://www.haskell.org/mailman/listinfo/libraries
>>
>
> _______________________________________________
> Libraries mailing list
> Libraries <at> haskell.org
> http://www.haskell.org/mailman/listinfo/libraries

--

-- 
Sincerely yours,
-- Daniil
Twan van Laarhoven | 17 Feb 17:43 2014
Picon

Re: Adding (??) into Data.Functor

On 17/02/14 17:29, Daniil Frumin wrote:
> On Mon, Feb 17, 2014 at 8:21 PM, Twan van Laarhoven <twanvl <at> gmail.com> 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
Daniil Frumin | 17 Feb 19:08 2014
Picon

Re: Adding (??) into Data.Functor

Oh, I forgot about the effect order,
sorry for hijacking the thread.

On Mon, Feb 17, 2014 at 8:43 PM, Twan van Laarhoven <twanvl <at> gmail.com> wrote:
> On 17/02/14 17:29, Daniil Frumin wrote:
>>
>> On Mon, Feb 17, 2014 at 8:21 PM, Twan van Laarhoven <twanvl <at> gmail.com>
>> 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
Edward Kmett | 18 Feb 00:53 2014
Picon

Re: Adding (??) into Data.Functor

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 <twanvl <at> gmail.com> 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 (<*>)`.


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 <at> haskell.org
http://www.haskell.org/mailman/listinfo/libraries


_______________________________________________
Libraries mailing list
Libraries <at> haskell.org
http://www.haskell.org/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
Libraries <at> haskell.org
http://www.haskell.org/mailman/listinfo/libraries

Gmane