[Haskell-cafe] positive Int

Neil Mitchell ndmitchell at gmail.com
Thu Aug 2 20:59:05 EDT 2007


> > It will detect that length ys is natural, and will be safe. However,
> > if you pass any arbitrary value as the index to !! it will warn of a
> > possible pattern match error.
> I hope catch doesn't actually think that's safe, because it's not - set
> ys = xs = [1,2,3,4,5], you'll get an index out of range error.  (Yes, I
> deliberately chose a list longer than 4 elements).

Of course, it doesn't, I abstracted for the sake of simplicity :-)

The !! operator has two entirely separate pattern match errors, one is
"negative index", one is "ran off the end of the list". The length xs
will satisfy the first one by proving that length is always a natural,
but the only proof of the other condition is that either the list is
infinite, or that the index is Zero/One, and the list is bigger than



More information about the Haskell-Cafe mailing list