What does a fullstop or period or dot (.) mean in Haskell?

蓝咒 提交于 2019-11-28 21:16:49
Pratik Deoghare

f(g(x))

is

in mathematics : f ∘ g (x)

in haskell : ( f . g ) (x)

Alex Jenter

It means function composition. See this question.

Note also the f.g.h x is not equivalent to (f.g.h) x, because it is interpreted as f.g.(h x) which won't typecheck unless (h x) returns a function.

This is where the $ operator can come in handy: f.g.h $ x turns x from being a parameter to h to being a parameter to the whole expression. And so it becomes equivalent to f(g(h x)) and the pipe works again.

. is a higher order function for function composition.

Prelude> :type (.)
(.) :: (b -> c) -> (a -> b) -> a -> c
Prelude> (*2) . (+1) $ 1
4
Prelude> ((*2) . (+1)) 1
4

"The period is a function composition operator. In general terms, where f and g are functions, (f . g) x means the same as f (g x). In other words, the period is used to take the result from the function on the right, feed it as a parameter to the function on the left, and return a new function that represents this computation."

Source: Google search 'haskell period operator'

It is a function composition: link

Function composition (the page is pretty long, use search)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!