X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=GHC%2FArr.lhs;h=8f439cd85e97a232f578874083f29b996c5e134c;hb=7c0b04fd273621130062418bb764809c79488dd2;hp=c5e945ffdf636552f6e49900ad6bdbb72e8c499f;hpb=7953d86d3d7649f948be2757a15c99856322d296;p=haskell-directory.git diff --git a/GHC/Arr.lhs b/GHC/Arr.lhs index c5e945f..8f439cd 100644 --- a/GHC/Arr.lhs +++ b/GHC/Arr.lhs @@ -1,5 +1,5 @@ \begin{code} -{-# OPTIONS_GHC -fno-implicit-prelude #-} +{-# OPTIONS_GHC -fno-implicit-prelude -fno-bang-patterns #-} ----------------------------------------------------------------------------- -- | -- Module : GHC.Arr @@ -75,12 +75,16 @@ class (Ord a) => Ix a where unsafeRangeSize :: (a,a) -> Int -- Must specify one of index, unsafeIndex - index b i | inRange b i = unsafeIndex b i + index b i | inRange b i = unsafeIndex b i | otherwise = error "Error in array index" unsafeIndex b i = index b i rangeSize b@(_l,h) | inRange b h = unsafeIndex b h + 1 - | otherwise = 0 + | otherwise = 0 -- This case is only here to + -- check for an empty range + -- NB: replacing (inRange b h) by (l <= h) fails for + -- tuples. E.g. (1,2) <= (2,1) but the range is empty + unsafeRangeSize b@(_l,h) = unsafeIndex b h + 1 \end{code} @@ -195,15 +199,15 @@ instance Ix () where instance (Ix a, Ix b) => Ix (a, b) where -- as derived {-# SPECIALISE instance Ix (Int,Int) #-} - {- INLINE range #-} + {-# INLINE range #-} range ((l1,l2),(u1,u2)) = [ (i1,i2) | i1 <- range (l1,u1), i2 <- range (l2,u2) ] - {- INLINE unsafeIndex #-} + {-# INLINE unsafeIndex #-} unsafeIndex ((l1,l2),(u1,u2)) (i1,i2) = unsafeIndex (l1,u1) i1 * unsafeRangeSize (l2,u2) + unsafeIndex (l2,u2) i2 - {- INLINE inRange #-} + {-# INLINE inRange #-} inRange ((l1,l2),(u1,u2)) (i1,i2) = inRange (l1,u1) i1 && inRange (l2,u2) i2