[Haskell-cafe] "Bounds checking" pragma?

Artyom Kazak artyom.kazak at gmail.com
Thu Nov 10 12:57:47 CET 2011


2011/11/10 Daniel Fischer <daniel.is.fischer at googlemail.com>:
>
> There's a problem here, unsafeAt uses an Int index into the array, while
> (!) uses the declared index type. Even skipping the bounds check, you'd
> still have to calculate the Int index for the replacement of (!).
>
>
> #ifdef OMIT_BOUNDS_CHECK
> {-# RULES
> "ArrayIndex"  arr ! i = unsafeAt arr (unsafeIndex (bounds arr) i)
>  #-}
> #endif
>

Thanks!

>
> (?) = unsafeAt
>

Yes, but (!) was taken as an example. There is a lot of other
functions doing bounds checking... Creating replacements for every
single function is rather tedious.

The flag pragma also has other uses. For example, we can introduce an
"overflow" flag (check every operation with Int's for overflow) ,
which may be useful for debugging. In release version this flag will
be turned off.



More information about the Haskell-Cafe mailing list