-
Notifications
You must be signed in to change notification settings - Fork 15
Types and Programming Languages Chapters 6 & 7 An ML Implementation of the Lambda Calculus
- 5 minutes of collective helplessness in the absence of @mudge
- 1 minute of collective resolve to persevere nonetheless
- 20 mins on De Bruijn indices
- 5 mins of deciding to mob an implementation without worrying about renaming at all
- 1hr of successful mobbing
- 20 mins of show and tell
If anyone can remember what we spent the missing 9 minutes on, please update accordingly.
We decided (based on experiences of those who'd written an implementation before the meeting) that the most achievable goal would be to try a ruby implementation that used a conventional named representation of terms, but not worry about bound variable renaming to avoid capture.
We decided on a handful of basic test cases to exercise each of the evaluation rule schemas, while avoiding the naming problems we'd deliberately decided to skirt:
-
E-AppAbs (commit): (λx. x)(λx. x) -> (λx. x)
For this rule we required an application of two values (i.e. lambda-abstractions), so this was the simplest test case we could construct. It required us to begin implementing substitution, in the first iteration simply matching on variable names.
-
E-App2 (commit): (λx. x) ((λx. x) (λz. (λx. x) z)) -> id (λz. id z)
Not much to say here - now that the RHS of the application isn't a value, per the evaluation rule we just eval'd the RHS and returned a new application with the result. Our existing substitution logic was sufficient for this to work.
-
E-App1 (commit): ((λx. x) (λx. x)) (λz. z) -> (λx. x) (λz. z)
This again was fairly straightforward - with the LHS as an application, we eval'd the LHS and returned a new application using the result.
-
Expanding substitution (code): (λx. (λy. x y))(λz. z) -> λy. (λz. z) y
So far our examples had only required implementing substitution for variables, so we wrote an example that required substitution in both an abstraction and an application.
-
Playing around (commit)
We wanted to try some more examples, so we implemented a "fully evaluate" method and started to plug in some of the boolean examples from earlier chapters.
I think we also tried some breaking examples that our absence of name-handling couldn't cope with, but we didn't commit them and I can't remember what they were. They were probably really good, though.
The implementations:
-
@jcoglan's Haskell implementations:
- using variable renaming
- using nameless representation of terms
- @leocassarani's Haskell implementation
- @zetter's Elixir implementation
- @tomstuart's Ruby implementation using higher order abstract syntax
- Home
- Documentation
- Choosing a Topic
- Shows & Tells
- Miscellaneous
- Opt Art
- Reinforcement Learning: An Introduction
- 10 Technical Papers Every Programmer Should Read (At Least Twice)
- 7 More Languages in 7 Weeks
- Lua, Day 1: The Call to Adventure
- Lua, Day 2: Tables All the Way Down
- Lua, Day 3
- Factor, Day 1: Stack On, Stack Off
- Factor, Day 2: Painting the Fence
- Factor, Day 3: Balancing on a Boat
- Elm, Day 1: Handling the Basics
- Elm, Day 2: The Elm Architecture
- Elm, Day 3: The Elm Architecture
- Elixir, Day 1: Laying a Great Foundation
- Elixir, Day 2: Controlling Mutations
- Elixir, Day 3: Spawning and Respawning
- Julia, Day 1: Resistance Is Futile
- Julia, Day 2: Getting Assimilated
- Julia, Day 3: Become One With Julia
- Minikanren, Days 1-3
- Minikanren, Einstein's Puzzle
- Idris Days 1-2
- Types and Programming Languages
- Chapter 1: Introduction
- Chapter 2: Mathematical Preliminaries
- Chapter 3: Untyped Arithmetic Expressions
- Chapter 4: An ML Implementation of Arithmetic Expressions
- Chapter 5: The Untyped Lambda-Calculus
- Chapters 6 & 7: De Bruijn Indices and an ML Implementation of the Lambda-Calculus
- Chapter 8: Typed Arithmetic Expressions
- Chapter 9: The Simply-Typed Lambda Calculus
- Chapter 10: An ML Implementation of Simple Types
- Chapter 11: Simple Extensions
- Chapter 11 Redux: Simple Extensions
- Chapter 13: References
- Chapter 14: Exceptions
- Chapter 15: Subtyping – Part 1
- Chapter 15: Subtyping – Part 2
- Chapter 16: The Metatheory of Subtyping
- Chapter 16: Implementation
- Chapter 18: Case Study: Imperative Objects
- Chapter 19: Case Study: Featherweight Java
- The New Turing Omnibus
- Errata
- Chapter 11: Search Trees
- Chapter 8: Random Numbers
- Chapter 35: Sequential Sorting
- Chapter 58: Predicate Calculus
- Chapter 27: Perceptrons
- Chapter 9: Mathematical Research
- Chapter 16: Genetic Algorithms
- Chapter 37: Public Key Cryptography
- Chapter 6: Game Trees
- Chapter 5: Gödel's Theorem
- Chapter 34: Satisfiability (also featuring: Sentient)
- Chapter 44: Cellular Automata
- Chapter 47: Storing Images
- Chapter 12: Error-Correcting Codes
- Chapter 32: The Fast Fourier Transform
- Chapter 36: Neural Networks That Learn
- Chapter 41: NP-Completeness
- Chapter 55: Iteration and Recursion
- Chapter 19: Computer Vision
- Chapter 61: Searching Strings
- Chapter 66: Church's Thesis
- Chapter 52: Text Compression
- Chapter 22: Minimum spanning tree
- Chapter 64: Logic Programming
- Chapter 60: Computer Viruses
- Show & Tell
- Elements of Computing Systems
- Archived pages