+% -----------------------------------------------------------------------------
+% $Id: Array.lhs,v 1.16 2001/04/14 22:27:00 qrczak Exp $
%
-% (c) The AQUA Project, Glasgow University, 1994-1999
+% (c) The University of Glasgow, 1994-2000
%
-
\section[Array]{Module @Array@}
\begin{code}
-- Implementation checked wrt. Haskell 98 lib report, 1/99.
) where
+\end{code}
#ifndef __HUGS__
+
+\begin{code}
+ ------------ GHC --------------------
import Ix
-import PrelList
-import PrelShow
import PrelArr -- Most of the hard work is done here
-import PrelBase
-#else
-import Ix
-import List( (\\) )
-#endif
-
-infixl 9 !, //
+ ------------ End of GHC --------------------
\end{code}
-#ifndef __HUGS__
-
-
-%*********************************************************
-%* *
-\subsection{Definitions of array, !, bounds}
-%* *
-%*********************************************************
+#else
\begin{code}
+ ------------ HUGS (rest of file) --------------------
+import PrelPrim ( PrimArray
+ , runST
+ , primNewArray
+ , primWriteArray
+ , primReadArray
+ , primUnsafeFreezeArray
+ , primIndexArray
+ )
+import Ix
+import List( (\\) )
-
-{-# SPECIALISE listArray :: (Int,Int) -> [b] -> Array Int b #-}
-listArray :: (Ix a) => (a,a) -> [b] -> Array a b
-listArray b vs = array b (zip (range b) vs)
-
-{-# INLINE elems #-}
-elems :: (Ix a) => Array a b -> [b]
-elems a = [a!i | i <- indices a]
-
-ixmap :: (Ix a, Ix b) => (a,a) -> (a -> b) -> Array b c -> Array a c
-ixmap b f a = array b [(i, a ! f i) | i <- range b]
+infixl 9 !, //
\end{code}
%*********************************************************
%* *
-\subsection{Instance declarations for Array type}
+\subsection{The Array type}
%* *
%*********************************************************
-#else
\begin{code}
data Array ix elt = Array (ix,ix) (PrimArray elt)
array :: Ix a => (a,a) -> [(a,b)] -> Array a b
-array ixs@(ix_start, ix_end) ivs = primRunST (do
+array ixs@(ix_start, ix_end) ivs = runST (do
{ mut_arr <- primNewArray (rangeSize ixs) arrEleBottom
; mapM_ (\ (i,v) -> primWriteArray mut_arr (index ixs i) v) ivs
; arr <- primUnsafeFreezeArray mut_arr
assocs a = [(i, a!i) | i <- indices a]
(//) :: Ix a => Array a b -> [(a,b)] -> Array a b
-a // us = array (bounds a)
+(//) a us = array (bounds a)
([(i,a!i) | i <- indices a \\ [i | (i,_) <- us]]
++ us)