Daniel McAllansmith wrote:
> I can see the domain bounds check would be a problem in theory, but in
> practice doesn't the type enforce that? Keeping Word positive costs nothing
> because it just overflows. Wouldn't it be much the same?
If you're planning wraparound semantics then you're better off with Int
indexes. Passing an index congruent to -1 mod 2^32 is certainly an error,
and (!!) may as well fail immediately rather than try to traverse 2^32-1
list nodes. I think both Int and Word are equally "correct" here, since both
are proper supersets of the valid set of indexes. (If you're working with
lists so long that Int may not be big enough, you shouldn't trust Word either.)
Haskell 98's List module supplies "generic" versions of the list functions,
like genericIndex :: Integral a => [b] -> a -> b, which will work with Word.
-- Ben