top | item 34287248

(no title)

jcmoyer | 3 years ago

Is the Rust compose backwards? Normally I would expect compose(f,g)(x) = (f∘g)(x) = f(g(x)), but in this post it's g(f(x)).

In Haskell for instance,

    (+2) . (*10) $ 2
    => 22

discuss

order

stephencanon|3 years ago

This is purely notational convention and both interpretations are pretty widely attested in different subfields. The composition circle operator is most often the Haskell order (“f after g”), but “compose” can refer to either.

kadoban|3 years ago

Haskell's compose being in that direction ends up fairly annoying, IMO. That's not the direction we think about a chain of functions, 90+% of the time, so you end up having to type the next thing in the chain, then go backwards over everything you just typed to do the next step.

Thankfully in Haskell you can just define your own, but it's annoying and then harder to share than if one existed in prelude. IIRC (<<<) or one of them is a more general backwards compose, but the precedence ends up working poorly so it's not a good fix.