logoalt Hacker News

rdevillatoday at 2:41 AM1 replyview on HN

> Of course there's no way to tell at compile time that a value will definitely be zero.

Yes there is. Dependently typed languages like Idris can inspect terms at the value-level during compile time. Rather, instead of proving that the divisor will be zero, you must instead statically prove that the divisor cannot be zero; otherwise the code will not typecheck.


Replies

hyperhellotoday at 2:54 AM

Okay,

int integer_division(int a, int b) { if (b!=0) return a/b; raise(SIGFPE); }

Great.

show 3 replies