Skip to content

SergioBonatto/Phi

Repository files navigation

Phi - A Lambda Calculus Interpreter

Phi is a lightweight interpreter for pure lambda calculus, implemented in Haskell. It provides a simple yet powerful environment for experimenting with lambda calculus expressions.

Key Features

  • Pure Lambda Calculus Support: Implements β-reduction and variable substitution
  • Lazy Evaluation: Uses Haskell's natural lazy evaluation strategy
  • Robust Parser: Handles nested expressions and complex lambda terms
  • Comment Support: Handles both single-line (--) and multi-line ({- -}) comments
  • Maximum Step Limit: Prevents infinite recursion with configurable step limits

Installation

Prerequisites

Building

# Clone the repository
git clone https://github.com/sergiobonatto/phi.git
cd phi

# Build the project
stack build

# install the project
stack install

Usage

Basic Syntax

-- Single line comments start with --
{- Multi-line comments
   use {- and -} -}

-- Basic boolean operations
let true  = λt.λf.t
let false = λt.λf.f
let neg   = λb. (b false true)

-- List implementation using Scott encoding
let cons = λh.λt.λc.λn. (c h (t c n))
let nil  = λc.λn.n

Command Line Interface

stack exec phi -- <file> [-s] [-c]

Options:
  -s    Display execution statistics (reduction steps and time)
  -c    Show final environment state

Project Structure

The interpreter follows a modular design with clear separation of concerns:

1. Core Components

2. Parsing Pipeline

3. Processing

Testing

The project includes a test suite covering the main components:

stack test

Tests include:

  • Tokenization
  • Expression parsing
  • Definition processing
  • Evaluation logic

License

BSD-3-Clause License.

About

A Lambda Calculus Interpreter

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published