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 examining the Monastery: (12)
As of 2016-02-11 17:18 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (376 votes), past polls