package ppx_compose

  1. Overview
  2. Docs
Inlined function composition

Install

Dune Dependency

Authors

Maintainers

Sources

ppx_compose-v0.1.0.tbz
sha256=87f063215e9f06d4433302f492fb35c72b25f09737ba748d9df3542f562f9a7f
sha512=7c8c14f5b28c5173e74bec8176b59697cc1ec7f48ccbbab4656b083259fde6666b4399a74b13fc3605d50cb48ff4c11ff8b96fafa6ef4af5613eab5ccf5a49f1

Description

ppx_compose is a simple syntax extension which rewrites code containing function compositions into composition-free code, effectively inlining the composition operators. The following two operators are supported

let (%) g f x = g (f x)
let (%>) f g x = g (f x)

Corresponding definitions are not provided, so partial applications of (%) and (%>) will be undefined unless you provide the definitions.

The following rewrites are done:

  • A composition occurring to the left of an application is reduced by applying each term of the composition from right to left to the argument, ignoring associative variations.

  • A composition which is not the left side of an application is first turned into one by η-expansion, then the above rule applies.

  • Any partially applied composition operators are passed though unchanged.

E.g.

h % g % f ==> (fun x -> h (f (g x)))
h % (g % f) ==> (fun x -> h (f (g x)))
(g % f) (h % h) ==> g (f (fun x -> h (h x)))

Published: 22 Dec 2019

README

README.md

ppx_compose - Inlined Function Composition

ppx_compose is a simple syntax extension which rewrites code containing function compositions into composition-free code, effectively inlining the composition operators. The following two operators are supported

let (%) g f x = g (f x)
let (%>) f g x = g (f x)

Corresponding definitions are not provided, so partial applications of (%) and (%>) will be undefined unless you provide the definitions.

The following rewrites are done:

  • A composition occurring to the left of an application is reduced by applying each term of the composition from right to left to the argument, ignoring associative variations.

  • A composition which is not the left side of an application is first turned into one by η-expansion, then the above rule applies.

  • Any partially applied composition operators are passed though unchanged.

E.g.

h % g % f ==> (fun x -> h (f (g x)))
h % (g % f) ==> (fun x -> h (f (g x)))
(g % f) (h % h) ==> g (f (fun x -> h (h x)))

Is It Needed?

Recent flambda-enabled compilers can inline the following alternative definitions of the composition operators [1]:

let (%) g f = (); fun x -> g (f x)
let (%>) f g = (); fun x -> g (f x)

so this syntax extension will likely be retired at some point.

Dependencies (3)

  1. ocaml-migrate-parsetree >= "1.5.0" & < "2.0.0"
  2. dune >= "1.1"
  3. ocaml >= "4.02.3"

Dev Dependencies

None

Used by

None

Conflicts

None

OCaml

Innovation. Community. Security.