A Golang runtime and compilation backend for Delta Interaction Nets.
at main 49 lines 806 B view raw
1package lambda 2 3import "fmt" 4 5// Term represents a lambda calculus term. 6type Term interface { 7 String() string 8} 9 10// Var represents a variable usage. 11type Var struct { 12 Name string 13} 14 15func (v Var) String() string { 16 return v.Name 17} 18 19// Abs represents an abstraction (lambda). 20type Abs struct { 21 Arg string 22 Body Term 23} 24 25func (a Abs) String() string { 26 return fmt.Sprintf("(%s: %s)", a.Arg, a.Body) 27} 28 29// App represents an application. 30type App struct { 31 Fun Term 32 Arg Term 33} 34 35func (a App) String() string { 36 return fmt.Sprintf("(%s %s)", a.Fun, a.Arg) 37} 38 39// Let represents a let binding (sugar for application). 40// let x = Val in Body -> (\x. Body) Val 41type Let struct { 42 Name string 43 Val Term 44 Body Term 45} 46 47func (l Let) String() string { 48 return fmt.Sprintf("let %s = %s; %s", l.Name, l.Val, l.Body) 49}