Dot Operator in Haskell: need more explanation

后端 未结 6 1055
旧时难觅i
旧时难觅i 2020-11-30 23:50

I\'m trying to understand what the dot operator is doing in this Haskell code:

sumEuler = sum . (map euler) . mkList

The entire source code

6条回答
  •  不知归路
    2020-12-01 00:35

    The . operator is used for function composition. Just like math, if you have to functions f(x) and g(x) f . g becomes f(g(x)).

    map is a built-in function which applies a function to a list. By putting the function in parentheses the function is treated as an argument. A term for this is currying. You should look that up.

    What is does is that it takes a function with say two arguments, it applies the argument euler. (map euler) right? and the result is a new function, which takes only one argument.

    sum . (map euler) . mkList is basically a fancy way of putting all that together. I must say, my Haskell is a bit rusty but maybe you can put that last function together yourself?

提交回复
热议问题