projects
/
haskell-directory.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
disambiguate uses of foldr for nhc98 to compile without errors
[haskell-directory.git]
/
GHC
/
Arr.lhs
diff --git
a/GHC/Arr.lhs
b/GHC/Arr.lhs
index
b376c2f
..
87ce3b2
100644
(file)
--- a/
GHC/Arr.lhs
+++ b/
GHC/Arr.lhs
@@
-1,5
+1,5
@@
\begin{code}
\begin{code}
-{-# OPTIONS_GHC -fno-implicit-prelude #-}
+{-# OPTIONS_GHC -fno-implicit-prelude -fno-bang-patterns #-}
-----------------------------------------------------------------------------
-- |
-- Module : GHC.Arr
-----------------------------------------------------------------------------
-- |
-- Module : GHC.Arr
@@
-14,6
+14,7
@@
--
-----------------------------------------------------------------------------
--
-----------------------------------------------------------------------------
+-- #hide
module GHC.Arr where
import {-# SOURCE #-} GHC.Err ( error )
module GHC.Arr where
import {-# SOURCE #-} GHC.Err ( error )
@@
-71,22
+72,20
@@
class (Ord a) => Ix a where
rangeSize :: (a,a) -> Int
-- | like 'rangeSize', but without checking that the upper bound is
-- in range.
rangeSize :: (a,a) -> Int
-- | like 'rangeSize', but without checking that the upper bound is
-- in range.
- --
- -- As long as you don't override the default 'rangeSize', you can
- -- specify 'unsafeRangeSize' as follows, to speed up some operations:
- --
- -- > unsafeRangeSize b@(_l,h) = unsafeIndex b h + 1
- --
unsafeRangeSize :: (a,a) -> Int
-- Must specify one of index, unsafeIndex
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 = error "Error in array index"
unsafeIndex b i = index b i
rangeSize b@(_l,h) | inRange b h = unsafeIndex b h + 1
- | otherwise = 0
- unsafeRangeSize b = rangeSize b
+ | 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}
Note that the following is NOT right
\end{code}
Note that the following is NOT right
@@
-130,8
+129,6
@@
instance Ix Char where
inRange (m,n) i = m <= i && i <= n
inRange (m,n) i = m <= i && i <= n
- unsafeRangeSize b@(_l,h) = unsafeIndex b h + 1
-
----------------------------------------------------------------------
instance Ix Int where
{-# INLINE range #-}
----------------------------------------------------------------------
instance Ix Int where
{-# INLINE range #-}
@@
-148,8
+145,6
@@
instance Ix Int where
{-# INLINE inRange #-}
inRange (I# m,I# n) (I# i) = m <=# i && i <=# n
{-# INLINE inRange #-}
inRange (I# m,I# n) (I# i) = m <=# i && i <=# n
- unsafeRangeSize b@(_l,h) = unsafeIndex b h + 1
-
----------------------------------------------------------------------
instance Ix Integer where
{-# INLINE range #-}
----------------------------------------------------------------------
instance Ix Integer where
{-# INLINE range #-}
@@
-163,8
+158,6
@@
instance Ix Integer where
inRange (m,n) i = m <= i && i <= n
inRange (m,n) i = m <= i && i <= n
- unsafeRangeSize b@(_l,h) = unsafeIndex b h + 1
-
----------------------------------------------------------------------
instance Ix Bool where -- as derived
{-# INLINE range #-}
----------------------------------------------------------------------
instance Ix Bool where -- as derived
{-# INLINE range #-}
@@
-178,8
+171,6
@@
instance Ix Bool where -- as derived
inRange (l,u) i = fromEnum i >= fromEnum l && fromEnum i <= fromEnum u
inRange (l,u) i = fromEnum i >= fromEnum l && fromEnum i <= fromEnum u
- unsafeRangeSize b@(_l,h) = unsafeIndex b h + 1
-
----------------------------------------------------------------------
instance Ix Ordering where -- as derived
{-# INLINE range #-}
----------------------------------------------------------------------
instance Ix Ordering where -- as derived
{-# INLINE range #-}
@@
-193,8
+184,6
@@
instance Ix Ordering where -- as derived
inRange (l,u) i = fromEnum i >= fromEnum l && fromEnum i <= fromEnum u
inRange (l,u) i = fromEnum i >= fromEnum l && fromEnum i <= fromEnum u
- unsafeRangeSize b@(_l,h) = unsafeIndex b h + 1
-
----------------------------------------------------------------------
instance Ix () where
{-# INLINE range #-}
----------------------------------------------------------------------
instance Ix () where
{-# INLINE range #-}
@@
-206,8
+195,6
@@
instance Ix () where
{-# INLINE index #-}
index b i = unsafeIndex b i
{-# INLINE index #-}
index b i = unsafeIndex b i
- unsafeRangeSize b@(_l,h) = unsafeIndex b h + 1
-
----------------------------------------------------------------------
instance (Ix a, Ix b) => Ix (a, b) where -- as derived
{-# SPECIALISE instance Ix (Int,Int) #-}
----------------------------------------------------------------------
instance (Ix a, Ix b) => Ix (a, b) where -- as derived
{-# SPECIALISE instance Ix (Int,Int) #-}
@@
-224,8
+211,6
@@
instance (Ix a, Ix b) => Ix (a, b) where -- as derived
inRange ((l1,l2),(u1,u2)) (i1,i2) =
inRange (l1,u1) i1 && inRange (l2,u2) i2
inRange ((l1,l2),(u1,u2)) (i1,i2) =
inRange (l1,u1) i1 && inRange (l2,u2) i2
- unsafeRangeSize b@(_l,h) = unsafeIndex b h + 1
-
-- Default method for index
----------------------------------------------------------------------
-- Default method for index
----------------------------------------------------------------------
@@
-246,8
+231,6
@@
instance (Ix a1, Ix a2, Ix a3) => Ix (a1,a2,a3) where
inRange (l1,u1) i1 && inRange (l2,u2) i2 &&
inRange (l3,u3) i3
inRange (l1,u1) i1 && inRange (l2,u2) i2 &&
inRange (l3,u3) i3
- unsafeRangeSize b@(_l,h) = unsafeIndex b h + 1
-
-- Default method for index
----------------------------------------------------------------------
-- Default method for index
----------------------------------------------------------------------
@@
-268,8
+251,6
@@
instance (Ix a1, Ix a2, Ix a3, Ix a4) => Ix (a1,a2,a3,a4) where
inRange (l1,u1) i1 && inRange (l2,u2) i2 &&
inRange (l3,u3) i3 && inRange (l4,u4) i4
inRange (l1,u1) i1 && inRange (l2,u2) i2 &&
inRange (l3,u3) i3 && inRange (l4,u4) i4
- unsafeRangeSize b@(_l,h) = unsafeIndex b h + 1
-
-- Default method for index
instance (Ix a1, Ix a2, Ix a3, Ix a4, Ix a5) => Ix (a1,a2,a3,a4,a5) where
-- Default method for index
instance (Ix a1, Ix a2, Ix a3, Ix a4, Ix a5) => Ix (a1,a2,a3,a4,a5) where
@@
-292,8
+273,6
@@
instance (Ix a1, Ix a2, Ix a3, Ix a4, Ix a5) => Ix (a1,a2,a3,a4,a5) where
inRange (l3,u3) i3 && inRange (l4,u4) i4 &&
inRange (l5,u5) i5
inRange (l3,u3) i3 && inRange (l4,u4) i4 &&
inRange (l5,u5) i5
- unsafeRangeSize b@(_l,h) = unsafeIndex b h + 1
-
-- Default method for index
\end{code}
-- Default method for index
\end{code}