feat: lambda
This commit is contained in:
@@ -19,7 +19,7 @@ func GetRegistry() *registry.Registry {
|
|||||||
(registry.RegisterEngine(r, normalorder.NewProcess, "normalorder", "lambda"))
|
(registry.RegisterEngine(r, normalorder.NewProcess, "normalorder", "lambda"))
|
||||||
|
|
||||||
// Marshalers
|
// Marshalers
|
||||||
(registry.RegisterCodec(r, lambda.Marshaler{}, "lambda"))
|
(registry.RegisterCodec(r, lambda.Codec{}, "lambda"))
|
||||||
(registry.RegisterCodec(r, saccharine.Codec{}, "saccharine"))
|
(registry.RegisterCodec(r, saccharine.Codec{}, "saccharine"))
|
||||||
|
|
||||||
return r
|
return r
|
||||||
|
|||||||
@@ -6,12 +6,18 @@ import (
|
|||||||
"git.maximhutz.com/max/lambda/pkg/codec"
|
"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{}
|
type Codec struct{}
|
||||||
|
|
||||||
|
// Decode parses a string as lambda calculus. Returns an error if it cannot.
|
||||||
func (m Codec) Decode(string) (Expression, error) {
|
func (m Codec) Decode(string) (Expression, error) {
|
||||||
return nil, fmt.Errorf("unimplemented")
|
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) {
|
func (m Codec) Encode(e Expression) (string, error) {
|
||||||
return Stringify(e), nil
|
return Stringify(e), nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
|
// Package lambda defines the AST for the untyped lambda calculus.
|
||||||
package lambda
|
package lambda
|
||||||
|
|
||||||
// Expression is the interface for all lambda calculus expression types.
|
// An Expression is a node in the lambda calculus abstract syntax tree.
|
||||||
// It embeds the general expr.Expression interface for cross-mode compatibility.
|
// It is a sealed interface; only types in this package may implement it.
|
||||||
type Expression interface {
|
type Expression interface {
|
||||||
expression()
|
expression()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// An Abstraction binds a single parameter over a body expression.
|
||||||
type Abstraction struct {
|
type Abstraction struct {
|
||||||
Parameter string
|
Parameter string
|
||||||
Body Expression
|
Body Expression
|
||||||
@@ -13,6 +15,7 @@ type Abstraction struct {
|
|||||||
|
|
||||||
func (a Abstraction) expression() {}
|
func (a Abstraction) expression() {}
|
||||||
|
|
||||||
|
// An Application applies an abstraction to a single argument.
|
||||||
type Application struct {
|
type Application struct {
|
||||||
Abstraction Expression
|
Abstraction Expression
|
||||||
Argument Expression
|
Argument Expression
|
||||||
@@ -20,6 +23,7 @@ type Application struct {
|
|||||||
|
|
||||||
func (a Application) expression() {}
|
func (a Application) expression() {}
|
||||||
|
|
||||||
|
// A Variable is a named reference to a bound or free variable.
|
||||||
type Variable struct {
|
type Variable struct {
|
||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user