aboutsummaryrefslogtreecommitdiff
path: root/entries/braxtonhall/types
diff options
context:
space:
mode:
authorbraxtonhall2022-10-23 19:27:49 +0000
committerbraxtonhall2022-10-23 19:27:49 +0000
commit77ffde450e92ffe6527c35ffc2383b17d4c04f68 (patch)
tree65a560a18f1952114727e05872fce3f149e660e4 /entries/braxtonhall/types
parentb5b18e46e3a5c4daaa3b4613395b1a216a47bc17 (diff)
Rename directory to use GitHub ID
Diffstat (limited to 'entries/braxtonhall/types')
-rw-r--r--entries/braxtonhall/types/index.ts18
-rw-r--r--entries/braxtonhall/types/test.ts19
2 files changed, 37 insertions, 0 deletions
diff --git a/entries/braxtonhall/types/index.ts b/entries/braxtonhall/types/index.ts
new file mode 100644
index 0000000..11f4086
--- /dev/null
+++ b/entries/braxtonhall/types/index.ts
@@ -0,0 +1,18 @@
+type Zero = "😰";
+
+type Succ<N> = {prev: N};
+
+type Prev<N> = N extends Succ<infer P> ? P : never;
+
+type Add<A, B> = B extends Zero ? A : Succ<Add<A, Prev<B>>>;
+
+type _Fib<N, AccumulatorA, AccumulatorB> =
+ N extends Zero
+ ? AccumulatorA
+ : N extends Succ<Zero>
+ ? AccumulatorB
+ : _Fib<Prev<N>, AccumulatorB, Add<AccumulatorA, AccumulatorB>>;
+
+type Fib<N> = _Fib<N, Zero, Succ<Zero>>;
+
+export type {Zero, Succ, Fib};
diff --git a/entries/braxtonhall/types/test.ts b/entries/braxtonhall/types/test.ts
new file mode 100644
index 0000000..2ce83e7
--- /dev/null
+++ b/entries/braxtonhall/types/test.ts
@@ -0,0 +1,19 @@
+import {Zero, Succ, Fib} from "./index";
+
+const zero: Zero = "😰";
+const one: Succ<typeof zero> = {prev: zero};
+const two: Succ<typeof one> = {prev: one};
+const three: Succ<typeof two> = {prev: two};
+const four: Succ<typeof three> = {prev: three};
+const five: Succ<typeof four> = {prev: four};
+const six: Succ<typeof five> = {prev: five};
+const seven: Succ<typeof six> = {prev: six};
+const eight: Succ<typeof seven> = {prev: seven};
+
+const fibZero: Fib<typeof zero> = zero;
+const fibOne: Fib<typeof one> = one;
+const fibTwo: Fib<typeof two> = one;
+const fibThree: Fib<typeof three> = two;
+const fibFour: Fib<typeof four> = three;
+const fibFive: Fib<typeof five> = five;
+const fibSix: Fib<typeof six> = eight;