1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
<!DOCTYPE html>
<html lang="en">
<head><script src="/livereload.js?mindelay=10&v=2&port=1313&path=livereload" data-no-instant defer></script>
<title>Untyped Lambda Calculus :: </title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="As I mentioned in an [earlier post]({% post_url 2017-08-16-tapl %}), I’ve been working through Types and Programming Languages in Rust. Chapters 5 to 7 of TAPL discuss untyped lambda calculus through an implementation of a simple expression-based language. Chapter 5 lays the foundations; chapter 6 focuses more on one of the concepts introduced in chapter 5; de Bruijn index and chapter 7 explores an ML implementation of the said language, but only how to evaluate the terms, and not how to parse them. The accompanying OCaml implementation’s parser is generated automatically from a Yacc grammar.
" />
<meta name="keywords" content="" />
<meta name="robots" content="noodp" />
<link rel="canonical" href="http://localhost:1313/post/2017-08-24-untyped-lambda-calculus/" />
<link rel="stylesheet" href="http://localhost:1313/css/buttons.min.86f6b4c106b6c6eb690ae5203d36b442c1f66f718ff4e8164fa86cf6c61ad641.css">
<link rel="stylesheet" href="http://localhost:1313/css/code.min.d529ea4b2fb8d34328d7d31afc5466d5f7bc2f0bc9abdd98b69385335d7baee4.css">
<link rel="stylesheet" href="http://localhost:1313/css/fonts.min.5bb7ed13e1d00d8ff39ea84af26737007eb5051b157b86fc24487c94f3dc8bbe.css">
<link rel="stylesheet" href="http://localhost:1313/css/footer.min.eb8dfc2c6a7eafa36cd3ba92d63e69e849e2200e0002a228d137f236b09ecd75.css">
<link rel="stylesheet" href="http://localhost:1313/css/gist.min.a751e8b0abe1ba8bc53ced52a38b19d8950fe78ca29454ea8c2595cf26aad5c0.css">
<link rel="stylesheet" href="http://localhost:1313/css/header.min.75c7eb0e2872d95ff48109c6647d0223a38db52e2561dd87966eb5fc7c6bdac6.css">
<link rel="stylesheet" href="http://localhost:1313/css/main.min.36833afd348409fc6c3d09d0897c5833d9d5bf1ff31f5e60ea3ee42ce2b1268c.css">
<link rel="stylesheet" href="http://localhost:1313/css/menu.min.3c17467ebeb3d38663dce68f71f519901124fa5cbb4519b2fb0667a21e9aca39.css">
<link rel="stylesheet" href="http://localhost:1313/css/pagination.min.bbb986dbce00a5ce5aca0504b7925fc1c581992a4bf57f163e5d69cc1db7d836.css">
<link rel="stylesheet" href="http://localhost:1313/css/post.min.e6dddd258e64c83e05cec0cd49c05216742d42fc8ecbfbe6b67083412b609bd3.css">
<link rel="stylesheet" href="http://localhost:1313/css/syntax.min.a0773cce9310cb6d8ed23e50f005448facf29a53001b57e038828daa466b25c0.css">
<link rel="stylesheet" href="http://localhost:1313/css/terminal.min.e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css">
<link rel="stylesheet" href="http://localhost:1313/css/terms.min.b81791663c3790e738e571cdbf802312390d30e4b1d8dc9d814a5b5454d0ac11.css">
<link rel="shortcut icon" href="http://localhost:1313/favicon.png">
<link rel="apple-touch-icon" href="http://localhost:1313/apple-touch-icon.png">
<meta name="twitter:card" content="summary" />
<meta property="og:locale" content="en" />
<meta property="og:type" content="article" />
<meta property="og:title" content="Untyped Lambda Calculus">
<meta property="og:description" content="As I mentioned in an [earlier post]({% post_url 2017-08-16-tapl %}), I’ve been working through Types and Programming Languages in Rust. Chapters 5 to 7 of TAPL discuss untyped lambda calculus through an implementation of a simple expression-based language. Chapter 5 lays the foundations; chapter 6 focuses more on one of the concepts introduced in chapter 5; de Bruijn index and chapter 7 explores an ML implementation of the said language, but only how to evaluate the terms, and not how to parse them. The accompanying OCaml implementation’s parser is generated automatically from a Yacc grammar.
" />
<meta property="og:url" content="http://localhost:1313/post/2017-08-24-untyped-lambda-calculus/" />
<meta property="og:site_name" content="" />
<meta property="og:image" content="http://localhost:1313/og-image.png">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="627">
<meta property="article:published_time" content="2017-08-24 00:00:00 +0000 UTC" />
<script>
window.MathJax = {
tex: {
inlineMath: [['$', '$'], ['\\(', '\\)']],
displayMath: [['$$', '$$'], ['\\[', '\\]']],
processEscapes: true,
processEnvironments: true
},
options: {
skipHtmlTags: ['script', 'noscript', 'style', 'textarea', 'pre']
}
};
</script>
<script id="MathJax-script" async src="/mathjax/tex-mml-chtml.js"></script>
</head>
<body>
<div class="container center">
<header class="header">
<div class="header__inner">
<div class="header__logo">
<a href="http://localhost:1313/">
<div class="logo">
Terminal
</div>
</a>
</div>
</div>
</header>
<div class="content">
<article class="post">
<h1 class="post-title">
<a href="http://localhost:1313/post/2017-08-24-untyped-lambda-calculus/">Untyped Lambda Calculus</a>
</h1>
<div class="post-meta"><time class="post-date">2017-08-24</time></div>
<span class="post-tags">
#<a href="http://localhost:1313/tags/tapl/">tapl</a>
#<a href="http://localhost:1313/tags/rust/">rust</a>
</span>
<div class="post-content"><div>
<p>As I mentioned in an [earlier post]({% post_url 2017-08-16-tapl %}), I’ve been working through <a href="https://www.cis.upenn.edu/~bcpierce/tapl/">Types and Programming Languages</a> in Rust. Chapters 5 to 7 of TAPL discuss untyped lambda calculus through an implementation of a simple expression-based language. Chapter 5 lays the foundations; chapter 6 focuses more on one of the concepts introduced in chapter 5; <a href="https://en.wikipedia.org/wiki/De_Bruijn_index">de Bruijn index</a> and chapter 7 explores an ML implementation of the said language, but only how to evaluate the terms, and not how to parse them. The accompanying OCaml <a href="https://www.cis.upenn.edu/~bcpierce/tapl/checkers/">implementation</a>’s parser is generated automatically from a Yacc grammar.</p>
<p>I’ve had good experiences writting parsers in Haskell using <a href="https://hackage.haskell.org/package/parsec">parsec</a> and <a href="https://hackage.haskell.org/package/attoparsec">attoparsec</a> before, so I started looking for parser-combinators in Rust. There seem to be three capable options:</p>
<ul>
<li><a href="https://github.com/Marwes/combine">combine</a></li>
<li><a href="https://github.com/m4rw3r/chomp">chomp</a></li>
<li><a href="https://github.com/Geal/nom">nom</a></li>
</ul>
<p>Combine even has the <a href="https://github.com/Marwes/combine-language">combine-language</a> extension which is very similar to Parsec’s <a href="http://hackage.haskell.org/package/parsec/docs/Text-Parsec-Token.html">Text.Parsec.Token</a> which would’ve simplified the task of parsing lexical elements but I couldn’t add it as a dependency to my project—due to compile errors which I’m sure has been because of my ignorance and lack of familiarity with Rust and Cargo. At the end I ended up choosing using layman’s metrics, number of GitHub stars and nom won by a huge margin.</p>
</div></div>
<div class="pagination">
<div class="pagination__title">
<span class="pagination__title-h"></span>
<hr />
</div>
<div class="pagination__buttons">
<a href="http://localhost:1313/post/2018-09-11-shapeless/" class="button inline prev">
< [<span class="button__text">Shapeless</span>]
</a>
::
<a href="http://localhost:1313/post/2017-08-22-thinkpad-e470/" class="button inline next">
[<span class="button__text">ThinkPad E470</span>] >
</a>
</div>
</div>
</article>
</div>
<footer class="footer">
<div class="footer__inner">
<div class="copyright">
<span>© 2026 Powered by <a href="https://gohugo.io">Hugo</a></span>
<span>:: <a href="https://github.com/panr/hugo-theme-terminal" target="_blank">Theme</a> made by <a href="https://github.com/panr" target="_blank">panr</a></span>
</div>
</div>
</footer>
<script type="text/javascript" src="/bundle.min.js"></script>
</div>
</body>
</html>
|