Skip to content

Instantly share code, notes, and snippets.

@wizzard0
Created December 29, 2014 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wizzard0/6dbecfd08a73ed8bcbf0 to your computer and use it in GitHub Desktop.
Save wizzard0/6dbecfd08a73ed8bcbf0 to your computer and use it in GitHub Desktop.
Type-level recursion :)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(pt(5, 42));
}
static string pt<TC>(int depth, TC value)
{
if (depth == 0)
{
return value.ToString();
}
else
{
return pt<Pair<TC>>(depth - 1, new Pair<TC> { A = value, B = value });
}
}
}
class Pair<T>
{
public T A { get; set; }
public T B { get; set; }
public override string ToString()
{
return String.Format("Pair<{0} {1}>", A, B);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment