|
| 1 | +# functional |
| 2 | + |
| 3 | +Functional programming in C++ |
| 4 | + |
| 5 | +## Why |
| 6 | + |
| 7 | +The purpose of this library is to exercise an approach to functional programming in C++ on top of the existing `std` C++ `std::expected` and `std::optional`, with the aim of eventually extending the future versions of the C++ standard library with the functionality found to work well. |
| 8 | + |
| 9 | +## How |
| 10 | + |
| 11 | +The approach is to take the existing `std` types in the C++ standard library (when appropriate) and extend them (via inheritance) with the facilities useful in writing functional style programs. Eventually, the proposed functionality will be (hopefully) folded into the existing `std` types and new `std` types will be added. |
| 12 | + |
| 13 | +## What |
| 14 | + |
| 15 | +The library provides following utilities: |
| 16 | + |
| 17 | +* functors - extensible system of encapsulation of monadic operations, expressed with a pipe `operator |` |
| 18 | +* sum of types - coproduct of types, similar to `std::variant` but indexed by type rather than order, composes with the product of types |
| 19 | +* choice monad - monad built on top of the coproduct of types, dispatch by overloading rules |
| 20 | +* pack - product of types, similar to `std::tuple`, composes with the coproduct of types |
| 21 | +* composition - monadic types containing arbitrary types, products or coproducts can be combined with `operator &` |
| 22 | +* multidispatch - dispatch any valid combination of product(s) and coproduct(s) to a function, based on overloading rules |
| 23 | +* graded monad - integrate coproduct into `optional` and `expected` monads, enables extensible `expected` error types |
| 24 | +* ... and more |
| 25 | + |
| 26 | +## Acknowledgments |
| 27 | + |
| 28 | +* Gašper Ažman, for providing the inspiration in ["(Fun)ctional C++ and the M-word"][gasper-functional-presentation] |
| 29 | +* Bartosz Milewski, for taking the time to explain [parametrised and graded monads][parametrised-and-graded-monads] and [effect systems][effect-systems] |
| 30 | +* [Ripple][ripple], for allowing the main author the time to work on this library |
| 31 | + |
| 32 | +[gasper-functional-presentation]: https://youtu.be/Jhggz8rtHbk?si=T-3DXPcvgE_Y5cpH |
| 33 | +[parametrised-and-graded-monads]: https://arxiv.org/pdf/2001.10274.pdf |
| 34 | +[effect-systems]: https://www.doc.ic.ac.uk/~dorchard/publ/haskell14-effects.pdf |
| 35 | +[ripple]: https://ripple.com/ |
0 commit comments