From afd4d27695b975d93846aa598c9de2a97775ff88 Mon Sep 17 00:00:00 2001 From: "M.V. Hutz" Date: Mon, 9 Feb 2026 20:14:31 -0500 Subject: [PATCH] feat: lambda --- cmd/lambda/registry.go | 2 +- pkg/lambda/codec.go | 6 ++++++ pkg/lambda/lambda.go | 8 ++++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/cmd/lambda/registry.go b/cmd/lambda/registry.go index 404eda8..bff4fa2 100644 --- a/cmd/lambda/registry.go +++ b/cmd/lambda/registry.go @@ -19,7 +19,7 @@ func GetRegistry() *registry.Registry { (registry.RegisterEngine(r, normalorder.NewProcess, "normalorder", "lambda")) // Marshalers - (registry.RegisterCodec(r, lambda.Marshaler{}, "lambda")) + (registry.RegisterCodec(r, lambda.Codec{}, "lambda")) (registry.RegisterCodec(r, saccharine.Codec{}, "saccharine")) return r diff --git a/pkg/lambda/codec.go b/pkg/lambda/codec.go index c1c96bb..32d19df 100644 --- a/pkg/lambda/codec.go +++ b/pkg/lambda/codec.go @@ -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 } diff --git a/pkg/lambda/lambda.go b/pkg/lambda/lambda.go index d92ca4d..e8cfef0 100644 --- a/pkg/lambda/lambda.go +++ b/pkg/lambda/lambda.go @@ -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 }