4 ms·
For haskell there is a fantastic tool that converts code into a pointfree function definition. https://hackage.haskell.org/package/pointfree https://hackage.ha
by rnhmjoj 10y ago
For haskell there is a fantastic tool that converts code into a pointfree function definition.
https://hackage.haskell.org/package/pointfree https://hackage.haskell.org/package/pointfree
- JadeNB 10y ago> For haskell there is a fantastic tool that converts code into a pointfree function definition. But why? If a point-free style is more readable, then by all means use it, but if you need an automated tool to do the translation for you, then that seems unlikely. If it's an efficiency question, then your compiler can, and (given the trickiness of GHC in particular) probably will, do anything that an external automated tool can.
- rnhmjoj 10y agoFor fun mostly but it can be useful too: it can find neat solutions I couldn't think of and I may decide to use it. Of course it gives also crazy stuff like `(((.) . (,)) .)` that I will never put in a program because I don't understand or it's just worse than the original input.
- JadeNB 10y ago> For fun mostly but it can be useful too: it can find neat solutions I couldn't think of and I may decide to use it. Of course it gives also crazy stuff like `(((.) . (,)) .)` that I will never put in a program because I don't understand or it's just worse than the original input. If it is purely an intellectual exercise, to see how else the code could theoretically be written, then I totally see the point. (I am a mathematician, after all!) On the other hand, if it is code that you actually use in production, then surely the old dictum that I will misquote, for want of looking it up, as "if you write the cleverest code possible, then you are not clever enough to debug it", applies all the more so to say "if you aren't clever enough to write your own code, then you certainly aren't clever enough to debug it"! (Not you personally, I mean; just a comment on programmer-facing auto-generated code.)
- posterboy 10y agoI think the lesson here is, if the conversion looks horrendous, then the original was questionable in the first place.
- JadeNB 10y agoIncidentally, I couldn't resist some eta expansion. If I didn't screw it up: (((.) . (,)) .) f x g y (((.) . (,)) . f) x g y (((.) . (,)) (f x)) g y ((.) ((,) (f x))) g y ((.) (f x,)) g y ((f x,) . g) y (f x, g y)
- evincarofautumn 10y agoI wish the pointfree utility would use slightly higher-level combinators like those from Control.Arrow. Readable point-free code tends to break things up into many small reusable pieces, following the maxim of “name code, not data”. This example is totally absurd, since you’d just write “(f x, g y)” and call it a day, but you can extract a fully point-free version that’s somewhat readable. f = pairwise $ curry $ apply *** apply where pairwise = fcurry fcurry fcurry = fmap curry apply = uncurry ($)
- thomastjeffery 10y ago> If a point-free style is more readable, then by all means use it And this is a tool to do just that.
- lmm 10y ago> If a point-free style is more readable, then by all means use it, but if you need an automated tool to do the translation for you, then that seems unlikely. I find the pointfree style is usually easier to read but the pointful style is often easier to write. So I tend to write pointful first and then translate into pointfree. An automated tool can help with that.