Skip to content

Instantly share code, notes, and snippets.

@damienstanton
Last active November 8, 2024 06:11
Show Gist options
  • Save damienstanton/b6b09c23311d310233dff4ec2ef02c7d to your computer and use it in GitHub Desktop.
Save damienstanton/b6b09c23311d310233dff4ec2ef02c7d to your computer and use it in GitHub Desktop.
Nat.cs
/*
A type `Nat` is either
-> Zero
-> Succ of Nat
We can say the same thing in C# 12 (.Net 8)
*/
record Nat<T>();
record Zero : Nat<Zero>;
record Succ<T>(Nat<T> Pred) : Nat<Succ<T>>;
public class Judgements
{
[Fact]
public void ZeroToThree()
{
Nat<Zero> zero = new Zero();
Nat<Succ<Zero>> one = new Succ<Zero>(zero);
Nat<Succ<Succ<Zero>>> two = new Succ<Succ<Zero>>(one);
Nat<Succ<Succ<Succ<Zero>>>> three = new Succ<Succ<Succ<Zero>>>(two);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment