fredoverflow
fredoverflow

Reputation: 263088

function composition with reverse syntax

If I want to apply f first and g second, I have to write:

g . f

Is there another standard syntax that would allow me to write the functions in the reverse order?

f <whatever> g

I know I can just invent my own syntax:

compose f g x = g (f x)

and then use it like this:

f `compose` g

But I would rather use a standard library facility.

Upvotes: 57

Views: 7724

Answers (2)

gregorias
gregorias

Reputation: 363

In addtition to >>>, some libraries provide their own version of this function, for example:

You may use Hoogle to find examples of functions with a specific signature. For your exact question you can use hoogle.haskell.org/?hoogle=(a -> b) -> (b -> c) -> (a -> c).

Upvotes: 2

Josh Lee
Josh Lee

Reputation: 177530

f >>> g from Control.Arrow.

Upvotes: 62

Related Questions