A purely-functional programming language with Hindley-Milner type inference and `callcc`.
Go to file
James T. Martin 79e054700b
Make the printer smarter, separate intermediate AST data type.
* The expression printer now knows how to use `let`, multi-argument lambdas and applications, and block arguments when appropriate.
* There is a separate type, AbstractSyntax, which separates parsing/printing logic from removing/reintroducing the more advanced syntax described above.
* Expression is now its own module because its 'show' depends on AbstractSyntax,
  and I don't want the ast2expr/expr2ast stuff to be in the same module as the real lambda calculus stuff.
2020-11-03 13:43:43 -08:00
.github/workflows Add GitHub workflow. 2020-11-02 16:00:43 -08:00
app Make the printer smarter, separate intermediate AST data type. 2020-11-03 13:43:43 -08:00
src Make the printer smarter, separate intermediate AST data type. 2020-11-03 13:43:43 -08:00
test Make the printer smarter, separate intermediate AST data type. 2020-11-03 13:43:43 -08:00
.editorconfig Allow defining multiple variables with one `let`. 2020-11-03 11:33:35 -08:00
.gitignore Complexity was getting out of hand. Beginning a rewrite. Added tests. 2019-12-11 18:29:28 -08:00
LICENSE Initial commit. Some terms are still not evaluated correctly. 2019-08-15 10:42:24 -07:00
README.md Make the printer smarter, separate intermediate AST data type. 2020-11-03 13:43:43 -08:00
Setup.hs Initial commit. Some terms are still not evaluated correctly. 2019-08-15 10:42:24 -07:00
package.yaml Make the printer smarter, separate intermediate AST data type. 2020-11-03 13:43:43 -08:00
stack.yaml Make the printer smarter, separate intermediate AST data type. 2020-11-03 13:43:43 -08:00
stack.yaml.lock Make the printer smarter, separate intermediate AST data type. 2020-11-03 13:43:43 -08:00

README.md

James Martin's Lambda Calculus

This is a simple implementation of the untyped lambda calculus with an emphasis on clear, readable Haskell code.

Usage

Type in your expression at the prompt: >> . The expression will be evaluated to normal form and then printed. Exit the prompt with Ctrl-c (or equivalent).

Example session

>> let D = \x. x x; F = \f. f (f y) in D (F \x. x)
y y
>> let T = \f x. f (f x) in (\f x. T (T (T (T T))) f x) (\x. x) y
y
>> (\x y z. x y) y
λy' z. y y'
>> ^C

Notation

Conventional Lambda Calculus notation applies, with the exception that variable names are multiple characters long, \ is used in lieu of λ to make it easier to type, and spaces are used to separate variables rather than commas.

  • Variable names are alphanumeric, beginning with a letter.
  • Outermost parentheses may be dropped: M N is equivalent to (M N).
  • Applications are left-associative: M N P may be written instead of ((M N) P).
  • The body of an abstraction or let expression extends as far right as possible: \x. M N means \x.(M N) and not (\x. M) N.
  • A sequence of abstractions may be contracted: \foo. \bar. \baz. N may be abbreviated as \foo bar baz. N.
  • Variables may be bound using let expressions: let x = N in M is syntactic sugar for (\x. N) M.
  • Multiple variables may be defined in one let expression: let x = N; y = O in M