feat: lambda

This commit is contained in:
2026-02-09 20:14:31 -05:00
parent c6d7dd56ff
commit afd4d27695
3 changed files with 13 additions and 3 deletions

View File

@@ -6,12 +6,18 @@ import (
"git.maximhutz.com/max/lambda/pkg/codec"
)
// A Codec is a [codec.Codec] that serializes lambda calculus expressions.
// Decode is not implemented and always returns an error.
// Encode stringifies an expression using standard lambda notation.
type Codec struct{}
// Decode parses a string as lambda calculus. Returns an error if it cannot.
func (m Codec) Decode(string) (Expression, error) {
return nil, fmt.Errorf("unimplemented")
}
// Encode turns a lambda calculus expression into a string. Returns an error if
// it cannot.
func (m Codec) Encode(e Expression) (string, error) {
return Stringify(e), nil
}

View File

@@ -1,11 +1,13 @@
// Package lambda defines the AST for the untyped lambda calculus.
package lambda
// Expression is the interface for all lambda calculus expression types.
// It embeds the general expr.Expression interface for cross-mode compatibility.
// An Expression is a node in the lambda calculus abstract syntax tree.
// It is a sealed interface; only types in this package may implement it.
type Expression interface {
expression()
}
// An Abstraction binds a single parameter over a body expression.
type Abstraction struct {
Parameter string
Body Expression
@@ -13,6 +15,7 @@ type Abstraction struct {
func (a Abstraction) expression() {}
// An Application applies an abstraction to a single argument.
type Application struct {
Abstraction Expression
Argument Expression
@@ -20,6 +23,7 @@ type Application struct {
func (a Application) expression() {}
// A Variable is a named reference to a bound or free variable.
type Variable struct {
Name string
}