GHC.Arr

Simon Marlow marlowsd at gmail.com
Fri Dec 18 05:15:35 EST 2009


On 18/12/09 09:48, Simon Peyton-Jones wrote:
> Right. I'll make some specialised instances in GHC.Arr.  And add comments to explain the issue

Probably a good idea to reference the tickets in the comments: #1610, 
#2120, #2669.

Cheers,
	Simon

>
> S
>
> | -----Original Message-----
> | From: Simon Marlow [mailto:marlowsd at gmail.com]
> | Sent: 18 December 2009 09:31
> | To: Duncan Coutts
> | Cc: Simon Peyton-Jones; Simon Marlow; cvs-ghc at haskell.org
> | Subject: Re: GHC.Arr
> |
> | On 18/12/09 05:48, Duncan Coutts wrote:
> |>  On Thu, 2009-12-17 at 18:03 +0000, Simon Peyton-Jones wrote:
> |>>  Simon
> |>>
> |>>  I'm puzzling over GHC.Arr.safeIndex
> |>>
> |>>  It calls the overloaded method 'index' which does bound checks on the
> |>>  "semantic range", by checking that i is in the range (l,u).  But then
> |>>  safeIndex does *another* range check, on the resulting index value.
> |>>
> |>>  Shouldn't it be an invariant that if index (l,u) i returns at all, it
> |>>  returns an in-range value?
> |>>
> |>>  I suppose we can't enforce that.  But *by default* doing two range
> |>>  checks on every array access seems stupid.
> |>
> |>  So far we've been through three iterations of this thing :-)
> |>
> |>  The original version did one range check, the Ix one. Then people
> |>  complained that custom Ix instances were unsafe because they could index
> |>  outside the array.
> |>
> |>  The next iteration just checked the resulting index value. Then people
> |>  complained because you could index outside the Ix range (eg on 2-d
> |>  arrays) without any error being raised.
> |>
> |>  The current iteration now does both checks. Now people complain that
> |>  it's slow :-)
> |>
> |>  So the challenge is to satisfy all these requirements simultaneously.
> |
> | We could omit the Ix check for simple scalar types where the range check
> | is sufficient.  For 2-d arrays and suchlike we could do the Ix check but
> | omit the range check.  User-defined Ix instances would get both an Ix
> | check and a range check unless they explicitly use the unsafe methods.
> |
> | Cheers,
> | 	Simon
>



More information about the Cvs-ghc mailing list