Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/paurkedal/ppx_compose
Composition Inlining for OCaml
https://github.com/paurkedal/ppx_compose
combinator function-composition ocaml optimization ppx-rewriter
Last synced: 5 days ago
JSON representation
Composition Inlining for OCaml
- Host: GitHub
- URL: https://github.com/paurkedal/ppx_compose
- Owner: paurkedal
- License: lgpl-3.0
- Created: 2017-03-16T23:03:36.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2021-10-12T19:41:45.000Z (over 3 years ago)
- Last Synced: 2025-01-10T22:47:36.952Z (15 days ago)
- Topics: combinator, function-composition, ocaml, optimization, ppx-rewriter
- Language: OCaml
- Size: 42 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: COPYING
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/paurkedal/ppx_compose.svg?branch=master)](https://travis-ci.org/paurkedal/ppx_compose)
## `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
```ocaml
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.
```ocaml
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]]:
```ocaml
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.[1]: https://discuss.ocaml.org/t/ann-ppx-compose-0-0-3/345