[Haskell-cafe] Re: Shouldn't this loop indefinitely => take (last [0..]) [0..]

Chris Smith cdsmith at twu.net
Fri Apr 4 18:05:07 EDT 2008

Don Stewart wrote:
> length, take, drop and index working on machine-sized Ints by default
> are really a bit of a wart, aren't they?

Definitely.  See http://cdsmith.wordpress.com/2007/07/05/find-the-bug/ 
for my account of this problem when I ran into it last summer.

In particular, the combination of these functions using Int and too much 
reliance on type inference can be fatal.  Overflow is possible in most 
languages; but in Haskell you get used to not dealing with it by assuming 
that numeric types default to Integer.  Then, in some remote corner 
somewhere, just one use of 'length' may result in an inferred type of Int 
for half the numbers in the program.  The problem is likely to be in a 
piece of code completely unrelated to where the symptoms occur.

Chris Smith

More information about the Haskell-Cafe mailing list