Designing a Module for Combinatory Logic in Haskell
4/09/2010Like the Lambda Calculus (on which Lisp is based), Combinatory Logic is a formal system that can be used to model and study computation. What makes it fascinating is that it is as powerful as the (already simple) lambda calculus, but has no need for the variables that LC requires to perform substitution!
Here I show how we can use Haskell’s type classes and other language features to model the Combinator Calculus. The goals of this module were:
- don’t force any one evaluation strategy
- allow users to define new combinators without exposing the implementation
- allow new combinators to be defined in terms of other already-defined combinators.
- discourage creation of non-sensical combinator expressions, or possible mis-use of the module
- hide existential types and anything else exotic
If you want to play with it, you can do a:
$> darcs get http://coder.bsimmons.name/code/CombinatorCalculus