00:30:40 | <eyebloom> | Instead of f x y z you could write f _ _ z |
00:31:24 | <rasfar> | eyebloom, this is amazing, you have hit upon the language extension I just started implementing an hour ago |
00:31:45 | <rasfar> | underscores and all... |
00:31:45 | <eyebloom> | You know what they say about great minds. |
00:32:17 | <rasfar> | maybe we'll find out whether there's any need. |
00:33:44 | <rasfar> | i was just looking to see if such an extension already exists, but it appears not (so far) |
00:37:51 | <eyebloom> | As syntactic sugar it would be a lot cleaner looking then a lambda a flip or even an explicit infix. |
00:40:16 | <eyebloom> | message me if you start working on this. |
00:40:26 | <rasfar> | fair enough! «email sent» |
00:31:12 | <quintessence> | :t flip |
00:31:13 | <lambdabot> | forall (f :: * -> *) a b. (Functor f) => f (a -> b) -> a -> f b |
00:32:13 | <cmccann> | :t flip . fmap flip |
00:32:14 | <lambdabot> | forall (f :: * -> *) a (f1 :: * -> *) b. (Functor f, Functor f1) => f (f1 (a -> b)) -> a -> f (f1 b) |
00:32:24 | <cmccann> | :t flip . fmap Prelude.flip |
00:32:28 | <lambdabot> | forall (f :: * -> *) a a1 c. (Functor f) => f (a1 -> a -> c) -> a -> f (a1 -> c) |
00:32:29 | <cmccann> | argh |
00:32:34 | <cmccann> | :t flip <<< fmap Prelude.flip |
00:32:35 | <lambdabot> | forall (f :: * -> *) a a1 c. (Functor f) => f (a1 -> a -> c) -> a -> f (a1 -> c) |
00:32:44 | <cmccann> | :t Prelude.flip <<< fmap Prelude.flip |
00:32:45 | <lambdabot> | forall a b a1 c. (a -> a1 -> b -> c) -> b -> a -> a1 -> c |
00:32:56 | <cmccann> | :t Prelude.flip <<< fmap Prelude.flip <<< fmap (fmap Prelude.flip) |
00:32:56 | <lambdabot> | forall a b a1 a2 c. (a -> a1 -> a2 -> b -> c) -> b -> a -> a1 -> a2 -> c |
00:33:32 | * | cmccann has a type-hackery generalized flip that does the kind of argument rotation as the above functions |
00:31:15 | <shachaf> | (\x y -> f x y z) |
00:32:15 | <dolio> | Vetoed. |
00:32:18 | <mzero> | if the function takes two arguments, say foo a b and you want to apply the b (leaving a function that takes a) then idiomatic Haskell is to write (`foo` 7) |
00:32:30 | <shachaf> | I second dolio's veto. |
00:33:44 | <mzero> | if you want more, it is idiomatic to use a lambda, which is generally easier than all this flipyness: (\a b -> fixMyThirdArg a b 42) |
00:34:13 | <tikhonjelvis> | flipyness is a good word |
00:34:22 | <mzero> | :-) |
00:34:24 | <eyebloom> | truthiness |
00:45:43 | <mzero> | gosh - I think the rarity of needing to partially apply a function to some argument than the first or second is such that it isn't worth complicating the language at all |
00:45:55 | <mzero> | practically, this just doesn't come up in my code base that often |
00:47:53 | <mzero> | wow - all this to avoid computer science's smallest lambda syntax? rlly? |
00:46:01 | <shachaf> | The obvious solution is to replace every _ with (\x->x). |
00:46:15 | <shachaf> | {-# LANGUAGE CPP #-} #define _ (\x->x) |
00:36:42 | <nand`> | let apFst = id; apSnd = flip; alThd f c = \a b -> f a b c; ... |
00:36:52 | <nand`> | foo `apThd` 42 |
00:38:19 | <dolio> | I've used languages with it, and it leads to people writing unclear code. |
00:38:43 | <dolio> | map (foo (g _) x) (h _) |
00:38:45 | * | rasfar attends to dolio carefully... |
00:38:47 | <quintessence> | scala? |
00:38:52 | <dolio> | Yes. |
00:38:51 | <glguy_> | Unclear code? Yup, Haskell already supports that |
00:39:09 | <eyebloom> | :) so does every language. |
00:39:44 | <quintessence> | I think the problem in scala is more that it's hard to see the scope of the (implicit) lambda |
00:40:22 | <dolio> | foo (g _) =?= foo $ g _ |
00:40:58 | <glguy_> | Factor supports that as a library |
00:41:06 | <quintessence> | Something like (\-> f _ 10 _) would be a little less ambiguous |
00:41:26 | <rwbarton> | Mathematica has this goofy Foo[a, #, c] & syntax |
00:42:39 | <rwbarton> | where & is like quintessence's \-> but in postfix form |
00:44:27 | <dolio> | Matter of fact, what does "map (foo (g _) x) (h _)" mean? |
00:45:29 | <nand`> | \a b -> map (foo (g a) x) (h b) maybe? |
00:45:48 | <shachaf> | How do you figure out where to put the lambda? |
00:45:55 | <nand`> | I didn't. I took a wild guess |
00:46:01 | <nand`> | that's the problem |
00:46:16 | <dolio> | nand`: I can tell you, that's not what the equivalent Scala code means. |
00:46:30 | <rwbarton> | could you show the actual equivalent Scala code? |
00:46:56 | <dolio> | h(_).map(foo(g(_))(x)) |
00:47:21 | <glguy_> | it burns us! |
00:47:27 | <dolio> | Drink that in. |
00:47:30 | <nyingen> | urk |
00:48:06 | <dolio> | The foo(g(_)) is something you'd actually use in scala, too. |
00:48:18 | <dolio> | because often times foo(g) would be illegal. |
00:48:31 | <dolio> | So you're stuck with foo(g(_)) or foo(g _) |
00:49:12 | <dolio> | Anyhow it means: a => h(a).map(foo(b => g(b))(x)) |
00:49:52 | <dolio> | Or if you kept it as: map(foo(g(_))(x))(h(_)), it'd be: map(foo(a => g(a))(x)(b => h(b)), I believe. |
00:49:53 | <rwbarton> | is that a => (h(a).map(foo(b => g(b))(x))) ? |
00:50:18 | <dolio> | Yes. x => e is a lambda expression in Scala. |
00:48:52 | <quintessence> | I think avoiding the names is the win and avoiding the lambda is the problem |
00:50:30 | <nand`> | \ -> (or more generally, replacing any distinct instance of _ in the right hand side of a lambda by a new identifier which would be appended to the left hand side of the nearest lambda) might work to save you a few keystrokes; |
00:50:37 | <nand`> | but then you run into situations such as nesting those |
00:52:49 | <nand`> | (\a -> f _ 42 _ a) could be assumed equivalent to (\a b c -> f b 42 c a) |