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

Herbert Valerio Riedel hvr at gnu.org
Sun Aug 10 10:34:52 UTC 2014


Hello Malcolm

On 2014-08-10 at 10:07:42 +0200, Malcolm Wallace wrote:

> [...] I believe the use of unknown-precision Word to represent
> non-negative integers was the winning justification, but it remains
> controversial in the same way that Int (rather than Int32, or Integer)
> does.  Lack of clarity over whether or when a number overflows is a
> pretty bad downside.  Pragmatically, it may work OK for most people
> most of the time.  But the Haskell way is to prefer correctness.

Btw, were there ever any discussions or plans to introduce "checked"
Int/Word types into the Haskell Report? As well as efficient dynamically
(or even statically) checked fromIntegral conversions (c.f. [1])?

I.e. 'Int'/'Word' types (whose bit-width has some degree of freedom as
you point out) whose 'Num' operations would throw appropriate
`ArithException`s if the result over/underflows the type domain
(c.f. [2])


 [1]: I plan to bring this up at some later point as part of an effort
      to provide Haskell with statically accessible range meta-info
      about bounded integral types (something like a promoted `Bounded`
      typeclass), as right now it seems one has to resort to type-level
      hackery such as

        http://hackage.haskell.org/package/int-cast-0.1.1.0/docs/Data-IntCast.html

      to achieve what I have in mind.

 [2]: http://hackage.haskell.org/package/safeint

Cheers,
  hvr


More information about the Libraries mailing list