Why is the dot written from right to left in Haskell?

If we have two functions, fand g, then in Haskell is h = f . gequivalent h x = f(g x). That is, the functions are applied from right to left at the entrance. Is there any fundamental reason why this happens from right to left, and not from left to right? That is why they did not make h = f . gequivalent h x = g(f x)instead?

EDIT: since others pointed to my equivalent functions where there was a wrong path, so I fixed them.

+4
source share
1 answer

First of all, there is an error in your [original, unedited] question:

h = f. g is equivalent to hx = g (fx)

- : h = f . g h x = f (g x).

, , , , , , ; . http://en.wikipedia.org/wiki/Function_composition:

[...] g ∘ f: X → Z, (g ∘ f) (x) = g (f (x)) x X.

- (f . g) x == f (g x) - , f g .


, " ", , . :

(.>) = flip (.)

Prelude> ((+1) .> (*2)) 3
8
Prelude> ((+1) . (*2)) 3
7

Control.Arrow.(>>>), , :

Prelude Control.Arrow> ((+1) >>> (*2)) 3
8
+14

Source: https://habr.com/ru/post/1584740/


All Articles