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
-
Show this thread
-
Replying to @propensive
It's that package on Scala 3? I thought there would be little in terms of changes to stdlib.
1 reply 0 retweets 0 likes -
Replying to @dcsobral
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]).
1 reply 0 retweets 0 likes
Replying to @propensive @dcsobral
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).
8:49 AM - 21 Jan 2021
from Krakow, Poland
0 replies
0 retweets
0 likes
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.