Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

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.

blokhead


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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2014-09-22 05:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (178 votes), past polls