-module(apcl). -export([identity/1, constant/1, compose/2, apply/1, flip/1, left/2, right/2, recombine/3, under/2]). %% @doc Returns its argument. identity(X) -> X. %% @doc Returns a function which returns `x' no matter what it is passed. constant(X) -> fun(_Y) -> X end. %% @doc Performs function composition. compose(F, G) -> fun(X) -> F(G(X)) end. %% @doc Returns a function which applies `F' to `Xs'. apply(F) -> fun(Xs) -> apply(F, Xs) end. %% @doc Returns a function which permutes its arguments and applies `F' to them. flip(F) -> fun(X, Y) -> F(Y, X) end. %% @doc Given two arguments, returns the left one. left(X, _Y) -> X. %% @doc Given two arguments, returns the right one. right(_X, Y) -> Y. %% @doc Returns a function that applies `G' and `H' to its arguments, taking the resulting values as the arguments to `F'. recombine(F, G, H) -> fun(X) -> F(G(X), H(X)) end. %% @doc Returns a function that applies `G' to each of its arguments, taking the resulting values as the arguments to `F'. under(F, G) -> fun(X, Y) -> F(G(X), G(Y)) end.