Alex Rivera | Logout

Haskell: Why is ((.).(.)) f g equal to f . g x?

Asked 2013-02-05T12:36:09.357
8

Could you please explain the meaning of the expression ((.).(.))? As far as I know (.) has the type (b -> c) -> (a -> b) -> a -> c.

Edit
Report

1 Answer

2

You've got an answer already, here's a slightly different take on it.

In combinatory logic (.) is B-combinator : Babc = a(bc). When writing combinator expressions it is customary to assume that every identifier consists of one letter only, and omit white-space in application, to make the expressions more readable. Of course the usual currying applies: abcde is (((ab)c)d)e and vice versa.

(.) is B, so ((.) . (.)) == (.) (.) (.) == BBB. So,

BBBfgxy = B(Bf)gxy = (Bf)(gx)y = Bf(gx)y = (f . g x) y    
 abc        a  bc                 a b  c                  

We can throw away both ys at the end (this is known as eta-reduction: Gy=Hy --> G=H, if y does not appear inside H1). But also, another way to present this, is

BBBfgxy = B(Bf)gxy = ((f .) . g) x y = f (g x y)     -- (.) f == (f .)
-- compare with:       (f .) g x = f (g x)

((f .) . g) x y might be easier to type in than ((.).(.)) f g x y, but YMMV.


1 For example, with S combinator, defined as Sfgx = fx(gx), without regard for that rule we could write

Sfgx = fx(gx) = B(fx)gx = (f x . g) x
Sfg = B(fx)g = (f x . g)   --- WRONG, what is "x"?

which is nonsense.

answered 2013-02-06T10:45:17.050

Your Answer