Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I thought conflating the dot with function composition wouldn't be too bad because they're similar in a sense, but then I remembered that the two work in the reverse order in the sense that:

(.a.b.c) . (.d.e.f) = (.d.e.f.a.b.c)

If you use -> both for the member function and for reverse function composition you'd get:

(->a->b->c) -> (->d->e->f) = (->a->b->c->d->e->f)

which is somehow nicer, especially because accessing a member and composing functions become the same thing when you view a value as the unique function sending the initial object to that value.

But unfortunately we've spent centuries composing functions the wrong way round, so now we're forced to deal with the consequences.



You can do left to right function composition with (>>>)

Given functions f, g , h,

h >>> g >>> f is equivalent to f . g . h

Its from Control.Category, so it generalizes to other things, but for functions specifically its left to right composition.

( theres also (<<<), which in this case is identical to (.) )

( Also present in Control.Arrow . Why? I dont know this topic well enough to explain. My understanding is limited to what these operators mean in the specific of functions. Functions(->) are a type as well, so they can be instances of typeclasses. for example

  instance Functor ((->) r) where  
        fmap = (.)

)


Almost, but you are conflating function composition (lambda x: lambda y: f(x(y))) with function application (lambda x: f(x)).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: