What are some interesting uses of higher-order functions?

后端 未结 14 573
走了就别回头了
走了就别回头了 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:49

    Higher-order functions are also required for currying, which Haskell uses everywhere. Essentially, a function taking two arguments is equivalent to a function taking one argument and returning another function taking one argument. When you see a type signature like this in Haskell:

    f :: A -> B -> C
    

    ...the (->) can be read as right-associative, showing that this is in fact a higher-order function returning a function of type B -> C:

    f :: A -> (B -> C)
    

    A non-curried function of two arguments would instead have a type like this:

    f' :: (A, B) -> C
    

    So any time you use partial application in Haskell, you're working with higher-order functions.

提交回复
热议问题