Is there a better way to express the absolute error function in point-free notation?

前端 未结 2 580
萌比男神i
萌比男神i 2020-12-15 21:01

In pointful notation:

absoluteError x y = abs (x-y)

An unclear example in pointfree notation:

absoluteError\' = curry (abs . uncur

2条回答
  •  眼角桃花
    2020-12-15 21:49

    Here's a handful of ways.

    1. the old-fashioned: absoluteError = (abs .) . (-)
    2. use the so-called "boobs operator", or "owl operator" absoluteError = ((.) . (.)) abs (-)
    3. name the boobs operator something more politically correct (and what the heck, generalize it at the same time)

      (.:) = fmap fmap fmap
      absoluteError = abs .: (-)
      
    4. 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!

提交回复
热议问题