Programming Language Theory: Difference between revisions

No edit summary
No edit summary
Line 12: Line 12:
The integers (or any countably infinite set) can be represented via the [http://en.wikipedia.org/wiki/Church_encoding Church encoding]:
The integers (or any countably infinite set) can be represented via the [http://en.wikipedia.org/wiki/Church_encoding Church encoding]:
* <tt>n ≡ λf. λx . f<sup>n</sup>x</tt>
* <tt>n ≡ λf. λx . f<sup>n</sup>x</tt>
* <tt>plus ≡ λm. λn. λf. λx. m f (n f x)</tt> (from f<sup>(m + n)</sup>(x) = f<sup>m</sup>(f<sup>n</sup>(x)))
* <tt>plus ≡ λm. λn. λf. λx. m f (n f x)</tt> (from ''f<sup>(m + n)</sup>(x) = f<sup>m</sup>(f<sup>n</sup>(x))'')
* <tt>succ ≡ λn. λf. λx. f (n f x)</tt> (β-equivalent to <tt>(plus 1)</tt> for a defined <tt>1</tt>)
* <tt>succ ≡ λn. λf. λx. f (n f x)</tt> (β-equivalent to <tt>(plus 1)</tt> for a defined <tt>1</tt>)
* <tt>mult ≡ λm. λn. λf. n (m f)</tt> (from f<sup>(m * n)</sup> = (f<sup>m</sup>)<sup>n</sup>)
* <tt>mult ≡ λm. λn. λf. n (m f)</tt> (from ''f<sup>(m * n)</sup> = (f<sup>m</sup>)<sup>n</sup>'')
The Church booleans take two arguments, and evaluate to one of them:
The Church booleans take two arguments, and evaluate to one of them:
* <tt>true ≡ λa. λb . a</tt>
* <tt>true ≡ λa. λb . a</tt>