
Eta-reducing is nice, and sometimes it makes code more readable. But 'flip' is one of those functions that always seems to hinder rather than help readability, conversely factoring out flip always makes code easier to comprehend. I don't see a need for its existence - maybe I'm missing something and more experienced Haskellers can comment. -deech

On Sun, Jul 25, 2010 at 4:13 PM, aditya siram
Eta-reducing is nice, and sometimes it makes code more readable. But 'flip' is one of those functions that always seems to hinder rather than help readability, conversely factoring out flip always makes code easier to comprehend. I don't see a need for its existence - maybe I'm missing something and more experienced Haskellers can comment.
I'm a fan of (flip map), (flip mapM) and the like. These are usually renamed 'for' and 'forM' (and then 'forM_', of course). It makes for nice in-line function literals:
flip map xs $ \elem -> do something long and complex with xs
Antoine

On Sunday 25 July 2010 23:13:16, aditya siram wrote:
Eta-reducing is nice, and sometimes it makes code more readable. But 'flip' is one of those functions that always seems to hinder rather than help readability, conversely factoring out flip always makes code easier to comprehend. I don't see a need for its existence - maybe I'm missing something and more experienced Haskellers can comment.
-deech
For example, sortBy (flip compare) is very convenient (easier to parse¹ and it provides fewer opportunities for error than (\a b -> compare b a)). Also foldl' (flip Set.insert) Set.empty values and such stuff. Sometimes, functions have the wrong argument order for what you want to do, then flip is very handy. ¹ This is of course not a universal truth but a personal preference.

Excerpts from aditya siram's message of Sun Jul 25 17:13:16 -0400 2010:
Eta-reducing is nice, and sometimes it makes code more readable. But 'flip' is one of those functions that always seems to hinder rather than help readability, conversely factoring out flip always makes code easier to comprehend. I don't see a need for its existence - maybe I'm missing something and more experienced Haskellers can comment.
An interesting alternate spin on flip is infix notation combined with partial application, such as: (`foobar` 3) which is equivalent to \x -> foobar x 3 I frequently use this, although the jury's out on whether or not it's more readable. Cheers, Edward

On Sun, Jul 25, 2010 at 11:53 PM, Edward Z. Yang
An interesting alternate spin on flip is infix notation combined with partial application, such as:
(`foobar` 3)
which is equivalent to
\x -> foobar x 3
I frequently use this, although the jury's out on whether or not it's more readable.
I had HLint suggest me this : before : listeEtagTot = concatMap (flip listeEtagArm cfgTypesTringle) listeArmOrd after : listeEtagTot = concatMap (`listeEtagArm` cfgTypesTringle) listeArmOrd David.

On 26 July 2010 16:33, David Virebayre
On Sun, Jul 25, 2010 at 11:53 PM, Edward Z. Yang
wrote: An interesting alternate spin on flip is infix notation combined with partial application, such as:
(`foobar` 3)
which is equivalent to
\x -> foobar x 3
I frequently use this, although the jury's out on whether or not it's more readable.
I had HLint suggest me this :
before :
listeEtagTot = concatMap (flip listeEtagArm cfgTypesTringle) listeArmOrd
after :
listeEtagTot = concatMap (`listeEtagArm` cfgTypesTringle) listeArmOrd
However, if you had something like this, I think the flip version is nicer: With flip: foo = map (f . flip g x) Without flip: foo = map (f . (`g` x)) -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com

On 26.07.2010 08:33, David Virebayre wrote:
listeEtagTot = concatMap (`listeEtagArm` cfgTypesTringle) listeArmOrd
listeEtagTot = concatMap (listeEtagArm `flip` cfgTypesTringle)
You can use flip as a "wildcard" aswell: listeArmOrd Makes it even more readable in my opinion, since this really "shows" you where the value belongs to.

That's just cool. I now reverse my original statement - 'flip' does have
it's place in the pantheon of standard Haskell functions.
-deech
On Mon, Jul 26, 2010 at 3:42 PM, Nils
On 26.07.2010 08:33, David Virebayre wrote:
listeEtagTot = concatMap (`listeEtagArm` cfgTypesTringle) listeArmOrd
You can use flip as a "wildcard" aswell:
listeEtagTot = concatMap (listeEtagArm `flip` cfgTypesTringle) listeArmOrd
Makes it even more readable in my opinion, since this really "shows" you where the value belongs to.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Mon, Jul 26, 2010 at 10:42 PM, Nils
On 26.07.2010 08:33, David Virebayre wrote:
listeEtagTot = concatMap (`listeEtagArm` cfgTypesTringle) listeArmOrd
You can use flip as a "wildcard" aswell:
listeEtagTot = concatMap (listeEtagArm `flip` cfgTypesTringle) listeArmOrd
Makes it even more readable in my opinion, since this really "shows" you where the value belongs to.
It took me a fair while (I'm talking on the order of half a minute) to figure out what that meant, but it's pretty cool. Maybe a different name would be better? How about (??) or "it"?
listeEtagTot = concatMap (listeEtagArm ?? cfgTypesTringle) listeArmOrd listeEtagTot = concatMap (listeEtagArm `it` cfgTypesTringle) listeArmOrd
--Max

On Monday 26 July 2010 23:25:27, Max Rabkin wrote:
It took me a fair while (I'm talking on the order of half a minute) to figure out what that meant, but it's pretty cool.
Yeah, really neat.
Maybe a different name would be better? How about (??) or "it"?
listeEtagTot = concatMap (listeEtagArm ?? cfgTypesTringle) listeArmOrd listeEtagTot = concatMap (listeEtagArm `it` cfgTypesTringle) listeArmOrd
I think (??) is far better. Additionally, it doesn't run into problems with ghci's magical `it'.
--Max

2010/7/26 Daniel Fischer
On Monday 26 July 2010 23:25:27, Max Rabkin wrote:
It took me a fair while (I'm talking on the order of half a minute) to figure out what that meant, but it's pretty cool.
Yeah, really neat.
Maybe a different name would be better? How about (??) or "it"?
listeEtagTot = concatMap (listeEtagArm ?? cfgTypesTringle) listeArmOrd listeEtagTot = concatMap (listeEtagArm `it` cfgTypesTringle) listeArmOrd
I think (??) is far better. Additionally, it doesn't run into problems with ghci's magical `it'.
(__) is quite good :)

2010/7/26 Vo Minh Thu
2010/7/26 Daniel Fischer
: On Monday 26 July 2010 23:25:27, Max Rabkin wrote:
It took me a fair while (I'm talking on the order of half a minute) to figure out what that meant, but it's pretty cool.
Yeah, really neat.
Maybe a different name would be better? How about (??) or "it"?
listeEtagTot = concatMap (listeEtagArm ?? cfgTypesTringle) listeArmOrd listeEtagTot = concatMap (listeEtagArm `it` cfgTypesTringle) listeArmOrd
I think (??) is far better. Additionally, it doesn't run into problems with ghci's magical `it'.
(__) is quite good :)
Well, I meant `__` Cheers, Thu

It seems confusing to alias a function without adding any functionality just
to make things slightly easier to read. Instead wouldn't it be better if
this idiom were documented on haskell.org?
-deech
On Mon, Jul 26, 2010 at 4:47 PM, Vo Minh Thu
2010/7/26 Daniel Fischer
: On Monday 26 July 2010 23:25:27, Max Rabkin wrote:
It took me a fair while (I'm talking on the order of half a minute) to figure out what that meant, but it's pretty cool.
Yeah, really neat.
Maybe a different name would be better? How about (??) or "it"?
listeEtagTot = concatMap (listeEtagArm ?? cfgTypesTringle)
2010/7/26 Vo Minh Thu
: listeArmOrd listeEtagTot = concatMap (listeEtagArm `it` cfgTypesTringle) listeArmOrd
I think (??) is far better. Additionally, it doesn't run into problems with ghci's magical `it'.
(__) is quite good :)
Well, I meant `__`
Cheers, Thu _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 7/26/10 17:53 , aditya siram wrote:
It seems confusing to alias a function without adding any functionality just to make things slightly easier to read. Instead wouldn't it be better if this idiom were documented on haskell.org http://haskell.org?
And yet much of Applicative is exactly that. (It even started out being called "idioms".) - -- brandon s. allbery [linux,solaris,freebsd,perl] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.10 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkxONH0ACgkQIn7hlCsL25XLsgCcDLhDWBfkHcAGgc7145NuY08/ N4IAmgPHachdFS28mOGHeYD7yy1A3px2 =NLVp -----END PGP SIGNATURE-----

I think it is pretty cool as well. But I think there is a problem with
viewing it as a wildcard.
let's say we define the following:
(??) = flip
foo :: a -> b -> c
foo ?? x :: a -> c
Perfect!
But saying ?? can be used as a wildcard might in the following wrong
perception:
foo x ?? :: b -> c -- WRONG
Just a small concern. Other than that, very neat!
On 26 July 2010 21:42, Nils
On 26.07.2010 08:33, David Virebayre wrote:
listeEtagTot = concatMap (`listeEtagArm` cfgTypesTringle) listeArmOrd
You can use flip as a "wildcard" aswell:
listeEtagTot = concatMap (listeEtagArm `flip` cfgTypesTringle) listeArmOrd
Makes it even more readable in my opinion, since this really "shows" you where the value belongs to.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Ozgur Akgun

IMO, if you really want a wildcard, just write a lambda... \x -> foo 1 x 3 Cheers, Edward

Seconded. On Monday Jul 26, 2010, at 6:24 PM, Edward Z. Yang wrote:
IMO, if you really want a wildcard, just write a lambda...
\x -> foo 1 x 3
Cheers, Edward _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

(??) is misleading, some may be tempted to write things like: func ?? 45 ?? x , forgetting that ?? is just a mere operator, not a syntactic convenience. Unfortunately, Haskell doesn't provide Scala's underscore for partially applied functions: func(56, _, "foo", _)

On 26.07.2010 23:55, Ozgur Akgun wrote:
I think it is pretty cool as well. But I think there is a problem with viewing it as a wildcard.
let's say we define the following:
(??) = flip
foo :: a -> b -> c foo ?? x :: a -> c
Perfect!
But saying ?? can be used as a wildcard might in the following wrong perception:
foo x ?? :: b -> c -- WRONG
This looks interesting. I played around with this for a bit: {-# LANGUAGE MultiParamTypeClasses , FunctionalDependencies , FlexibleInstances #-} class Wildcard f v r | f -> v r where (??) :: f -> v -> r instance Wildcard (a -> b -> c) b (a -> c) where (??) = flip instance Wildcard (b -> c) b c where (??) = id f :: String -> Int -> String f s i = s ++ show i a :: String -> String a = (f ?? 5) b :: Int -> String b = (f "Int: " ??) Sadly, this won't typecheck: pattern.hs:19:0: Couldn't match expected type `Int' against inferred type `[Char]' Expected type: Int Inferred type: String When using functional dependencies to combine Wildcard (b -> c) b c, arising from the dependency `f -> a r' in the instance declaration at pattern.hs:12:9 Wildcard (String -> Int -> String) Int (String -> String), arising from a use of `??' at pattern.hs:19:5-10 When generalising the type(s) for `a' Ideas anyone? :)

aditya siram wrote:
Eta-reducing is nice, and sometimes it makes code more readable. But 'flip' is one of those functions that always seems to hinder rather than help readability, conversely factoring out flip always makes code easier to comprehend. I don't see a need for its existence - maybe I'm missing something and more experienced Haskellers can comment.
Not quite Haskell but, in combinator calculi 'flip' is unexpectedly powerful. It'd be odd not to have/use it in Haskell. Though in general I agree that it should be used sparingly, for legibility's sake. -- Live well, ~wren
participants (15)
-
aditya siram
-
Antoine Latter
-
Bill Atkins
-
Brandon S Allbery KF8NH
-
Daniel Fischer
-
David Virebayre
-
Edward Z. Yang
-
Ivan Miljenovic
-
Max Rabkin
-
Nils
-
Nils Schweinsberg
-
Ozgur Akgun
-
Vo Minh Thu
-
wren ng thornton
-
Yves Parès