Code Monkey home page Code Monkey logo

ppx_compose's Introduction

Build Status

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.

ppx_compose's People

Contributors

paurkedal avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.