GithubHelp home page GithubHelp logo

risto-stevcev / haskell-church-encodings Goto Github PK

View Code? Open in Web Editor NEW
24.0 3.0 3.0 21 KB

:cyclone: Church encodings written in Haskell

Home Page: https://github.com/Risto-Stevcev/haskell-church-encodings

License: BSD 3-Clause "New" or "Revised" License

Haskell 99.36% Makefile 0.64%
haskell church numerals encoding encodings church-encodings

haskell-church-encodings's Introduction

Church Encodings in Haskell

This exercise was to demonstrate and play around with church encodings in a more involved way, and as a way for me to gain experience with haskell and it's type system.

Church encodings were developed by the late and famous Alonzo Church. Church is probably most well known for inventing lambda calculus, a formal branch of mathematics that introduces the notion of lambdas, or anonymous functions. You may have used them before when programming.

Church encodings are a very interesting development arising from lambda calculus. Church found out that every concept in programming languages can be represented using functions! everything from boolean logic, conditional statements, numbers (natural, integer, real, complex, imaginary), and even loops (infinite loops also)!

The most interesting thing about this is that numbers aren't anything special in math, they're just convenient placeholders. Math is really just logic in it's purest form.

Rank1Types

My first attempt at fleshing out church encodings involved absolutely no type declarations, just to see how far I can go with Haskell's Hindley-Milner type system before I needed to introduce more complicated workings. I got as far as I could go without church subtraction. It turns out that the type system starts to choke just at that type because it's too polymorphic.

RankNTypes

This is my final attempt and has worked for every church encoding I have attempted so far. I translated all of the encodings from the church encoding wikipedia page.

So far I've translated church booleans, church boolean operators, church conditionals, church comparison operators, church numerals (natural numbers), church arithmetic operators (for natural numbers), church lists, church 2-tuples, church integers, loops with the y-combinator, and church arithmetic operators (for integers) less the exponential and factorial operators.

I can still translate the leftover operators for integers, as well as real, rational, imaginary and complex numbers.

Credits

I'd like to give credit where it's due:

  • Martin's Blog for starting me off in the right direction.

  • luqui's StackOverflow post for uncovering how to move past the limitation's of Haskell's Hindley-Milner type system in order to implement church subtraction (and everything that follows it).

  • The church encoding wikipedia page for being so incredibly detailed and informative.

And finally, Church himself, for being such a badass!

Alonzo Church
Alonzo Church

haskell-church-encodings's People

Contributors

risto-stevcev avatar tkaden4 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.