16
1
What is the shortest way we can express the function
f(a,b)(c,d)=(a+c,b+d)
in point-free notation?
pointfree.io gives us
uncurry (flip flip snd . (ap .) . flip flip fst . ((.) .) . (. (+)) . flip . (((.) . (,)) .) . (+))
which with a little bit of work can be shortened to
uncurry$(`flip`snd).((<*>).).(`flip`fst).((.).).(.(+)).flip.(((.).(,)).).(+)
for 76 bytes. But this still seems really long and complex for such a simple task. Is there any way we can express pairwise addition as a shorter point-free function?
To be clear by what I mean by point-free, a point-free declaration of a function involves taking existing functions and operators and applying them to each other in such a way that the desired function is created. Backticks, parentheses and literal values ([]
,0
,[1..3]
, etc.) are allowed but keywords like where
and let
are not. This means:
You may not assign any variables/functions
You may not use lambdas
You may not import
9I never understood why it is called “point-free” when it is actually full of points. :P – Mr. Xcoder – 2017-12-29T17:10:19.117
5
@Mr.Xcoder "A common misconception is that the 'points' of pointfree style are the (.) operator (function composition, as an ASCII symbol), which uses the same identifier as the decimal point. This is wrong. The term originated in topology, a branch of mathematics which works with spaces composed of points, and functions between those spaces. So a 'points-free' definition of a function is one which does not explicitly mention the points (values) of the space on which the function acts."
– Post Rock Garf Hunter – 2017-12-29T17:11:26.503What's considered an external library? Are imports from base allowed?
– Petr Pudlák – 2017-12-29T17:23:49.547I think so. So no keywords are allowed at all? I'd suggest explicitly allowing literal values like 0 and the empty tuple. Also, your example uses backticks, it should be clear then that's allowed. – xnor – 2017-12-29T17:41:12.953
@xnor Literals are allowed, keywords are not. Thanks for asking for clarifications, hopefully everything is clear. – Post Rock Garf Hunter – 2017-12-29T17:44:37.567
5
It's a shame we're not allowed to import the best Haskell package, or else the solution would just be
– Silvio Mayolo – 2017-12-30T03:05:00.243(+)***(+)
.2An idea:
(+)<$>([1],2)<*>([3],4)
gives([1,3],6)
. – xnor – 2017-12-30T05:40:02.7201
@SilvioMayolo Please add this to the tips for golfing in haskell! (and I invite you to join of monads and men :)
– flawr – 2017-12-30T10:29:56.1532
I spent some time trying to craft a fine solution utilizing xnor's tip... but I ended up with this garbage. I don't even know why I try sometimes...
– totallyhuman – 2017-12-30T13:59:07.917@flawr What is the meta consensus on using external packages? The package I referenced isn't part of
base
so it would have to be installed. – Silvio Mayolo – 2017-12-30T17:56:11.0231@SilvioMayolo You are allowed to use packages. If it's not in base its a different language, that's all. – Post Rock Garf Hunter – 2017-12-30T17:57:37.597
If not for the import ban, I'd say
Biapplicative
was the way to go. – dfeuer – 2019-06-14T22:35:58.317