Say that again…

We can also translate the code of the previous entry into C#
 

abstract class Arrow<X, Y>
{
 
public abstract Y app(X x);
}

class C2<X,Y> : Arrow<Arrow<Y,X>, X>
{
  Y y;
 
public C2(Y y)
  {
   
this.y = y;
  }
 
public override X app(Arrow<Y,X> x)
  {
   
return x.app(y);
  }
}

class C1<X,Y> : Arrow<Y, Arrow<Arrow<Y,X>, X>>
{
 
public override Arrow<Arrow<Y,X>,X> app(Y x)
  {
   
return new C2<X,Y>(x);
  }
}

abstract class All_Type_2<Z>
{
 
public abstract Arrow<Y, Arrow<Arrow<Y,Z>, Z>> tyapp<Y>();
}

class T2<X> : All_Type_2<X>
{
 
public override Arrow<Y,Arrow<Arrow<Y,X>,X>> tyapp<Y>()
  {
   
return new C1<X,Y>();
  }
}

class LengthFn : Arrow<string, int>
{
 
public override int app(string x)
  {
   
return x.Length;
  }
}

class Program
{
 
static void Main(string[] args)
  {
   
var app1 = (new T2<int>()).tyapp<string>();
   
var app2 = app1.app("hello");
   
Console.WriteLine(app2.app(new LengthFn()));
  }
}

Advertisements
This entry was posted in Books. Bookmark the permalink.

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