Interlude: Schönfinkeling for R

Schönfinkel takes a function in A x B -> C. It returns one of type A -> B -> C.

Schönfinkel = function(f) {
function(x) {function (y) f(x,y)}
}

unSchönfinkel does the reverse:

unSchönfinkel = function(f) {
function(x,y) f(x)(y)
}

And an example:

> add = function(x,y) x+y
>
> succ = Schönfinkel(add)(1)
> succ(2)
[1] 3
>
> unSchönfinkel(Schönfinkel(add))(1,2)
[1] 3

Can’t be hard to generalise this.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s