Created
December 29, 2014 14:19
-
-
Save wizzard0/6dbecfd08a73ed8bcbf0 to your computer and use it in GitHub Desktop.
Type-level recursion :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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