Proposal: Export Data.Word.Word from Prelude

Evan Laforge qdunkan at gmail.com
Wed Aug 13 23:05:26 UTC 2014


On Wed, Aug 13, 2014 at 3:06 PM, Ben Millwood <haskell at benmachine.co.uk> wrote:
> `length :: [a] -> Word` (or things of that ilk) would be even more of a
> mistake, because type inference will spread that `Word` everywhere, and `2 -
> 3 :: Word` is catastrophically wrong.

This is a pretty convincing argument for me.  I have in the past used
Word for things that seemed like they should always be positive, and
pretty quickly reverted back to a signed type.  All you need is a
subtraction anywhere and the chance of underflow is very high.  And,
as Ben said, it's easy for the "always positive" type to wind up in a
domain where subtraction is valid due to type inference.  The
principled thing might be to make that a different type, but in
practice that can be a lot of hassle so it often doesn't happen (do
you use NonEmpty everywhere possible? always have separate types for
absolute and relative measures? sometimes it's not worth the clutter).


More information about the Libraries mailing list