What are some interesting uses of higher-order functions?

后端 未结 14 828
走了就别回头了
走了就别回头了 2021-01-30 00:55

I\'m currently doing a Functional Programming course and I\'m quite amused by the concept of higher-order functions and functions as first class citizens. However, I can\'t yet

14条回答
  •  野性不改
    2021-01-30 01:35

    Martín Escardó provides an interesting example of a higher-order function:

    equal :: ((Integer -> Bool) -> Int) -> ((Integer -> Bool) -> Int) -> Bool
    

    Given two functionals f, g :: (Integer -> Bool) -> Int, then equal f g decides if f and g are (extensionally) equal or not, even though f and g don't have a finite domain. In fact, the codomain, Int, can be replaced by any type with a decidable equality.

    The code Escardó gives is written in Haskell, but the same algorithm should work in any functional language.

    You can use the same techniques that Escardó describes to compute definite integrals of any continuous function to arbitrary precision.

提交回复
热议问题