Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Adding 2 + 2 (Church numerals)

by blokhead (Monsignor)
on Jan 30, 2007 at 18:43 UTC ( #597427=note: print w/ replies, xml ) Need Help??

in reply to Adding 2 + 2

Lambda calculus! But it doesn't have integers (or any data types for that matter), you say? Sure it does, it has Church numerals!

my $two = sub { my($f,$x) = @_; $f->($f->($x)); }; sub add { my($m,$n) = @_; sub { my($f,$x) = @_; $m->($f, $n->($f, $x)) }; } sub decode { my($n) = @_; $n->( sub{$_[0]+1}, 0 ); } print decode( add($two, $two) ), $/;
Yeah, at some point we have to convert the Church numeral to something that Perl can print.. but you get the idea.


Comment on Re: Adding 2 + 2 (Church numerals)
Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://597427]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2015-11-26 00:12 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (693 votes), past polls