Last active
November 8, 2024 06:11
-
-
Save damienstanton/b6b09c23311d310233dff4ec2ef02c7d to your computer and use it in GitHub Desktop.
Nat.cs
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
/* | |
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