Commit f4275e0d authored by Don Stewart's avatar Don Stewart
Browse files

untabify

parent c0e1b8dd
......@@ -17,10 +17,10 @@ module Data.Bool (
-- * Booleans
Bool(..),
-- ** Operations
(&&), -- :: Bool -> Bool -> Bool
(||), -- :: Bool -> Bool -> Bool
not, -- :: Bool -> Bool
otherwise, -- :: Bool
(&&), -- :: Bool -> Bool -> Bool
(||), -- :: Bool -> Bool -> Bool
not, -- :: Bool -> Bool
otherwise, -- :: Bool
) where
#ifdef __GLASGOW_HASKELL__
......
......@@ -13,7 +13,7 @@
--
-----------------------------------------------------------------------------
module Data.Char
module Data.Char
(
Char
......@@ -48,7 +48,7 @@ module Data.Char
-- * String representations
, showLitChar -- :: Char -> ShowS
, lexLitChar -- :: ReadS String
, lexLitChar -- :: ReadS String
, readLitChar -- :: ReadS Char
-- Implementation checked wrt. Haskell 98 lib report, 1/99.
......@@ -85,10 +85,10 @@ foreign import ccall unsafe "WCsubst.h u_gencat" wgencat :: CInt -> CInt
-- (i.e. @\'0\'@..@\'9\'@, @\'a\'@..@\'f\'@, @\'A\'@..@\'F\'@).
digitToInt :: Char -> Int
digitToInt c
| isDigit c = ord c - ord '0'
| isDigit c = ord c - ord '0'
| c >= 'a' && c <= 'f' = ord c - ord 'a' + 10
| c >= 'A' && c <= 'F' = ord c - ord 'A' + 10
| otherwise = error ("Char.digitToInt: not a digit " ++ show c) -- sigh
| otherwise = error ("Char.digitToInt: not a digit " ++ show c) -- sigh
#ifndef __GLASGOW_HASKELL__
isAsciiUpper, isAsciiLower :: Char -> Bool
......
......@@ -18,16 +18,16 @@
-----------------------------------------------------------------------------
module Data.HashTable (
-- * Basic hash table operations
HashTable, new, insert, delete, lookup, update,
-- * Converting to and from lists
fromList, toList,
-- * Hash functions
-- $hash_functions
hashInt, hashString,
prime,
-- * Diagnostics
longestChain
-- * Basic hash table operations
HashTable, new, insert, delete, lookup, update,
-- * Converting to and from lists
fromList, toList,
-- * Hash functions
-- $hash_functions
hashInt, hashString,
prime,
-- * Diagnostics
longestChain
) where
-- This module is imported by Data.Dynamic, which is pretty low down in the
......@@ -36,36 +36,36 @@ module Data.HashTable (
#ifdef __GLASGOW_HASKELL__
import GHC.Base
#else
import Prelude hiding ( lookup )
import Prelude hiding ( lookup )
#endif
import Data.Tuple ( fst )
import Data.Tuple ( fst )
import Data.Bits
import Data.Maybe
import Data.List ( maximumBy, length, concat, foldl', partition )
import Data.Int ( Int32 )
import Data.List ( maximumBy, length, concat, foldl', partition )
import Data.Int ( Int32 )
#if defined(__GLASGOW_HASKELL__)
import GHC.Num
import GHC.Real ( fromIntegral )
import GHC.Show ( Show(..) )
import GHC.Int ( Int64 )
import GHC.Real ( fromIntegral )
import GHC.Show ( Show(..) )
import GHC.Int ( Int64 )
import GHC.IOBase ( IO, IOArray, newIOArray,
unsafeReadIOArray, unsafeWriteIOArray, unsafePerformIO,
IORef, newIORef, readIORef, writeIORef )
import GHC.IOBase ( IO, IOArray, newIOArray,
unsafeReadIOArray, unsafeWriteIOArray, unsafePerformIO,
IORef, newIORef, readIORef, writeIORef )
#else
import Data.Char ( ord )
import Data.IORef ( IORef, newIORef, readIORef, writeIORef )
import System.IO.Unsafe ( unsafePerformIO )
import Data.Int ( Int64 )
import Data.Char ( ord )
import Data.IORef ( IORef, newIORef, readIORef, writeIORef )
import System.IO.Unsafe ( unsafePerformIO )
import Data.Int ( Int64 )
# if defined(__HUGS__)
import Hugs.IOArray ( IOArray, newIOArray,
unsafeReadIOArray, unsafeWriteIOArray )
import Hugs.IOArray ( IOArray, newIOArray,
unsafeReadIOArray, unsafeWriteIOArray )
# elif defined(__NHC__)
import NHC.IOExtras ( IOArray, newIOArray, readIOArray, writeIOArray )
import NHC.IOExtras ( IOArray, newIOArray, readIOArray, writeIOArray )
# endif
#endif
import Control.Monad ( mapM, mapM_, sequence_ )
import Control.Monad ( mapM, mapM_, sequence_ )
-----------------------------------------------------------------------
......@@ -101,17 +101,17 @@ thawArray = return -- unsafeThaw
#endif
data HashTable key val = HashTable {
cmp :: !(key -> key -> Bool),
hash_fn :: !(key -> Int32),
cmp :: !(key -> key -> Bool),
hash_fn :: !(key -> Int32),
tab :: !(IORef (HT key val))
}
-- TODO: the IORef should really be an MVar.
data HT key val
= HT {
kcount :: !Int32, -- Total number of keys.
kcount :: !Int32, -- Total number of keys.
bmask :: !Int32,
buckets :: !(HTArray [(key,val)])
buckets :: !(HTArray [(key,val)])
}
-- ------------------------------------------------------------
......@@ -278,7 +278,7 @@ hYSTERESIS = 64 -- entries to ignore in load computation
--
new
:: (key -> key -> Bool) -- ^ @eq@: An equality comparison on keys
-> (key -> Int32) -- ^ @hash@: A hash function on keys
-> (key -> Int32) -- ^ @hash@: A hash function on keys
-> IO (HashTable key val) -- ^ Returns: an empty hash table
new cmpr hash = do
......
......@@ -2,9 +2,9 @@
-- The -fallow-overlapping-instances flag allows the user to over-ride
-- the instances for Typeable given here. In particular, we provide an instance
-- instance ... => Typeable (s a)
-- instance ... => Typeable (s a)
-- But a user might want to say
-- instance ... => Typeable (MyType a b)
-- instance ... => Typeable (MyType a b)
-----------------------------------------------------------------------------
-- |
......@@ -30,54 +30,54 @@
module Data.Typeable
(
-- * The Typeable class
Typeable( typeOf ), -- :: a -> TypeRep
-- * Type-safe cast
cast, -- :: (Typeable a, Typeable b) => a -> Maybe b
gcast, -- a generalisation of cast
-- * Type representations
TypeRep, -- abstract, instance of: Eq, Show, Typeable
TyCon, -- abstract, instance of: Eq, Show, Typeable
showsTypeRep,
-- * Construction of type representations
mkTyCon, -- :: String -> TyCon
mkTyConApp, -- :: TyCon -> [TypeRep] -> TypeRep
mkAppTy, -- :: TypeRep -> TypeRep -> TypeRep
mkFunTy, -- :: TypeRep -> TypeRep -> TypeRep
-- * Observation of type representations
splitTyConApp, -- :: TypeRep -> (TyCon, [TypeRep])
funResultTy, -- :: TypeRep -> TypeRep -> Maybe TypeRep
typeRepTyCon, -- :: TypeRep -> TyCon
typeRepArgs, -- :: TypeRep -> [TypeRep]
tyConString, -- :: TyCon -> String
typeRepKey, -- :: TypeRep -> IO Int
-- * The other Typeable classes
-- | /Note:/ The general instances are provided for GHC only.
Typeable1( typeOf1 ), -- :: t a -> TypeRep
Typeable2( typeOf2 ), -- :: t a b -> TypeRep
Typeable3( typeOf3 ), -- :: t a b c -> TypeRep
Typeable4( typeOf4 ), -- :: t a b c d -> TypeRep
Typeable5( typeOf5 ), -- :: t a b c d e -> TypeRep
Typeable6( typeOf6 ), -- :: t a b c d e f -> TypeRep
Typeable7( typeOf7 ), -- :: t a b c d e f g -> TypeRep
gcast1, -- :: ... => c (t a) -> Maybe (c (t' a))
gcast2, -- :: ... => c (t a b) -> Maybe (c (t' a b))
-- * Default instances
-- | /Note:/ These are not needed by GHC, for which these instances
-- are generated by general instance declarations.
typeOfDefault, -- :: (Typeable1 t, Typeable a) => t a -> TypeRep
typeOf1Default, -- :: (Typeable2 t, Typeable a) => t a b -> TypeRep
typeOf2Default, -- :: (Typeable3 t, Typeable a) => t a b c -> TypeRep
typeOf3Default, -- :: (Typeable4 t, Typeable a) => t a b c d -> TypeRep
typeOf4Default, -- :: (Typeable5 t, Typeable a) => t a b c d e -> TypeRep
typeOf5Default, -- :: (Typeable6 t, Typeable a) => t a b c d e f -> TypeRep
typeOf6Default -- :: (Typeable7 t, Typeable a) => t a b c d e f g -> TypeRep
-- * The Typeable class
Typeable( typeOf ), -- :: a -> TypeRep
-- * Type-safe cast
cast, -- :: (Typeable a, Typeable b) => a -> Maybe b
gcast, -- a generalisation of cast
-- * Type representations
TypeRep, -- abstract, instance of: Eq, Show, Typeable
TyCon, -- abstract, instance of: Eq, Show, Typeable
showsTypeRep,
-- * Construction of type representations
mkTyCon, -- :: String -> TyCon
mkTyConApp, -- :: TyCon -> [TypeRep] -> TypeRep
mkAppTy, -- :: TypeRep -> TypeRep -> TypeRep
mkFunTy, -- :: TypeRep -> TypeRep -> TypeRep
-- * Observation of type representations
splitTyConApp, -- :: TypeRep -> (TyCon, [TypeRep])
funResultTy, -- :: TypeRep -> TypeRep -> Maybe TypeRep
typeRepTyCon, -- :: TypeRep -> TyCon
typeRepArgs, -- :: TypeRep -> [TypeRep]
tyConString, -- :: TyCon -> String
typeRepKey, -- :: TypeRep -> IO Int
-- * The other Typeable classes
-- | /Note:/ The general instances are provided for GHC only.
Typeable1( typeOf1 ), -- :: t a -> TypeRep
Typeable2( typeOf2 ), -- :: t a b -> TypeRep
Typeable3( typeOf3 ), -- :: t a b c -> TypeRep
Typeable4( typeOf4 ), -- :: t a b c d -> TypeRep
Typeable5( typeOf5 ), -- :: t a b c d e -> TypeRep
Typeable6( typeOf6 ), -- :: t a b c d e f -> TypeRep
Typeable7( typeOf7 ), -- :: t a b c d e f g -> TypeRep
gcast1, -- :: ... => c (t a) -> Maybe (c (t' a))
gcast2, -- :: ... => c (t a b) -> Maybe (c (t' a b))
-- * Default instances
-- | /Note:/ These are not needed by GHC, for which these instances
-- are generated by general instance declarations.
typeOfDefault, -- :: (Typeable1 t, Typeable a) => t a -> TypeRep
typeOf1Default, -- :: (Typeable2 t, Typeable a) => t a b -> TypeRep
typeOf2Default, -- :: (Typeable3 t, Typeable a) => t a b c -> TypeRep
typeOf3Default, -- :: (Typeable4 t, Typeable a) => t a b c d -> TypeRep
typeOf4Default, -- :: (Typeable5 t, Typeable a) => t a b c d e -> TypeRep
typeOf5Default, -- :: (Typeable6 t, Typeable a) => t a b c d e f -> TypeRep
typeOf6Default -- :: (Typeable7 t, Typeable a) => t a b c d e f g -> TypeRep
) where
......@@ -95,45 +95,45 @@ import GHC.Show
import GHC.Err
import GHC.Num
import GHC.Float
import GHC.Real ( rem, Ratio )
import GHC.IOBase (IORef,newIORef,unsafePerformIO)
import GHC.Real ( rem, Ratio )
import GHC.IOBase (IORef,newIORef,unsafePerformIO)
-- These imports are so we can define Typeable instances
-- It'd be better to give Typeable instances in the modules themselves
-- but they all have to be compiled before Typeable
import GHC.IOBase ( IO, MVar, Exception, ArithException, IOException,
ArrayException, AsyncException, Handle )
import GHC.ST ( ST )
import GHC.STRef ( STRef )
import GHC.IOBase ( IO, MVar, Exception, ArithException, IOException,
ArrayException, AsyncException, Handle )
import GHC.ST ( ST )
import GHC.STRef ( STRef )
import GHC.Ptr ( Ptr, FunPtr )
import GHC.ForeignPtr ( ForeignPtr )
import GHC.Stable ( StablePtr, newStablePtr, freeStablePtr,
deRefStablePtr, castStablePtrToPtr,
castPtrToStablePtr )
import GHC.Exception ( block )
import GHC.Arr ( Array, STArray )
import GHC.Stable ( StablePtr, newStablePtr, freeStablePtr,
deRefStablePtr, castStablePtrToPtr,
castPtrToStablePtr )
import GHC.Exception ( block )
import GHC.Arr ( Array, STArray )
#endif
#ifdef __HUGS__
import Hugs.Prelude ( Key(..), TypeRep(..), TyCon(..), Ratio,
Exception, ArithException, IOException,
ArrayException, AsyncException, Handle,
Ptr, FunPtr, ForeignPtr, StablePtr )
import Hugs.IORef ( IORef, newIORef, readIORef, writeIORef )
import Hugs.IOExts ( unsafePerformIO )
-- For the Typeable instance
import Hugs.Array ( Array )
import Hugs.ConcBase ( MVar )
import Hugs.Prelude ( Key(..), TypeRep(..), TyCon(..), Ratio,
Exception, ArithException, IOException,
ArrayException, AsyncException, Handle,
Ptr, FunPtr, ForeignPtr, StablePtr )
import Hugs.IORef ( IORef, newIORef, readIORef, writeIORef )
import Hugs.IOExts ( unsafePerformIO )
-- For the Typeable instance
import Hugs.Array ( Array )
import Hugs.ConcBase ( MVar )
#endif
#ifdef __NHC__
import NHC.IOExtras (IORef,newIORef,readIORef,writeIORef,unsafePerformIO)
import IO (Handle)
import Ratio (Ratio)
-- For the Typeable instance
import NHC.FFI ( Ptr,FunPtr,StablePtr,ForeignPtr )
import Array ( Array )
-- For the Typeable instance
import NHC.FFI ( Ptr,FunPtr,StablePtr,ForeignPtr )
import Array ( Array )
#endif
#include "Typeable.h"
......@@ -142,7 +142,7 @@ import Array ( Array )
-------------------------------------------------------------
--
-- Type representations
-- Type representations
--
-------------------------------------------------------------
......@@ -175,16 +175,16 @@ instance Eq TyCon where
typeRepKey :: TypeRep -> IO Int
typeRepKey (TypeRep (Key i) _ _) = return i
--
-- let fTy = mkTyCon "Foo" in show (mkTyConApp (mkTyCon ",,")
-- [fTy,fTy,fTy])
--
-- returns "(Foo,Foo,Foo)"
--
-- The TypeRep Show instance promises to print tuple types
-- correctly. Tuple type constructors are specified by a
-- sequence of commas, e.g., (mkTyCon ",,,,") returns
-- the 5-tuple tycon.
--
-- let fTy = mkTyCon "Foo" in show (mkTyConApp (mkTyCon ",,")
-- [fTy,fTy,fTy])
--
-- returns "(Foo,Foo,Foo)"
--
-- The TypeRep Show instance promises to print tuple types
-- correctly. Tuple type constructors are specified by a
-- sequence of commas, e.g., (mkTyCon ",,,,") returns
-- the 5-tuple tycon.
----------------- Construction --------------------
......@@ -238,10 +238,10 @@ mkAppTy (TypeRep tr_k tc trs) arg_tr
-- > mkTyCon "a" == mkTyCon "a"
--
mkTyCon :: String -- ^ the name of the type constructor (should be unique
-- in the program, so it might be wise to use the
-- fully qualified name).
-> TyCon -- ^ A unique 'TyCon' object
mkTyCon :: String -- ^ the name of the type constructor (should be unique
-- in the program, so it might be wise to use the
-- fully qualified name).
-> TyCon -- ^ A unique 'TyCon' object
mkTyCon str = TyCon (mkTyConKey str) str
----------------- Observation ---------------------
......@@ -266,15 +266,15 @@ instance Show TypeRep where
[] -> showsPrec p tycon
[x] | tycon == listTc -> showChar '[' . shows x . showChar ']'
[a,r] | tycon == funTc -> showParen (p > 8) $
showsPrec 9 a .
showsPrec 9 a .
showString " -> " .
showsPrec 8 r
xs | isTupleTyCon tycon -> showTuple xs
| otherwise ->
showParen (p > 9) $
showsPrec p tycon .
showChar ' ' .
showArgs tys
| otherwise ->
showParen (p > 9) $
showsPrec p tycon .
showChar ' ' .
showArgs tys
showsTypeRep :: TypeRep -> ShowS
showsTypeRep = shows
......@@ -284,7 +284,7 @@ instance Show TyCon where
isTupleTyCon :: TyCon -> Bool
isTupleTyCon (TyCon _ ('(':',':_)) = True
isTupleTyCon _ = False
isTupleTyCon _ = False
-- Some (Show.TypeRep) helpers:
......@@ -301,7 +301,7 @@ showTuple args = showChar '('
-------------------------------------------------------------
--
-- The Typeable class and friends
-- The Typeable class and friends
--
-------------------------------------------------------------
......@@ -437,7 +437,7 @@ instance (Typeable7 s, Typeable a)
-------------------------------------------------------------
--
-- Type-safe cast
-- Type-safe cast
--
-------------------------------------------------------------
......@@ -445,9 +445,9 @@ instance (Typeable7 s, Typeable a)
cast :: (Typeable a, Typeable b) => a -> Maybe b
cast x = r
where
r = if typeOf x == typeOf (fromJust r)
r = if typeOf x == typeOf (fromJust r)
then Just $ unsafeCoerce x
else Nothing
else Nothing
-- | A flexible variation parameterised in a type constructor
gcast :: (Typeable a, Typeable b) => c a -> Maybe (c b)
......@@ -481,7 +481,7 @@ gcast2 x = r
-------------------------------------------------------------
--
-- Instances of the Typeable classes for Prelude types
-- Instances of the Typeable classes for Prelude types
--
-------------------------------------------------------------
......@@ -588,7 +588,7 @@ INSTANCE_TYPEABLE0(RealWorld,realWorldTc,"RealWorld")
---------------------------------------------
--
-- Internals
-- Internals
--
---------------------------------------------
......@@ -601,9 +601,9 @@ data KeyPr = KeyPr !Key !Key deriving( Eq )
hashKP :: KeyPr -> Int32
hashKP (KeyPr (Key k1) (Key k2)) = (HT.hashInt k1 + HT.hashInt k2) `rem` HT.prime
data Cache = Cache { next_key :: !(IORef Key), -- Not used by GHC (calls genSym instead)
tc_tbl :: !(HT.HashTable String Key),
ap_tbl :: !(HT.HashTable KeyPr Key) }
data Cache = Cache { next_key :: !(IORef Key), -- Not used by GHC (calls genSym instead)
tc_tbl :: !(HT.HashTable String Key),
ap_tbl :: !(HT.HashTable KeyPr Key) }
{-# NOINLINE cache #-}
#ifdef __GLASGOW_HASKELL__
......@@ -613,25 +613,25 @@ foreign import ccall unsafe "RtsTypeable.h getOrSetTypeableStore"
cache :: Cache
cache = unsafePerformIO $ do
empty_tc_tbl <- HT.new (==) HT.hashString
empty_ap_tbl <- HT.new (==) hashKP
key_loc <- newIORef (Key 1)
let ret = Cache { next_key = key_loc,
tc_tbl = empty_tc_tbl,
ap_tbl = empty_ap_tbl }
empty_tc_tbl <- HT.new (==) HT.hashString
empty_ap_tbl <- HT.new (==) hashKP
key_loc <- newIORef (Key 1)
let ret = Cache { next_key = key_loc,
tc_tbl = empty_tc_tbl,
ap_tbl = empty_ap_tbl }
#ifdef __GLASGOW_HASKELL__
block $ do
stable_ref <- newStablePtr ret
let ref = castStablePtrToPtr stable_ref
ref2 <- getOrSetTypeableStore ref
if ref==ref2
then deRefStablePtr stable_ref
else do
freeStablePtr stable_ref
deRefStablePtr
(castPtrToStablePtr ref2)
block $ do
stable_ref <- newStablePtr ret
let ref = castStablePtrToPtr stable_ref
ref2 <- getOrSetTypeableStore ref
if ref==ref2
then deRefStablePtr stable_ref
else do
freeStablePtr stable_ref
deRefStablePtr
(castPtrToStablePtr ref2)
#else
return ret
return ret
#endif
newKey :: IORef Key -> IO Key
......@@ -639,8 +639,8 @@ newKey :: IORef Key -> IO Key
newKey kloc = do i <- genSym; return (Key i)
#else
newKey kloc = do { k@(Key i) <- readIORef kloc ;
writeIORef kloc (Key (i+1)) ;
return k }
writeIORef kloc (Key (i+1)) ;
return k }
#endif
#ifdef __GLASGOW_HASKELL__
......@@ -651,24 +651,24 @@ foreign import ccall unsafe "genSymZh"
mkTyConKey :: String -> Key
mkTyConKey str
= unsafePerformIO $ do
let Cache {next_key = kloc, tc_tbl = tbl} = cache
mb_k <- HT.lookup tbl str
case mb_k of
Just k -> return k
Nothing -> do { k <- newKey kloc ;
HT.insert tbl str k ;
return k }
let Cache {next_key = kloc, tc_tbl = tbl} = cache
mb_k <- HT.lookup tbl str
case mb_k of
Just k -> return k
Nothing -> do { k <- newKey kloc ;
HT.insert tbl str k ;
return k }
appKey :: Key -> Key -> Key
appKey k1 k2
= unsafePerformIO $ do
let Cache {next_key = kloc, ap_tbl = tbl} = cache
mb_k <- HT.lookup tbl kpr
case mb_k of
Just k -> return k
Nothing -> do { k <- newKey kloc ;
HT.insert tbl kpr k ;
return k }
let Cache {next_key = kloc, ap_tbl = tbl} = cache
mb_k <- HT.lookup tbl kpr
case mb_k of
Just k -> return k
Nothing -> do { k <- newKey kloc ;
HT.insert tbl kpr k ;
return k }
where
kpr = KeyPr k1 k2
......
......@@ -18,22 +18,22 @@
module Foreign.Ptr (
-- * Data pointers
Ptr, -- data Ptr a
nullPtr, -- :: Ptr a
castPtr, -- :: Ptr a -> Ptr b
plusPtr, -- :: Ptr a -> Int -> Ptr b
alignPtr, -- :: Ptr a -> Int -> Ptr a
minusPtr, -- :: Ptr a -> Ptr b -> Int
-- * Function pointers
FunPtr, -- data FunPtr a
nullFunPtr, -- :: FunPtr a
castFunPtr, -- :: FunPtr a -> FunPtr b
castFunPtrToPtr, -- :: FunPtr a -> Ptr b
castPtrToFunPtr, -- :: Ptr a -> FunPtr b
freeHaskellFunPtr, -- :: FunPtr a -> IO ()
-- Free the function pointer created by foreign export dynamic.
......@@ -57,17 +57,17 @@ import GHC.Read
import GHC.Real
import GHC.Show
import GHC.Enum
import GHC.Word ( Word(..) )
import GHC.Word ( Word(..) )
import Data.Int
import Data.Word
#else
import Control.Monad ( liftM )