Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://597427]
help
Chatterbox?
[LanX]: Moon not Mars
Corion updates his location info to "I'm needed everywhere"

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (16)
As of 2017-03-27 15:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (320 votes). Check out past polls.