[Haskell-cafe] for = flip map
Thomas Schilling
nominolo at googlemail.com
Thu Mar 29 23:47:28 CEST 2012
On 29 March 2012 22:03, Sjoerd Visscher <sjoerd at w3future.com> wrote:
> Some more bikeshedding:
>
> Perhaps ffor, as in
>
> ffor = flip fmap
>
> or perhaps
>
> infixr 0 <$$>
> (<$$>) = flip (<$>)
>
> xs <$$> \x -> ...
I don't think it makes sense to add a whole new operator for that.
You can just use sections:
(<$> xs) \x -> ...
The reason you can't do this with <*> is the ordering of effects.
I have to admit, though, that the above isn't exactly readable. The
non-operator version is somewhat more readable:
(`map` xs) \x -> ...
I'd still prefer "for" or "foreach".
>
> (cf. <**>)
>
> In both cases they should go in Data.Functor
>
> Sjoerd
>
> On Mar 28, 2012, at 11:26 PM, ezra at ezrakilty.net wrote:
>
>> I would very much like to see a standard function for "flip map" along
>> these lines. I think it would make a lot of code more readable.
>>
>> Like the OP, I use "for" in my own code. It's unfortunate that
>> Data.Traversable takes the name with another type. Two options would be
>> to (a) reuse the name in Data.List and force people to qualify as
>> necessary, or (b) choose another name for "flip map".
>>
>> Regarding other possible names: forall is a keyword and forAll is used
>> by QuickCheck. One possibility would be "foreach".
>>
>> Ezra
>>
>> On Wed, Mar 28, 2012, at 10:19 PM, Christopher Done wrote:
>>> On 28 March 2012 22:05, Matthew Steele <mdsteele at alum.mit.edu> wrote:
>>>> Doesn't for already exist, in Data.Traversable? Except that for =
>>>> flip traverse.
>>>
>>> Traverse doesn't fit the type of fmap, it demands an extra type
>>> constructor:
>>>
>>> traverse :: (Traversable t,Applicative f) => (a -> f b) -> t a -> f (t b)
>>>
>>> fmap :: Functor f => (a -> b) -> f a -> f b
>>>
>>> Note the (a -> f b) instead of (a -> b).
>>>
>>> E.g.
>>>
>>> fmap :: (a -> b) -> [a] -> [b]
>>>
>>> can't be expressed with traverse, you can only get this far:
>>>
>>> traverse :: (a -> [b]) -> [a] -> [[b]]
>>>
>>> Unless I'm missing something.
>>>
>>> _______________________________________________
>>> Haskell-Cafe mailing list
>>> Haskell-Cafe at haskell.org
>>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>
> --
> Sjoerd Visscher
> https://github.com/sjoerdvisscher/blog
>
>
>
>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
--
Push the envelope. Watch it bend.
More information about the Haskell-Cafe
mailing list