Haskell function composition

后端 未结 6 1486
梦如初夏
梦如初夏 2021-02-01 14:42

I am reading this tutorial on Haskell. They define function composition as the following:

(.)                     :: (b->c) -> (a->b) -> (a-         


        
6条回答
  •  孤城傲影
    2021-02-01 15:23

    The composition of f and g is a function that first applies g to its argument, then f to the value returned by g. It then returns the return value of f.

    This identity may be enlightening:

    f (g x) = (f . g) x

    If you have a Java/C background, consider this example:

    int f(int x);
    int g(int x);
    int theComposition(int x) { return f(g(x)); }
    

提交回复
热议问题