In functional programming, given a function f and a function g we can define a function . (compose):

let (.) f g = fun x -> g (f x)

Is there a term for the function which applies arguments in the opposite order? What would be an appropriate term for the # operator in the following definition?

let (#) f g = fun x -> f (g x)

  • 2
    Isn't this just flip (.)? – Jörg W Mittag May 11 '16 at 17:49
  • @JörgWMittag yes, that's a way to define it... but "flip compose" isn't a nice name for the function! – AlexFoxGill May 11 '16 at 18:01
  • I don't think it has a name. g ∘ f is sometimes pronounced "g after f" or "g following f", so that would suggest pronouncing g ♯ f "g before f" or "f following g". But given that it's really just the same as with its arguments reversed, I don't think there's a specific name for it. – Jörg W Mittag May 11 '16 at 18:06
  • 1
    Related: programmers.stackexchange.com/questions/198575/… – Jack May 11 '16 at 18:35
  • 1
    One terminology that's in common use for this is distinguishing between right-to-left and left-to-right composition. – sacundim May 26 '16 at 20:29

There isn't a standard name.

Haskell doesn't even bother defining it, but as Jörg said, you can easily define it yourself as

flip (.)

F# defines it as >> and calls it the "forward composition operator." Scala defines it as the andThen method, but doesn't describe it further. If you looked at 10 more functional languages, you'd probably get 10 different answers.

Unfortunately, functional programming borrowed most of its terms from mathematics, and mathematicians were satisfied with writing function composition "backwards."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.