checked Ints (was: Proposal: Export Data.Word.Word from Prelude)

Malcolm Wallace malcolm.wallace at me.com
Sun Aug 10 12:18:19 UTC 2014


On 10 Aug 2014, at 11:34, Herbert Valerio Riedel wrote:

> Btw, were there ever any discussions or plans to introduce "checked"
> Int/Word types into the Haskell Report?

There were discussions, yes.  I think the concern was that programmers tend to want either (a) correctness or (b) speed.  For the former, there is Integer, for the latter there is Int.  A checked-for-overflow bounded type would give you neither: i.e. slower than Int, but not significantly more correct.  On overflow, your program still goes wrong, but it would manifest as a crash/exception rather than an incorrect value.  

> As well as efficient dynamically
> (or even statically) checked fromIntegral conversions (c.f. [1])?

I think static detection of overflow-correctness would be desirable, yes, leading to promotion of the type from CheckedInt to Int, thus eliminating any runtime checks.  But if you can do that static analysis, you don't actually need another type.

However, I think there is still plenty of scope for a reappraisal of the concept.

Regards,
    Malcolm



More information about the Libraries mailing list