An open API service indexing awesome lists of open source software.

https://github.com/neu-rah/lpp

<λ++> type-level lambda calculus for C++ meta-programming
https://github.com/neu-rah/lpp

compile-time cpp-library idiom lambda-calculus metaprograming types

Last synced: 3 days ago
JSON representation

<λ++> type-level lambda calculus for C++ meta-programming

Awesome Lists containing this project

README

          

# <λ++>
#### turing-complete idiom to express types in C++

[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.me/ruihfazevedo)
[![License: MIT](https://img.shields.io/github/license/neu-rah/lpp)](https://spdx.org/licenses/MIT.html)

**see https://github.com/neu-rah/yolanda for a runtime/compile time alternative to this.**

Based on lambda calculus, therefor using functional paradigm on top of modern C++ metaprogramming. Expressions on this idiom are metaprogramming and evaluate at compile time, yelding C++ types as a result.

inspired by the excellent videos of @glebec (https://youtu.be/3VQ382QG-y4) (thank you!)

### Scope
This idiom uses lambda calculus as its background on a close cope with c++ templates.
It only operates at compile time.
Results in β normal form translate to C++ types (native or user defined).
So this expressions can only be used in replacement of C++ types.
A layer to provide `constexpr` values is available through dependent types.
It is therefor a turing-complete idiom to decide types at compile time.
Types have to be extracted after expression evaluation (::App) to yeld valid C++ types.
Using Lazyness, static immutable "data" (here expressed as c++ types) and partial application.

## lambda base

lambda calculus base [lambda core doc.](./LAMBDA.md)

## lpp

Syntatic sugar for "lambda.h"

because `Head` looks much better that `Expr::App`

[LPP doc.](./LPP.md)

## r-lambda

RCurry (runtime curry)
turns regular c++ functions into curry versions.

A C++ function that accepts lets say 2 arguments `a` and `b`, and returns `c` is then turned into a function that accepts one argument `a` and return a second function that accepts `b` and returns `c` (considering the previous `a`).

_curry is the only part implemented, and still testing. No lambda calculus yet_

```c++
#include
using namespace std;

#include //runtime lambda core
using namespace rlambda;

template
inline I _id(I i) {return i;}
template
constexpr auto id=RCurry),_id,I>();

//regular function with single param
int _d(int x){return x<<1;}
constexpr auto d=RCurry();
// constexpr auto d=typename decltype(fun(_d))::template curried;

//regular function with multiple param
int _m(int x,int y){return x*y;}
constexpr auto m=RCurry();

template constexpr auto _true=rK;

template O __false(O,O o) {return o;}
template constexpr auto _false=RCurry),__false,O,O>();

int main(int argc, char **argv) {
cout<<"d(2):"<(d)(1967:"<(d)(1967)<("Ok")("Fail")<("Fail")("Ok")<