These exist in stdlib, but… import compiletime.S type +[A <: Int, B <: Int] <: Int = A match case 0 => B case S[a] => a + S[B] type *[A <: Int, B <: Int] = Mult[A, B, 0] type Mult[A, B, C] <: Int = A match case 0 => C case S[a] => Mult[a, B, B + C] val x: 10 * 11 = 110
This is my own code. Both + and * are defined for type-level Ints in the standard library, with fast implementations that just operate on the integers as numbers, but my implementations show that it's completely possible to build these using just the successor type (S[n]).
-
-
Note that S[n] actually provides both increment and decrement, depending on whether we apply it or pattern match against it (i.e. type unification).
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.