5 ms·
Why not translate your code to pointfree style automatically? Using[0], you can go from quad a b c = let d = b * b - 4 * a * c in ((-b + sqrt d) / 2 * a, (-b
by siraben 3y ago
Why not translate your code to pointfree style automatically? Using[0], you can go from
quad a b c = let d = b * b - 4 * a * c in ((-b + sqrt d) / 2 * a, (-b - sqrt d) / 2 * a)
to
ghci> import Control.Monad
ghci> quad = ap (ap . ((.) .) . ap (ap . (liftM2 (,) .) . flip (flip . ((*) .) . flip flip 2 . ((/) .) . (. sqrt) . (+) . negate)) (flip (flip . ((*) .) . flip flip 2 . ((/) .) . (. sqrt) . (-) . negate))) (flip ((.) . (-) . join (*)) . (*) . (4 *))
ghci> quad 1 3 (-4)
(1.0,-4.0)
[0] https://pointfree.io/ https://pointfree.io/
- yau8edq12i 3y agoApart from "just because we can" or "it's fun", why on earth would someone prefer the second style?
- euiq 3y agoIt's a joke.
- rebeccaskinner 3y agoIn this example I can’t imagine anyone preferring the second style, but there are cases where it’s nicer. For example compare the tacit: foo = h . g . f With the more verbose: foo x = let a = f x b = g a c = h b in c If a, b, and c have useful names that help you understand the code then the second function might be preferable- but in a lot of cases all the intermediate variables are just adding noise and making it harder to see what’s happening at a glance. The tacit example makes it very clear at a quick glance exactly what’s happening. My personal rule of thumb is that if you are passing combinators in as arguments to other combinators then you should probably stop, but straightforward chaining is usually okay.
- pasquinelli 3y agotacit programming means you don't use argument names to direct your data to the desired output. what's interesting to me about that is the unexplored possibilities of how data could be directed without names.
- meindnoch 3y agoClearly superior.