Playing with lambda elimination and point-free style
It was a long time since I've last played with Haskell, so I decided to do a bit of lambda elimination as an exercise.
Beautiful, isn't it? :-D
Of course the last one boils down to foldl1 ((+).(*10)) [1..4], but don't tell anyone! ;-) I'm too embarrassed to spell out what the others mean...
Note that I've figured out the optimization of f and g themselves only halfway through the session.
A bit of this magic can improve your code, as you've probably noticed in my numerous posted sources, but this is also motivating: UNIX pipes vs. dot operator.
Though, you shouldn't go too far, or else you could arrive at a solution similar to this automatically translated one found on Nabble:
That results in the following sexy line noise:
let f=(\x y->x++y);g=(\x y z->x++y++z)in f(g "1""2""3")"4"
let f=(++);g=(f.).f in f(g "1""2""3")"4"
let f=(++);g=(f.).f in (f(g "1""2""3"))"4"
let f=(++);g=(f.).f in (f.(g "1""2"))"3""4"
let f=(++);g=(f.).f in (f.((g "1")"2"))"3""4"
let f=(++);g=(f.).f in ((f.).(g "1"))"2""3""4"
let f=(++);g=(f.).f in ((f.).g "1")"2""3""4"
let f=(++);g=(f.).f in (((f.).).g)"1""2""3""4"
let f=(++);g=(f.).f;h=((f.).).g in h"1""2""3""4"
let f=(++);h=((f.).).(f.).f in h"1""2""3""4"
let f=(++);h=(((f.).).).((f.).).(f.).f in h"1""2""3""4""5"
let f=((+).(*10));h=((f.).).(f.).f in h 1 2 3 4
Beautiful, isn't it? :-D
Of course the last one boils down to foldl1 ((+).(*10)) [1..4], but don't tell anyone! ;-) I'm too embarrassed to spell out what the others mean...
Note that I've figured out the optimization of f and g themselves only halfway through the session.
A bit of this magic can improve your code, as you've probably noticed in my numerous posted sources, but this is also motivating: UNIX pipes vs. dot operator.
Though, you shouldn't go too far, or else you could arrive at a solution similar to this automatically translated one found on Nabble:
(\op (a, b) (c, d) -> (a `op` c, b `op` d))
That results in the following sexy line noise:
(`ap` snd) . (. fst) . flip flip snd . ((flip . (ap .)) .) . flip flip fst . ((flip . ((.) .)) .) . (flip =<< (((.) . flip . (((.) . (,)) .)) .))
Comments
Post a Comment