Good: we have mapM, and we have forM ( = flip mapM ) .
Sure this is just a convenience, and indeed "forM xs $ \ x -> do ..." is quite handy, especially if "xs" is really small, and "..." is some larger expression. Bad: we have map, but we are missing: for ( = flip map ) . The function is very convenient, for the same reasons as above. I can't remember how often I typed "for = flip map" in a source file. I never put this definition in a module either, since the import statement would be longer than the definition. So, I'm all for "for" . In Data.List? In the Prelude? (Should put it right next to "map".) - J.W. _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
Similar proposal here: http://www.reddit.com/r/haskell/comments/qy990/suggestion_for_flip_map/
It seems generally favorable. Might as well generalize it though and have flip fmap. _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
In reply to this post by Johannes Waldmann
Doesn't for already exist, in Data.Traversable? Except that for =
flip traverse. http://www.haskell.org/hoogle/?hoogle=for Cheers, -Matthew On Wed, Mar 28, 2012 at 3:58 PM, Johannes Waldmann <[hidden email]> wrote: > Good: we have mapM, and we have forM ( = flip mapM ) . > > Sure this is just a convenience, and indeed > "forM xs $ \ x -> do ..." is quite handy, > especially if "xs" is really small, > and "..." is some larger expression. > > Bad: we have map, but we are missing: for ( = flip map ) . > > The function is very convenient, for the same reasons as above. > I can't remember how often I typed "for = flip map" in a source file. > I never put this definition in a module either, > since the import statement would be longer than the definition. > > So, I'm all for "for" . > > In Data.List? In the Prelude? (Should put it right next to "map".) > > - J.W. > > > _______________________________________________ > Haskell-Cafe mailing list > [hidden email] > http://www.haskell.org/mailman/listinfo/haskell-cafe _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
On 28 March 2012 22:05, Matthew Steele <[hidden email]> 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 [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
Think of "traverse" as a "mapA", as it's just like Data.Traversable.mapM, but with the Applicative class constraint instead of the Monad one.
I've always wondered why it isn't called this way, sequenceM equivalent for Applicatives is sequenceA for instance. Le 28 mars 2012 22:19, Christopher Done <[hidden email]> a écrit :
_______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
In reply to this post by Christopher Done
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 <[hidden email]> 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 > [hidden email] > http://www.haskell.org/mailman/listinfo/haskell-cafe _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
In reply to this post by Christopher Done
On Mar 28, 2012, at 4:19 PM, Christopher Done wrote:
> On 28 March 2012 22:05, Matthew Steele <[hidden email]> 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. That right; I was simply pointing out that the name 'for' is already taken by an existing base function. Things might be more consistant if 'traverse' and 'for' were instead called 'mapA' and 'forA' (by analogy with 'mapM' and 'forM'). Then one could add 'for = flip map' to base without conflict. But for some reason, that's not the case. Cheers, -Matthew _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
In reply to this post by Ezra Cooper
Some more bikeshedding:
Perhaps ffor, as in ffor = flip fmap or perhaps infixr 0 <$$> (<$$>) = flip (<$>) xs <$$> \x -> ... (cf. <**>) In both cases they should go in Data.Functor Sjoerd On Mar 28, 2012, at 11:26 PM, [hidden email] 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 <[hidden email]> 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 >> [hidden email] >> http://www.haskell.org/mailman/listinfo/haskell-cafe > > _______________________________________________ > Haskell-Cafe mailing list > [hidden email] > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- Sjoerd Visscher https://github.com/sjoerdvisscher/blog _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
On 29 March 2012 22:03, Sjoerd Visscher <[hidden email]> 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, [hidden email] 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 <[hidden email]> 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 >>> [hidden email] >>> http://www.haskell.org/mailman/listinfo/haskell-cafe >> >> _______________________________________________ >> Haskell-Cafe mailing list >> [hidden email] >> http://www.haskell.org/mailman/listinfo/haskell-cafe >> > > -- > Sjoerd Visscher > https://github.com/sjoerdvisscher/blog > > > > > > > _______________________________________________ > Haskell-Cafe mailing list > [hidden email] > http://www.haskell.org/mailman/listinfo/haskell-cafe -- Push the envelope. Watch it bend. _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
In reply to this post by Sjoerd Visscher-2
I've always thought this was missing for parser combinator libraries
as there is the notational tradition from YACC etc. to have production at the left then action at the right. On 29 March 2012 22:03, Sjoerd Visscher <[hidden email]> wrote: > or perhaps > > infixr 0 <$$> > (<$$>) = flip (<$>) > > xs <$$> \x -> ... _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
Powered by Nabble | Edit this page |