User defined Ix instances potentially unsafe

Alastair Reid reid@cs.utah.edu
Mon, 7 May 2001 13:31:57 -0600


> If you really want to squeeze the last drops of performance out, then
> there's always that compiler option to disable array bounds checking...

If you mean:

  "disable array bounds checking" == assume that the (possibly user-supplied)
                                     Ix instance is correct but still perform
                                     the Ix-based range check.
                                     [This is the status quo.]

  "enable array bounds checking" == perform a possibly redundant range check
                                    because the Ix instance may be broken

then this sounds like an excellent idea.

Especially given that Pascal compilers (not exactly new technology) used to
do a pretty good job of eliminating redundant bounds checks so I imagine that
that redundant check could be eliminated from all the easy cases without
too much work. 

> For Haskell 200X, where strict backwards compatibility is not required,
> unchecked_index should be introduced as a documented new method for the
> Ix class.

Is this enough?
Most of the array code I write uses the higher-level operations like fmap and
ixmap.    Do I need unchecked versions of them too?
Can the higher-level operations amortise the cost of those extra
bounds checks?  I think fmap can but ixmap can't and I haven't considered
the others.

--
Alastair Reid