Proposal: Export Data.Word.Word from Prelude

Johan Tibell johan.tibell at gmail.com
Tue Aug 26 11:40:49 UTC 2014


On Tue, Aug 26, 2014 at 11:56 AM, Andreas Abel <andreas.abel at ifi.lmu.de>
wrote:

> Machine integers have the size of the addressable main memory, so they
> should be used (exclusively?) for quantities that are limited by the size
> of the memory, like the mentioned indices into data structures like vectors
> or arrays.
>
> With Word I can address as many objects as my machine can hold bytes.
> However, the objects are usually not bytes, but words themselves.  Thus,
> Int, which is only one bit short of Word, is as good as Word as an index
> type.  Further, Int supports subtraction.
>

"Usually" is not always. You address bytes and Int is not large enough to
do so. In fact, this proposal was partly triggered by GHC doing the wrong
thing with really large array indices, as the primops have a Int# argument
which caused a wraparound. This in turn led to bad Cmm being generated and
finally a segfault in the overflow1 test in the GHC test suite.


> I do not know what Word would be good for to the amount that it deserves a
> place in Prelude.
>

Bit twiddling of all kinds. We use it for e.g. bitmasks in
unordered-containers. Hashing, etc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20140826/dcec29e8/attachment.html>


More information about the Libraries mailing list