git @ Cat's Eye Technologies Lariat / e39e383
Edits Chris Pressey 3 years ago
1 changed file(s) with 24 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
2525
2626 There are several approaches for representing lambda terms in software.
2727
28 The naive approach is to represent them just as they are written on paper. In this approach, if you see
29 a variable, such as _x_, whether _x_ is free or bound depends on whether it is inside a lambda abstraction
28 The naive approach is to represent them just as they are written on paper. In this approach, whether
29 a variable, such as _x_, is free or bound depends on whether it is inside a lambda abstraction
3030 λ _x_ or not. If you need to manipulate it, you might need to rename it so that it doesn't conflict with
3131 another variable also called _x_ that is bound to a different lambda abstraction.
3232
3333 This is tiresome and error-prone. So other approaches were developed.
3434
35 One such approach is called De Bruijn indexes. In this approach, variables are represented not by names,
36 but by numbers. The number indicates which lambda abstraction the variable is bound to, if any. That is,
37 a 1 indicates it is bound to the immediately enclosing lambda abstraction, a 2 indicates it is bound to
38 the lambda abstraction just above that, and so on. If the number exceeds the number of lambda abstractions
39 which enclose the variable, it is a free variable.
40
41 This, too, has some drawbacks, so people have devised a number of other approaches:
35 One such approach alternate is De Bruijn indexes, where variables are represented not by names,
36 but by numbers. The number indicates which lambda abstraction the variable is bound to, if any;
37 a 1 indicates the immediately enclosing lambda abstraction, a 2 indicates the lambda abstraction
38 just above that, and so on. If the number exceeds the number of enclosing lambda abstractions,
39 then it is a free variable.
40
41 But this, too, has some drawbacks, so people have devised a number of other approaches:
4242
4343 * "nominal techniques" (Gabbay and Pitts)
4444 * "locally nameless" (various?)
4545 * "maps" (Sato et al.)
4646 * "bound" (Kmett)
4747
48 and so forth.
49
50 But the point is, at some level of abstraction _it does not matter_ which
51 approach is chosen _as long as_ the approach satisfies the essential properties
52 that we require lambda terms to have.
48 among others.
49
50 But the point we would like to make is this: At some level of abstraction _it does not matter_
51 which approach is chosen _as long as_ the approach satisfies the essential properties
52 that we require of lambda terms.
5353
5454 To this end, we present this abstract data type for lambda terms, which we
55 call "Lariat", consisting of six operations. The actual, concrete data type
55 call "Lariat", consisting of six operations. The actual, concrete data structure
5656 in which they are stored, and the actual, concrete mechanism by which names
57 become bound to terms, are of no real consequence (and may well be hidden
57 become bound to terms, are of no consequence (and may well be hidden
5858 from the programmer) so long as the implementation of the operations conforms
5959 to the stated specification.
6060
7171 ### `app(t1: term, t2: term): term`
7272
7373 Given a term _t1_ and a term _t2_, return an _application term_
74 which contains _t1_ as its head and _t2_ as its tail.
74 which contains _t1_ as its first subterm and _t2_ as its second
75 subterm.
76
77 > **Note**: An application term is a term that is an
78 > ordered pair of terms.
7579
7680 ### `abs(n: name, t: term): term`
7781
7882 Given a name _n_ and a term _t_, return an _abstraction term_
79 containing _t'_, where _t'_ is a version of _t_ where all free
80 variables named _n_ inside _t'_ have been replaced with
83 containing _t_', where _t_' is a version of _t_ where all free
84 variables named _n_ inside _t_' have been replaced with
8185 bound variables. These bound variables are bound to
8286 the returned abstraction term.
8387
8488 > **Note**: a bound variable is a term, but the user cannot
8589 > work with bound variables directly. A bound variable is always
86 > bound to an abstraction term. In the case of `abs`,
90 > bound to a particular abstraction term. In the case of `abs`,
8791 > the abstraction term to which variables are bound, is
8892 > the term returned by the operation.
8993