Proposal: Export Data.Word.Word from Prelude
Herbert Valerio Riedel
hvr at gnu.org
Sat Aug 9 21:12:58 UTC 2014
Hello Henning,
On 2014-08-09 at 21:25:50 +0200, Henning Thielemann wrote:
[...]
> Furthermore Word (like Int) has no protection against overflow,
> e.g. (-1 :: Word) is accepted without any warnings.
Like Int*, all Word*-typed literals are checked as well[1]. But for some
reason I haven't investigated (possibly a bug) the check fails for small
negative values unless -XNegativeLiterals is active:
Prelude> (0xfffffffffffffffff::Data.Word.Word)
<interactive>:2:2: Warning:
Literal 295147905179352825855 is out of the GHC.Types.Word range 0..18446744073709551615
18446744073709551615
Prelude> (-0xfffffffffffffffff::Data.Word.Word)
<interactive>:3:3: Warning:
Literal 295147905179352825855 is out of the GHC.Types.Word range 0..18446744073709551615
1
Prelude> (-1::Data.Word.Word)
18446744073709551615
Prelude> :set -XNegativeLiterals
Prelude> (-1::Data.Word.Word)
<interactive>:6:2: Warning:
Literal -1 is out of the GHC.Types.Word range 0..18446744073709551615
18446744073709551615
>> I don't have any concrete suggestions for improving this that aren't
>> somewhat groan worthy (eg type UInt = Word), but perhaps someone
>> else might at least offer some comforting words. (Sorry)
>
> Modula calls non-negative integers CARDINAL. I like the name. In
> Haskell there could be a Cardinal type for arbitrary size non-negative
> integers and Card for machine size integers, although the latter one
> could be misunderstood as cards used in card games.
Fwiw, I did wonder back then why Wirth chose the term 'cardinal' over
e.g. 'natural'. However, the thing is, 'Word' is already part of the
Haskell Report (and before that had been established already via the FFI
addendum), and it's already adopted widely (grep found " Data.Word"
mentioned in 1365 of 6766 packages). So the type-name 'Word' meaning
unsigned fixed-width integral is not going away that soon.
Cheers,
hvr
[1]: https://github.com/ghc/ghc/blob/1fc60ea1f1fd89b90c2992d060aecb5b5a65f8c0/compiler/deSugar/MatchLit.lhs#L158-L190
More information about the Libraries
mailing list