Giter Site home page Giter Site logo

lambdacalculus's Introduction

Lambda Calculus

A small cabal package for haskell featuring the basic operations of lambda calculus.

Feature List

  • Representation of objects in lambda calculus as data structures
  • IO of lambda expressions
  • Validity check of lambda expressions
  • Stepwise evaluation of lambda expressions

Installation

Installation of this library via cabal package manager:

cabal instal --lib

This will register the package for GHC as well.

Usage

After a succeccfull installation all modules are known to and importable from within GHC/GHCI.

Modules

  • Lambda.Data contains all data structures representing the lambda calculus and output functions (show)
  • Lambda.Parse contains a parser function for all data structures
  • Lambda.Evaluation contains functions related to expression evaluation

Notation

The standard notation λx. λy. x y is represented as \x. (\y. (x y)) with explicit parentheses around each function body if more than one term is present and exactly one parameter per function. Other term lists have to be placed within parentheses as well: (λx. λy. x y) a b becomes (\x. (\y. (x y)) a b).

Examples

Input/Output

Use parse to parse a grammatical data structure like word (top level structure):

> import Lambda.Parse
> parse word "\\a. \\b. (a b)"
Just (\a. (\b. (a b)))
>

Printing is implicit for each line but one can use show to turn a grammatical data structure into a string as a in:

> import Lambda.Parse
> w = parse word "\\a. \\b. (a b)"
> show w
"Just (\a. (\b. (a b)))"
>

Check Validity

To check the validity of a lambda expression use valid as in:

> import Lambda.Parse
> import Lambda.Evaluate
> import Data.Maybe
> w = w = fromJust (parse word "(\\x. \\y. (x y) \\y. (y z))")
> valid w
True
> w = w = fromJust (parse word "(\\x. \\x. (x y) \\y. (y z))")
> valid w
False
> 

Evaluation (Stepwise)

To perform a single evaluation step (for any valid lambda expression) use eval as in:


> import Lambda.Evaluate
> import Lambda.Parse
> import Data.Maybe
> w = fromJust $ parse word "(\\x. \\y. (x y) a b)"
> iterate eval w !! 0
((\x. (\y. (x y))) a b)
> iterate eval w !! 1
((\y. (a y)) b)
> iterate eval w !! 2
(a b)
> iterate eval w !! 3
(a b)
>

Dependencies

  • haskell compiler: ghc v4.9.0.0 or newer
    • archlinux: ghc package (may require further packages)
  • haskell package manager: cabal v2.4 or newer

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.