r/Idris • u/[deleted] • Oct 20 '19
An idea for a compiler optimization
It seems to me that any type defined like this (including but not limited to Nats):
data A = B | C A
should be trivially replaceable by an int: 8, 16, 32 or 64 bits — for dependent types with upper limits smaller than the corresponding power of 2 (for example, “A so that Int (a :: A) <= 1000” should be uint16_t); or some efficient implementation of BigInt for bigger or nonexistent limits.
This way, at least in regards to natural numbers, we can have the best of both worlds: the correctness proofs of Idris and the speed of C++. And the idea is probably applicable at a wider scale.
What do you think? Also, does Idris already do this by any chance?
3
Upvotes
3
8
u/Infinisil Oct 20 '19
It can actually already do that! See https://github.com/idris-lang/Idris-dev/pull/4685