{"id":13616463,"url":"https://github.com/loophp/church-encoding","last_synced_at":"2025-05-06T22:20:36.971Z","repository":{"id":38331867,"uuid":"305489201","full_name":"loophp/church-encoding","owner":"loophp","description":"Church encoding in PHP","archived":false,"fork":false,"pushed_at":"2025-04-15T12:31:31.000Z","size":96,"stargazers_count":4,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-15T13:35:19.662Z","etag":null,"topics":["church-encoding","educational","functional-programming","learning"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/loophp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"drupol","custom":["https://www.paypal.me/drupol"]}},"created_at":"2020-10-19T19:15:08.000Z","updated_at":"2024-10-09T14:19:24.000Z","dependencies_parsed_at":"2024-05-28T09:25:17.067Z","dependency_job_id":"3956f0af-af4c-4344-b232-4ec91c37af9c","html_url":"https://github.com/loophp/church-encoding","commit_stats":{"total_commits":46,"total_committers":3,"mean_commits":"15.333333333333334","dds":"0.32608695652173914","last_synced_commit":"d224e0c6ceabbaa9f663ef8149277aa8b5dba039"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loophp%2Fchurch-encoding","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loophp%2Fchurch-encoding/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loophp%2Fchurch-encoding/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loophp%2Fchurch-encoding/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loophp","download_url":"https://codeload.github.com/loophp/church-encoding/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252777132,"owners_count":21802545,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["church-encoding","educational","functional-programming","learning"],"created_at":"2024-08-01T20:01:28.868Z","updated_at":"2025-05-06T22:20:36.935Z","avatar_url":"https://github.com/loophp.png","language":"PHP","readme":"[![Latest Stable Version][latest stable version]][packagist]\n [![GitHub stars][github stars]][packagist]\n [![Total Downloads][total downloads]][packagist]\n [![GitHub Workflow Status][github workflow status]][github actions]\n [![Scrutinizer code quality][code quality]][code quality link]\n [![Type Coverage][type coverage]][sheperd type coverage]\n [![Code Coverage][code coverage]][code quality link]\n [![License][license]][packagist]\n [![Donate!][donate github]][github sponsor]\n [![Donate!][donate paypal]][paypal sponsor]\n\n# Church Encoding\n\nIn mathematics, **Church encoding** is a means of representing data and operators in the Lambda calculus. The Church numerals are a representation of the natural numbers using Lambda notation. The method is named for [Alonzo Church][Alonzo Church], who first encoded data in the Lambda calculus this way.\n\nThe Church encoding is not intended as a practical implementation of primitive data types. Its use is to show that other primitive data types are not required to represent any calculation. The completeness is representational...more on [Wikipedia][church encoding wikipedia].\n\n## History\n\nThis library has been done for personal educational purpose and made public, it has been inspired by the work of [Marcelo Camargo][Marcelo Camargo].\nThe code is available through Composer(via [Packagist][packagist]) just in case, but I doubt this will be useful for anyone beside learning purposes.\n\n## Usage\n\n`composer require loophp/church-encoding`\n\n## Documentation\n\n### Church numerals\n\nAssume we have a programming language that doesn’t support numbers or booleans: a **Lambda** is the only value it provides. It is an interesting question whether we can nonetheless create some system that allows us to count, add, multiply, and do all the other things we do with numbers.\n\nChurch numerals use Lambdas to create a representation of numbers.\n\nThe idea is closely related to the functional representation of natural numbers, i.e. to have a natural number representing `zero` and a function `succ` that returns the successor of the natural number it was given. The choice of `zero` and `succ` is arbitrary, all that matters is that there is a `zero` and that there is a function that can provide the successor. Church numerals are an extension of this.\n\nAll Church numerals are functions with two parameters: `λf . λx . something`\n\nThe first parameter `f` is the successor function that should be used. The second parameter `x` is the value that represents zero.\n\nTherefore, the Church numeral for zero is: `C0=λf . λx . x`\n\nWhenever it is applied, it returns the value representing zero. The Church numeral for one applies the successor function to the value representing zero exactly once: `C1=λf . λx . f x`.\n\nThe Church numerals that follow just have additional applications of the successor function\n\nIt is important to note that in this minimal Lambda calculus, we can’t really do very much with these Church numerals. We can count and add and multiply, but to understandthe result, we have to count the applications of the successor function.\n\n### Church booleans\n\nWe can ask the same question we asked about numbers about booleans. Can we represent them using just functions?\n**Yes we can**, and in a way very similar to Church numerals.\nA Church boolean is a function with two parameters, the first represents what the function should return if it is `true`,\nthe second what the function should return if it is `false`:\n\n* `true = λx . λy . x`\n* `false = λx . λy . y`\n\nJust like with Church numerals, we can also perform arithmetic with Church booleans.\n\nIt is easy to define functions for `and`, `or`, and `not`\n\n* `and` = `λM . λN . M (N true false) false`\n* `or` = `λM . λN . M true (N true false)`\n* `not` = `λM . M false true`\n\n### References\n\n* Types And Programming Languages ([TAPL][tapl])\n* Structure and Interpretation of Computer Programs ([SICP][sicp])\n* Lectures of [Robert ”Corky” Cartwright][robert corky cartwright]\n* Gabriel Lebec: [Part 1][gabriel lebec p1] and [Part 2][gabriel lebec p2]\n* Package [loophp/combinator][loophp/combinator]\n* [Lambda calculus on Wikipedia][lambda calculus wikipedia]\n* [Church encoding on Wikipedia][church encoding wikipedia]\n\n## Code quality, tests and benchmarks\n\nEvery time changes are introduced into the library, [Github][github actions] run the\ntests.\n\nThe library has tests written with [PHPSpec][phpspec].\nFeel free to check them out in the `spec` directory. Run `composer phpspec` to trigger the tests.\n\nBefore each commit some inspections are executed with [GrumPHP][grumphp],\nrun `composer grumphp` to check manually.\n\nThe quality of the tests is tested with [Infection][infection] a PHP Mutation testing\nframework,  run `composer infection` to try it.\n\nStatic analysers are also controlling the code. [PHPStan][phpstan] and\n[PSalm][psalm] are enabled to their maximum level.\n\n## Contributing\n\nFeel free to contribute by sending Github pull requests. I'm quite reactive :-)\n\nIf you can't contribute to the code, you can also sponsor me on [Github][github sponsor] or [Paypal][paypal sponsor].\n\n## Changelog\n\nSee [CHANGELOG.md][changelog-md] for a changelog based on [git commits][git-commits].\n\nFor more detailed changelogs, please check [the release changelogs][changelog-releases].\n\n[Alonzo Church]: https://en.wikipedia.org/wiki/Alonzo_Church\n[Marcelo Camargo]: https://github.com/haskellcamargo\n\n[latest stable version]: https://img.shields.io/packagist/v/loophp/church-encoding.svg?style=flat-square\n[packagist]: https://packagist.org/packages/loophp/church-encoding\n\n[github stars]: https://img.shields.io/github/stars/loophp/church-encoding.svg?style=flat-square\n\n[total downloads]: https://img.shields.io/packagist/dt/loophp/church-encoding.svg?style=flat-square\n\n[github workflow status]: https://img.shields.io/github/workflow/status/loophp/church-encoding/Continuous%20Integration?style=flat-square\n[github actions]: https://github.com/loophp/church-encoding/actions\n\n[code quality]: https://img.shields.io/scrutinizer/quality/g/loophp/church-encoding/master.svg?style=flat-square\n[code quality link]: https://scrutinizer-ci.com/g/loophp/church-encoding/?branch=master\n\n[type coverage]: https://shepherd.dev/github/loophp/church-encoding/coverage.svg\n[sheperd type coverage]: https://shepherd.dev/github/loophp/church-encoding\n\n[code coverage]: https://img.shields.io/scrutinizer/coverage/g/loophp/church-encoding/master.svg?style=flat-square\n[code quality link]: https://img.shields.io/scrutinizer/quality/g/loophp/church-encoding/master.svg?style=flat-square\n\n[license]: https://img.shields.io/packagist/l/loophp/church-encoding.svg?style=flat-square\n\n[donate github]: https://img.shields.io/badge/Sponsor-Github-brightgreen.svg?style=flat-square\n[github sponsor]: https://github.com/sponsors/drupol\n\n[donate paypal]: https://img.shields.io/badge/Sponsor-Paypal-brightgreen.svg?style=flat-square\n[paypal sponsor]: https://www.paypal.me/drupol\n\n[church encoding wikipedia]: https://en.wikipedia.org/wiki/Church_encoding\n\n[phpspec]: http://www.phpspec.net/\n[grumphp]: https://github.com/phpro/grumphp\n[infection]: https://github.com/infection/infection\n[phpstan]: https://github.com/phpstan/phpstan\n[psalm]: https://github.com/vimeo/psalm\n[changelog-md]: https://github.com/loophp/church-encoding/blob/master/CHANGELOG.md\n[git-commits]: https://github.com/loophp/church-encoding/commits/master\n[changelog-releases]: https://github.com/loophp/church-encoding/releases\n\n[gabriel lebec p1]: https://www.youtube.com/watch?v=3VQ382QG-y4\n[gabriel lebec p2]: https://www.youtube.com/watch?v=pAnLQ9jwN-E\n[robert corky cartwright]: https://www.cs.rice.edu/~cork/\n[tapl]: https://www.cis.upenn.edu/~bcpierce/tapl/\n[sicp]: https://en.wikipedia.org/wiki/Structure_and_Interpretation_of_Computer_Programs\n[loophp/combinator]: https://github.com/loophp/combinator\n[lambda calculus wikipedia]: https://en.wikipedia.org/wiki/Lambda_calculus\n","funding_links":["https://github.com/sponsors/drupol","https://www.paypal.me/drupol"],"categories":["PHP"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floophp%2Fchurch-encoding","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floophp%2Fchurch-encoding","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floophp%2Fchurch-encoding/lists"}