-- Must specify one of index, unsafeIndex
index b i | inRange b i = unsafeIndex b i
| otherwise = error "Error in array index"
- -- ToDo: raise (ArrayException IndexOutOfRange)
unsafeIndex b i = index b i
\end{code}
arrEleBottom :: a
arrEleBottom = error "(Array.!): undefined array element"
--- ToDo: arrEleBottom = throw (ArrayException (UndefinedElement "Array.!"))
+
-----------------------------------------------------------------------
-- These also go better with magic: (//), accum, accumArray
% -----------------------------------------------------------------------------
-% $Id: PrelException.lhs,v 1.9 1999/11/11 15:18:00 simonmar Exp $
+% $Id: PrelException.lhs,v 1.10 1999/11/11 15:20:29 simonmar Exp $
%
% (c) The GRAP/AQUA Project, Glasgow University, 1998
%
| AssertionFailed String -- Assertions
| DynException Dynamic -- Dynamic exceptions
| AsyncException AsyncException -- Externally generated errors
- | ArrayException ArrayException -- Array-related exceptions
| NonTermination
data ArithException
| ThreadKilled
deriving (Eq, Ord)
-data ArrayException
- = IndexOutOfBounds String
- | UndefinedElement String
- deriving (Eq, Ord)
-
stackOverflow, heapOverflow :: Exception -- for the RTS
stackOverflow = AsyncException StackOverflow
heapOverflow = AsyncException HeapOverflow
showsPrec _ HeapOverflow = showString "heap overflow"
showsPrec _ ThreadKilled = showString "thread killed"
-instance Show ArrayException where
- showsPrec _ (IndexOutOfBounds s) = showString "array index out of bounds: "
- . showString s
- showsPrec _ (UndefinedElement s) = showString "undefined array element: "
- . showString s
-
instance Show Exception where
showsPrec _ (IOException err) = shows err
showsPrec _ (ArithException err) = shows err
eqForeignObj mp1 mp2
= unsafePerformIO (primEqForeignObj mp1 mp2) /= (0::Int)
-foreign import "eqForeignObj" unsafe primEqForeignObj :: ForeignObj -> ForeignObj -> IO Int
+foreign import "eqForeignObj" primEqForeignObj :: ForeignObj -> ForeignObj -> IO Int
instance Eq ForeignObj where
p == q = eqForeignObj p q