For an input of ‘0’, which ‘Int’ does the following “function” return? def slotSize(n: Int): Int = 1000/n The answer: it doesn’t. The type signature is a bald-faced lie. Functional programs don’t lie. Which means they don’t throw exceptions—they use values to model failure.
-
-
Replying to @jdegoes
I agree that the type signature is insufficient. But I'm even more interested in the question of what the right design of a division operator would be to prevent this?
1 reply 0 retweets 2 likes -
Replying to @AlanJay1
Refinement types or smart constructors (NotZero) or just plain old Maybe / Option.
3 replies 0 retweets 8 likes
What about monadic style? Effect typing?
10:50 AM - 3 Dec 2018
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.
Read my blog!