Proposal: Export Data.Word.Word from Prelude

Ben Millwood haskell at benmachine.co.uk
Wed Aug 13 22:06:55 UTC 2014


On Sun, Aug 10, 2014 at 09:07:42AM +0100, Malcolm Wallace wrote:
> 
> On 10 Aug 2014, at 07:04, Ivan Lazar Miljenovic wrote:
> 
>> I'm +1 on the re-exporting (I would be tempted to go the whole hog and
>> re-export all the Word* types as well).
> 
> 
> I was involved in the discussions when the Word type was originally 
> added to Haskell, primarily for the use of the FFI.  As I recall, 
> people were deeply uncomfortable that there should even be a Word 
> type, with unspecified precision.  The types Word8, Word16, Word32, 
> and Word64 were entirely uncontroversial, because you know what you 
> are dealing with.  The primary use of the Word* types was to 
> represent machine words (bytes, half-words, etc), enabling (for 
> instance) bit-twiddling of individual components of the word.  With 
> an unknown-precision Word value, you can guarantee nothing about 
> whether your bit-operation will work.  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 Haskel
> l way is to prefer correctness.

I think I sympathise a great deal with people's discomfort. I feel 
like the ubiquity of Int was a mistake: it's basically a performance 
optimisation, with reasonably serious correctness issues, and 
shouldn't be the first thing every newbie comes across. I moreover 
feel like, e.g. `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. 
Although it seems nice to have an output type for non-negative 
functions that only has non-negative values, in fact Word happily 
supports subtraction, conversion from Integer, even negation (!) 
without a hint that anything has gone amiss. So I just don't believe 
that it is a type suitable for general "positive integer" 
applications.

I feel a little unqualified to comment in the face of people far more 
knowledgeable and experienced than I am enthusiastically +1-ing this 
proposal, but I'm going to go ahead and -1 it. I think the situations 
in which Word is really what you want are few enough that it should 
not clutter the universal namespace.

> Regards,
>    Malcolm
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries


More information about the Libraries mailing list