In pointful notation:
absoluteError x y = abs (x-y)
An unclear example in pointfree notation:
absoluteError' = curry (abs . uncurry (-))
Here's how you could derive it yourself, in small steps:
absoluteError x y = abs (x-y) = abs ((-) x y) = abs ( ((-) x) y)
= (abs . (-) x) y = ( (abs .) ((-) x) ) y =
= ( (abs .) . (-) ) x y
so, by eta-reduction, if f x y = g x y
we conclude f = g
.
Further, using _B = (.)
for a moment,
(abs .) . (-) = _B (abs .) (-) = _B (_B abs) (-) = (_B . _B) abs (-)
= ((.) . (.)) abs (-)
Here's a handful of ways.
absoluteError = (abs .) . (-)
absoluteError = ((.) . (.)) abs (-)
name the boobs operator something more politically correct (and what the heck, generalize it at the same time)
(.:) = fmap fmap fmap
absoluteError = abs .: (-)
using semantic editor combinators:
result :: (o1 -> o2) -> (i -> o1) -> (i -> o2)
result = (.)
absoluteError = (result . result) abs (-)
Of course, these are all the same trick, just with different names. Enjoy!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With