# Commit c16366c8204feca55cae3277315d1cd963ae35da

- Diff rendering mode:
- inline
- side by side

README

(37 / 0)

1 | This is a very simple interpreter for an extended lambda calculus. | ||

2 | It does Hindleyâ€“Milner style type inference and graph reduction. | ||

3 | |||

4 | Compile with: | ||

5 | yacc hm.y && gcc -std=c99 -pedantic -Wall -Wextra -O2 y.tab.c -o hm | ||

6 | |||

7 | Programs in this language consist of zero or more global definitions | ||

8 | interspersed freely with zero or more terms, each on its own line. | ||

9 | The interpreter takes them in linear order, one at a time, | ||

10 | typechecking each and either evaluating it(for terms) or storing it | ||

11 | (for definitions). Evaluation gets printed out one step at a time. | ||

12 | |||

13 | Global definitions have the form | ||

14 | |||

15 | <var> = <term> | ||

16 | |||

17 | The definition is not recursive; any reference in the right-hand-side | ||

18 | to a variable having the same name as the one being defined is taken | ||

19 | to refer to a previous definition of that variable. | ||

20 | |||

21 | Variable names start with a letter or the underscore and continue with | ||

22 | zero or more alphanumeric characters and underscores. | ||

23 | |||

24 | Terms are as in the untyped lambda calculus with extensions for | ||

25 | integer constants, addition, pairs (with projection functions "fst" | ||

26 | and "snd"), mu-forms and (nonrecursive) let-forms. | ||

27 | |||

28 | Mu forms are used for expressing recursion: mu <var> . <term> | ||

29 | expresses the equation <var> = <term> and evaluates to the solution of | ||

30 | that equation. | ||

31 | |||

32 | The type system is a straightforward Hindley-Milner inference engine. | ||

33 | Types are generalized when variables are introduced in the environment | ||

34 | by global definitions and let forms. No generalization is done for | ||

35 | the formal parameters of lambda abstractions or mu forms. | ||

36 | |||

37 | Examples can be found in the file unimaginatively called foo. |