packages feed

base 4.7.0.2 → 4.8.0.0

raw patch · 223 files changed

+20260/−17251 lines, 223 filesdep ~ghc-primdep ~integer-gmpsetup-changedPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: ghc-prim, integer-gmp

API changes (from Hackage documentation)

- Control.Applicative: Const :: a -> Const a b
- Control.Applicative: WrapArrow :: a b c -> WrappedArrow a b c
- Control.Applicative: WrapMonad :: m a -> WrappedMonad m a
- Control.Applicative: ZipList :: [a] -> ZipList a
- Control.Applicative: getConst :: Const a b -> a
- Control.Applicative: getZipList :: ZipList a -> [a]
- Control.Applicative: instance Alternative Maybe
- Control.Applicative: instance Alternative ReadP
- Control.Applicative: instance Alternative ReadPrec
- Control.Applicative: instance Alternative STM
- Control.Applicative: instance Alternative []
- Control.Applicative: instance Applicative ((->) a)
- Control.Applicative: instance Applicative (Either e)
- Control.Applicative: instance Applicative (ST s)
- Control.Applicative: instance Applicative IO
- Control.Applicative: instance Applicative Maybe
- Control.Applicative: instance Applicative Proxy
- Control.Applicative: instance Applicative ReadP
- Control.Applicative: instance Applicative ReadPrec
- Control.Applicative: instance Applicative STM
- Control.Applicative: instance Applicative []
- Control.Applicative: instance Arrow a => Applicative (ArrowMonad a)
- Control.Applicative: instance ArrowPlus a => Alternative (ArrowMonad a)
- Control.Applicative: instance Monoid a => Applicative ((,) a)
- Control.Applicative: instance Typeable Alternative
- Control.Applicative: instance Typeable Applicative
- Control.Applicative: unwrapArrow :: WrappedArrow a b c -> a b c
- Control.Applicative: unwrapMonad :: WrappedMonad m a -> m a
- Control.Arrow: ArrowMonad :: (a () b) -> ArrowMonad a b
- Control.Arrow: Kleisli :: (a -> m b) -> Kleisli m a b
- Control.Arrow: runKleisli :: Kleisli m a b -> a -> m b
- Control.Concurrent.Chan: instance Typeable Chan
- Control.Concurrent.QSemN: instance Typeable QSemN
- Control.Exception: AssertionFailed :: String -> AssertionFailed
- Control.Exception: BlockedIndefinitelyOnMVar :: BlockedIndefinitelyOnMVar
- Control.Exception: BlockedIndefinitelyOnSTM :: BlockedIndefinitelyOnSTM
- Control.Exception: Deadlock :: Deadlock
- Control.Exception: Denormal :: ArithException
- Control.Exception: DivideByZero :: ArithException
- Control.Exception: ErrorCall :: String -> ErrorCall
- Control.Exception: Handler :: (e -> IO a) -> Handler a
- Control.Exception: HeapOverflow :: AsyncException
- Control.Exception: IndexOutOfBounds :: String -> ArrayException
- Control.Exception: LossOfPrecision :: ArithException
- Control.Exception: MaskedInterruptible :: MaskingState
- Control.Exception: MaskedUninterruptible :: MaskingState
- Control.Exception: NestedAtomically :: NestedAtomically
- Control.Exception: NoMethodError :: String -> NoMethodError
- Control.Exception: NonTermination :: NonTermination
- Control.Exception: Overflow :: ArithException
- Control.Exception: PatternMatchFail :: String -> PatternMatchFail
- Control.Exception: RatioZeroDenominator :: ArithException
- Control.Exception: RecConError :: String -> RecConError
- Control.Exception: RecSelError :: String -> RecSelError
- Control.Exception: RecUpdError :: String -> RecUpdError
- Control.Exception: SomeAsyncException :: e -> SomeAsyncException
- Control.Exception: SomeException :: e -> SomeException
- Control.Exception: StackOverflow :: AsyncException
- Control.Exception: ThreadKilled :: AsyncException
- Control.Exception: UndefinedElement :: String -> ArrayException
- Control.Exception: Underflow :: ArithException
- Control.Exception: Unmasked :: MaskingState
- Control.Exception: UserInterrupt :: AsyncException
- Control.Exception.Base: AssertionFailed :: String -> AssertionFailed
- Control.Exception.Base: BlockedIndefinitelyOnMVar :: BlockedIndefinitelyOnMVar
- Control.Exception.Base: BlockedIndefinitelyOnSTM :: BlockedIndefinitelyOnSTM
- Control.Exception.Base: Deadlock :: Deadlock
- Control.Exception.Base: Denormal :: ArithException
- Control.Exception.Base: DivideByZero :: ArithException
- Control.Exception.Base: ErrorCall :: String -> ErrorCall
- Control.Exception.Base: HeapOverflow :: AsyncException
- Control.Exception.Base: IndexOutOfBounds :: String -> ArrayException
- Control.Exception.Base: LossOfPrecision :: ArithException
- Control.Exception.Base: MaskedInterruptible :: MaskingState
- Control.Exception.Base: MaskedUninterruptible :: MaskingState
- Control.Exception.Base: NestedAtomically :: NestedAtomically
- Control.Exception.Base: NoMethodError :: String -> NoMethodError
- Control.Exception.Base: NonTermination :: NonTermination
- Control.Exception.Base: Overflow :: ArithException
- Control.Exception.Base: PatternMatchFail :: String -> PatternMatchFail
- Control.Exception.Base: RatioZeroDenominator :: ArithException
- Control.Exception.Base: RecConError :: String -> RecConError
- Control.Exception.Base: RecSelError :: String -> RecSelError
- Control.Exception.Base: RecUpdError :: String -> RecUpdError
- Control.Exception.Base: SomeAsyncException :: e -> SomeAsyncException
- Control.Exception.Base: SomeException :: e -> SomeException
- Control.Exception.Base: StackOverflow :: AsyncException
- Control.Exception.Base: ThreadKilled :: AsyncException
- Control.Exception.Base: UndefinedElement :: String -> ArrayException
- Control.Exception.Base: Underflow :: ArithException
- Control.Exception.Base: Unmasked :: MaskingState
- Control.Exception.Base: UserInterrupt :: AsyncException
- Control.Exception.Base: instance Typeable NestedAtomically
- Control.Exception.Base: instance Typeable NoMethodError
- Control.Exception.Base: instance Typeable NonTermination
- Control.Exception.Base: instance Typeable PatternMatchFail
- Control.Exception.Base: instance Typeable RecConError
- Control.Exception.Base: instance Typeable RecSelError
- Control.Exception.Base: instance Typeable RecUpdError
- Control.Monad: instance MonadPlus Maybe
- Control.Monad: instance MonadPlus []
- Data.Bool: False :: Bool
- Data.Bool: True :: Bool
- Data.Char: ClosePunctuation :: GeneralCategory
- Data.Char: ConnectorPunctuation :: GeneralCategory
- Data.Char: Control :: GeneralCategory
- Data.Char: CurrencySymbol :: GeneralCategory
- Data.Char: DashPunctuation :: GeneralCategory
- Data.Char: DecimalNumber :: GeneralCategory
- Data.Char: EnclosingMark :: GeneralCategory
- Data.Char: FinalQuote :: GeneralCategory
- Data.Char: Format :: GeneralCategory
- Data.Char: InitialQuote :: GeneralCategory
- Data.Char: LetterNumber :: GeneralCategory
- Data.Char: LineSeparator :: GeneralCategory
- Data.Char: LowercaseLetter :: GeneralCategory
- Data.Char: MathSymbol :: GeneralCategory
- Data.Char: ModifierLetter :: GeneralCategory
- Data.Char: ModifierSymbol :: GeneralCategory
- Data.Char: NonSpacingMark :: GeneralCategory
- Data.Char: NotAssigned :: GeneralCategory
- Data.Char: OpenPunctuation :: GeneralCategory
- Data.Char: OtherLetter :: GeneralCategory
- Data.Char: OtherNumber :: GeneralCategory
- Data.Char: OtherPunctuation :: GeneralCategory
- Data.Char: OtherSymbol :: GeneralCategory
- Data.Char: ParagraphSeparator :: GeneralCategory
- Data.Char: PrivateUse :: GeneralCategory
- Data.Char: Space :: GeneralCategory
- Data.Char: SpacingCombiningMark :: GeneralCategory
- Data.Char: Surrogate :: GeneralCategory
- Data.Char: TitlecaseLetter :: GeneralCategory
- Data.Char: UppercaseLetter :: GeneralCategory
- Data.Complex: (:+) :: !a -> !a -> Complex a
- Data.Complex: instance Typeable Complex
- Data.Data: AlgConstr :: ConIndex -> ConstrRep
- Data.Data: AlgRep :: [Constr] -> DataRep
- Data.Data: CharConstr :: Char -> ConstrRep
- Data.Data: CharRep :: DataRep
- Data.Data: FloatConstr :: Rational -> ConstrRep
- Data.Data: FloatRep :: DataRep
- Data.Data: Infix :: Fixity
- Data.Data: IntConstr :: Integer -> ConstrRep
- Data.Data: IntRep :: DataRep
- Data.Data: NoRep :: DataRep
- Data.Data: Prefix :: Fixity
- Data.Dynamic: instance Typeable Dynamic
- Data.Either: Left :: a -> Either a b
- Data.Either: Right :: b -> Either a b
- Data.Either: instance Typeable Either
- Data.Fixed: MkFixed :: Integer -> Fixed a
- Data.Fixed: instance Typeable E0
- Data.Fixed: instance Typeable E1
- Data.Fixed: instance Typeable E12
- Data.Fixed: instance Typeable E2
- Data.Fixed: instance Typeable E3
- Data.Fixed: instance Typeable E6
- Data.Fixed: instance Typeable E9
- Data.Fixed: instance Typeable Fixed
- Data.Foldable: instance Foldable (Const m)
- Data.Maybe: Just :: a -> Maybe a
- Data.Maybe: Nothing :: Maybe a
- Data.Maybe: instance Eq a => Eq (Maybe a)
- Data.Maybe: instance Functor Maybe
- Data.Maybe: instance Monad Maybe
- Data.Maybe: instance Ord a => Ord (Maybe a)
- Data.Monoid: All :: Bool -> All
- Data.Monoid: Any :: Bool -> Any
- Data.Monoid: Dual :: a -> Dual a
- Data.Monoid: Endo :: (a -> a) -> Endo a
- Data.Monoid: First :: Maybe a -> First a
- Data.Monoid: Last :: Maybe a -> Last a
- Data.Monoid: Product :: a -> Product a
- Data.Monoid: Sum :: a -> Sum a
- Data.Monoid: appEndo :: Endo a -> a -> a
- Data.Monoid: getAll :: All -> Bool
- Data.Monoid: getAny :: Any -> Bool
- Data.Monoid: getDual :: Dual a -> a
- Data.Monoid: getFirst :: First a -> Maybe a
- Data.Monoid: getLast :: Last a -> Maybe a
- Data.Monoid: getProduct :: Product a -> a
- Data.Monoid: getSum :: Sum a -> a
- Data.Monoid: instance (Monoid a, Monoid b) => Monoid (a, b)
- Data.Monoid: instance (Monoid a, Monoid b, Monoid c) => Monoid (a, b, c)
- Data.Monoid: instance (Monoid a, Monoid b, Monoid c, Monoid d) => Monoid (a, b, c, d)
- Data.Monoid: instance (Monoid a, Monoid b, Monoid c, Monoid d, Monoid e) => Monoid (a, b, c, d, e)
- Data.Monoid: instance Monoid ()
- Data.Monoid: instance Monoid (Proxy s)
- Data.Monoid: instance Monoid Ordering
- Data.Monoid: instance Monoid [a]
- Data.Monoid: instance Monoid a => Monoid (Maybe a)
- Data.Monoid: instance Monoid b => Monoid (a -> b)
- Data.Monoid: instance Typeable Monoid
- Data.OldTypeable: cast :: (Typeable a, Typeable b) => a -> Maybe b
- Data.OldTypeable: class Typeable a
- Data.OldTypeable: class Typeable1 t
- Data.OldTypeable: class Typeable2 t
- Data.OldTypeable: class Typeable3 t
- Data.OldTypeable: class Typeable4 t
- Data.OldTypeable: class Typeable5 t
- Data.OldTypeable: class Typeable6 t
- Data.OldTypeable: class Typeable7 t
- Data.OldTypeable: data TyCon
- Data.OldTypeable: data TypeRep
- Data.OldTypeable: data TypeRepKey
- Data.OldTypeable: funResultTy :: TypeRep -> TypeRep -> Maybe TypeRep
- Data.OldTypeable: gcast :: (Typeable a, Typeable b) => c a -> Maybe (c b)
- Data.OldTypeable: gcast1 :: (Typeable1 t, Typeable1 t') => c (t a) -> Maybe (c (t' a))
- Data.OldTypeable: gcast2 :: (Typeable2 t, Typeable2 t') => c (t a b) -> Maybe (c (t' a b))
- Data.OldTypeable: instance [overlap ok] Eq TypeRepKey
- Data.OldTypeable: instance [overlap ok] Ord TypeRepKey
- Data.OldTypeable: mkAppTy :: TypeRep -> TypeRep -> TypeRep
- Data.OldTypeable: mkFunTy :: TypeRep -> TypeRep -> TypeRep
- Data.OldTypeable: mkTyCon :: String -> TyCon
- Data.OldTypeable: mkTyCon3 :: String -> String -> String -> TyCon
- Data.OldTypeable: mkTyConApp :: TyCon -> [TypeRep] -> TypeRep
- Data.OldTypeable: showsTypeRep :: TypeRep -> ShowS
- Data.OldTypeable: splitTyConApp :: TypeRep -> (TyCon, [TypeRep])
- Data.OldTypeable: tyConModule :: TyCon -> String
- Data.OldTypeable: tyConName :: TyCon -> String
- Data.OldTypeable: tyConPackage :: TyCon -> String
- Data.OldTypeable: tyConString :: TyCon -> String
- Data.OldTypeable: typeOf :: Typeable a => a -> TypeRep
- Data.OldTypeable: typeOf1 :: Typeable1 t => t a -> TypeRep
- Data.OldTypeable: typeOf1Default :: (Typeable2 t, Typeable a) => t a b -> TypeRep
- Data.OldTypeable: typeOf2 :: Typeable2 t => t a b -> TypeRep
- Data.OldTypeable: typeOf2Default :: (Typeable3 t, Typeable a) => t a b c -> TypeRep
- Data.OldTypeable: typeOf3 :: Typeable3 t => t a b c -> TypeRep
- Data.OldTypeable: typeOf3Default :: (Typeable4 t, Typeable a) => t a b c d -> TypeRep
- Data.OldTypeable: typeOf4 :: Typeable4 t => t a b c d -> TypeRep
- Data.OldTypeable: typeOf4Default :: (Typeable5 t, Typeable a) => t a b c d e -> TypeRep
- Data.OldTypeable: typeOf5 :: Typeable5 t => t a b c d e -> TypeRep
- Data.OldTypeable: typeOf5Default :: (Typeable6 t, Typeable a) => t a b c d e f -> TypeRep
- Data.OldTypeable: typeOf6 :: Typeable6 t => t a b c d e f -> TypeRep
- Data.OldTypeable: typeOf6Default :: (Typeable7 t, Typeable a) => t a b c d e f g -> TypeRep
- Data.OldTypeable: typeOf7 :: Typeable7 t => t a b c d e f g -> TypeRep
- Data.OldTypeable: typeOfDefault :: (Typeable1 t, Typeable a) => t a -> TypeRep
- Data.OldTypeable: typeRepArgs :: TypeRep -> [TypeRep]
- Data.OldTypeable: typeRepKey :: TypeRep -> IO TypeRepKey
- Data.OldTypeable: typeRepTyCon :: TypeRep -> TyCon
- Data.OldTypeable.Internal: TyCon :: {-# UNPACK #-} !Fingerprint -> String -> String -> String -> TyCon
- Data.OldTypeable.Internal: TypeRep :: {-# UNPACK #-} !Fingerprint -> TyCon -> [TypeRep] -> TypeRep
- Data.OldTypeable.Internal: class Typeable a
- Data.OldTypeable.Internal: class Typeable1 t
- Data.OldTypeable.Internal: class Typeable2 t
- Data.OldTypeable.Internal: class Typeable3 t
- Data.OldTypeable.Internal: class Typeable4 t
- Data.OldTypeable.Internal: class Typeable5 t
- Data.OldTypeable.Internal: class Typeable6 t
- Data.OldTypeable.Internal: class Typeable7 t
- Data.OldTypeable.Internal: data TyCon
- Data.OldTypeable.Internal: data TypeRep
- Data.OldTypeable.Internal: funResultTy :: TypeRep -> TypeRep -> Maybe TypeRep
- Data.OldTypeable.Internal: funTc :: TyCon
- Data.OldTypeable.Internal: instance [overlap ok] (Typeable1 s, Typeable a) => Typeable (s a)
- Data.OldTypeable.Internal: instance [overlap ok] (Typeable2 s, Typeable a) => Typeable1 (s a)
- Data.OldTypeable.Internal: instance [overlap ok] (Typeable3 s, Typeable a) => Typeable2 (s a)
- Data.OldTypeable.Internal: instance [overlap ok] (Typeable4 s, Typeable a) => Typeable3 (s a)
- Data.OldTypeable.Internal: instance [overlap ok] (Typeable5 s, Typeable a) => Typeable4 (s a)
- Data.OldTypeable.Internal: instance [overlap ok] (Typeable6 s, Typeable a) => Typeable5 (s a)
- Data.OldTypeable.Internal: instance [overlap ok] (Typeable7 s, Typeable a) => Typeable6 (s a)
- Data.OldTypeable.Internal: instance [overlap ok] Eq TyCon
- Data.OldTypeable.Internal: instance [overlap ok] Eq TypeRep
- Data.OldTypeable.Internal: instance [overlap ok] Ord TyCon
- Data.OldTypeable.Internal: instance [overlap ok] Ord TypeRep
- Data.OldTypeable.Internal: instance [overlap ok] Show TyCon
- Data.OldTypeable.Internal: instance [overlap ok] Show TypeRep
- Data.OldTypeable.Internal: instance [overlap ok] Typeable ()
- Data.OldTypeable.Internal: instance [overlap ok] Typeable Bool
- Data.OldTypeable.Internal: instance [overlap ok] Typeable Char
- Data.OldTypeable.Internal: instance [overlap ok] Typeable Double
- Data.OldTypeable.Internal: instance [overlap ok] Typeable Float
- Data.OldTypeable.Internal: instance [overlap ok] Typeable Int
- Data.OldTypeable.Internal: instance [overlap ok] Typeable Int16
- Data.OldTypeable.Internal: instance [overlap ok] Typeable Int32
- Data.OldTypeable.Internal: instance [overlap ok] Typeable Int64
- Data.OldTypeable.Internal: instance [overlap ok] Typeable Int8
- Data.OldTypeable.Internal: instance [overlap ok] Typeable Integer
- Data.OldTypeable.Internal: instance [overlap ok] Typeable Ordering
- Data.OldTypeable.Internal: instance [overlap ok] Typeable RealWorld
- Data.OldTypeable.Internal: instance [overlap ok] Typeable TyCon
- Data.OldTypeable.Internal: instance [overlap ok] Typeable TypeRep
- Data.OldTypeable.Internal: instance [overlap ok] Typeable Word
- Data.OldTypeable.Internal: instance [overlap ok] Typeable Word16
- Data.OldTypeable.Internal: instance [overlap ok] Typeable Word32
- Data.OldTypeable.Internal: instance [overlap ok] Typeable Word64
- Data.OldTypeable.Internal: instance [overlap ok] Typeable Word8
- Data.OldTypeable.Internal: instance [overlap ok] Typeable1 FunPtr
- Data.OldTypeable.Internal: instance [overlap ok] Typeable1 IO
- Data.OldTypeable.Internal: instance [overlap ok] Typeable1 IORef
- Data.OldTypeable.Internal: instance [overlap ok] Typeable1 MVar
- Data.OldTypeable.Internal: instance [overlap ok] Typeable1 Maybe
- Data.OldTypeable.Internal: instance [overlap ok] Typeable1 Ptr
- Data.OldTypeable.Internal: instance [overlap ok] Typeable1 Ratio
- Data.OldTypeable.Internal: instance [overlap ok] Typeable1 StablePtr
- Data.OldTypeable.Internal: instance [overlap ok] Typeable1 []
- Data.OldTypeable.Internal: instance [overlap ok] Typeable2 (,)
- Data.OldTypeable.Internal: instance [overlap ok] Typeable2 (->)
- Data.OldTypeable.Internal: instance [overlap ok] Typeable2 Array
- Data.OldTypeable.Internal: instance [overlap ok] Typeable2 IOArray
- Data.OldTypeable.Internal: instance [overlap ok] Typeable2 ST
- Data.OldTypeable.Internal: instance [overlap ok] Typeable2 STRef
- Data.OldTypeable.Internal: instance [overlap ok] Typeable3 (,,)
- Data.OldTypeable.Internal: instance [overlap ok] Typeable3 STArray
- Data.OldTypeable.Internal: instance [overlap ok] Typeable4 (,,,)
- Data.OldTypeable.Internal: instance [overlap ok] Typeable5 (,,,,)
- Data.OldTypeable.Internal: instance [overlap ok] Typeable6 (,,,,,)
- Data.OldTypeable.Internal: instance [overlap ok] Typeable7 (,,,,,,)
- Data.OldTypeable.Internal: listTc :: TyCon
- Data.OldTypeable.Internal: mkAppTy :: TypeRep -> TypeRep -> TypeRep
- Data.OldTypeable.Internal: mkFunTy :: TypeRep -> TypeRep -> TypeRep
- Data.OldTypeable.Internal: mkTyCon :: Word# -> Word# -> String -> String -> String -> TyCon
- Data.OldTypeable.Internal: mkTyCon3 :: String -> String -> String -> TyCon
- Data.OldTypeable.Internal: mkTyConApp :: TyCon -> [TypeRep] -> TypeRep
- Data.OldTypeable.Internal: showsTypeRep :: TypeRep -> ShowS
- Data.OldTypeable.Internal: splitTyConApp :: TypeRep -> (TyCon, [TypeRep])
- Data.OldTypeable.Internal: tyConHash :: TyCon -> {-# UNPACK #-} !Fingerprint
- Data.OldTypeable.Internal: tyConModule :: TyCon -> String
- Data.OldTypeable.Internal: tyConName :: TyCon -> String
- Data.OldTypeable.Internal: tyConPackage :: TyCon -> String
- Data.OldTypeable.Internal: tyConString :: TyCon -> String
- Data.OldTypeable.Internal: typeOf :: Typeable a => a -> TypeRep
- Data.OldTypeable.Internal: typeOf1 :: Typeable1 t => t a -> TypeRep
- Data.OldTypeable.Internal: typeOf1Default :: (Typeable2 t, Typeable a) => t a b -> TypeRep
- Data.OldTypeable.Internal: typeOf2 :: Typeable2 t => t a b -> TypeRep
- Data.OldTypeable.Internal: typeOf2Default :: (Typeable3 t, Typeable a) => t a b c -> TypeRep
- Data.OldTypeable.Internal: typeOf3 :: Typeable3 t => t a b c -> TypeRep
- Data.OldTypeable.Internal: typeOf3Default :: (Typeable4 t, Typeable a) => t a b c d -> TypeRep
- Data.OldTypeable.Internal: typeOf4 :: Typeable4 t => t a b c d -> TypeRep
- Data.OldTypeable.Internal: typeOf4Default :: (Typeable5 t, Typeable a) => t a b c d e -> TypeRep
- Data.OldTypeable.Internal: typeOf5 :: Typeable5 t => t a b c d e -> TypeRep
- Data.OldTypeable.Internal: typeOf5Default :: (Typeable6 t, Typeable a) => t a b c d e f -> TypeRep
- Data.OldTypeable.Internal: typeOf6 :: Typeable6 t => t a b c d e f -> TypeRep
- Data.OldTypeable.Internal: typeOf6Default :: (Typeable7 t, Typeable a) => t a b c d e f g -> TypeRep
- Data.OldTypeable.Internal: typeOf7 :: Typeable7 t => t a b c d e f g -> TypeRep
- Data.OldTypeable.Internal: typeOfDefault :: (Typeable1 t, Typeable a) => t a -> TypeRep
- Data.OldTypeable.Internal: typeRepArgs :: TypeRep -> [TypeRep]
- Data.OldTypeable.Internal: typeRepTyCon :: TypeRep -> TyCon
- Data.Ord: Down :: a -> Down a
- Data.Ord: EQ :: Ordering
- Data.Ord: GT :: Ordering
- Data.Ord: LT :: Ordering
- Data.Proxy: KProxy :: KProxy
- Data.Proxy: Proxy :: Proxy t
- Data.Proxy: instance Bounded (Proxy s)
- Data.Proxy: instance Enum (Proxy s)
- Data.Proxy: instance Eq (Proxy s)
- Data.Proxy: instance Ix (Proxy s)
- Data.Proxy: instance Ord (Proxy s)
- Data.Proxy: instance Read (Proxy s)
- Data.Proxy: instance Show (Proxy s)
- Data.Type.Coercion: Coercion :: Coercion a b
- Data.Type.Coercion: instance Coercible a b => Bounded (Coercion a b)
- Data.Type.Coercion: instance Coercible a b => Enum (Coercion a b)
- Data.Type.Coercion: instance Coercible a b => Read (Coercion a b)
- Data.Type.Coercion: instance Eq (Coercion a b)
- Data.Type.Coercion: instance Ord (Coercion a b)
- Data.Type.Coercion: instance Show (Coercion a b)
- Data.Type.Coercion: instance TestCoercion ((:~:) a)
- Data.Type.Coercion: instance TestCoercion (Coercion a)
- Data.Type.Equality: Refl :: a :~: a
- Data.Type.Equality: instance Eq (a :~: b)
- Data.Type.Equality: instance Ord (a :~: b)
- Data.Type.Equality: instance Show (a :~: b)
- Data.Type.Equality: instance TestEquality ((:~:) a)
- Data.Type.Equality: instance a ~ b => Bounded (a :~: b)
- Data.Type.Equality: instance a ~ b => Enum (a :~: b)
- Data.Type.Equality: instance a ~ b => Read (a :~: b)
- Data.Typeable: Proxy :: Proxy t
- Data.Typeable: Refl :: a :~: a
- Data.Typeable.Internal: Fingerprint :: {-# UNPACK #-} !Word64 -> {-# UNPACK #-} !Word64 -> Fingerprint
- Data.Typeable.Internal: Proxy :: Proxy t
- Data.Typeable.Internal: TyCon :: {-# UNPACK #-} !Fingerprint -> String -> String -> String -> TyCon
- Data.Typeable.Internal: TypeRep :: {-# UNPACK #-} !Fingerprint -> TyCon -> [TypeRep] -> TypeRep
- Data.Typeable.Internal: instance [overlap ok] (Typeable s, Typeable a) => Typeable (s a)
- Data.Typeable.Internal: instance [overlap ok] Eq TyCon
- Data.Typeable.Internal: instance [overlap ok] Eq TypeRep
- Data.Typeable.Internal: instance [overlap ok] Ord TyCon
- Data.Typeable.Internal: instance [overlap ok] Ord TypeRep
- Data.Typeable.Internal: instance [overlap ok] Show TyCon
- Data.Typeable.Internal: instance [overlap ok] Show TypeRep
- Data.Typeable.Internal: instance [overlap ok] Typeable ()
- Data.Typeable.Internal: instance [overlap ok] Typeable (,)
- Data.Typeable.Internal: instance [overlap ok] Typeable (,,)
- Data.Typeable.Internal: instance [overlap ok] Typeable (,,,)
- Data.Typeable.Internal: instance [overlap ok] Typeable (,,,,)
- Data.Typeable.Internal: instance [overlap ok] Typeable (,,,,,)
- Data.Typeable.Internal: instance [overlap ok] Typeable (,,,,,,)
- Data.Typeable.Internal: instance [overlap ok] Typeable (->)
- Data.Typeable.Internal: instance [overlap ok] Typeable (:~:)
- Data.Typeable.Internal: instance [overlap ok] Typeable Array
- Data.Typeable.Internal: instance [overlap ok] Typeable Bool
- Data.Typeable.Internal: instance [overlap ok] Typeable Char
- Data.Typeable.Internal: instance [overlap ok] Typeable Coercion
- Data.Typeable.Internal: instance [overlap ok] Typeable Double
- Data.Typeable.Internal: instance [overlap ok] Typeable Float
- Data.Typeable.Internal: instance [overlap ok] Typeable FunPtr
- Data.Typeable.Internal: instance [overlap ok] Typeable IO
- Data.Typeable.Internal: instance [overlap ok] Typeable Int
- Data.Typeable.Internal: instance [overlap ok] Typeable Integer
- Data.Typeable.Internal: instance [overlap ok] Typeable Maybe
- Data.Typeable.Internal: instance [overlap ok] Typeable Ordering
- Data.Typeable.Internal: instance [overlap ok] Typeable Proxy
- Data.Typeable.Internal: instance [overlap ok] Typeable Ptr
- Data.Typeable.Internal: instance [overlap ok] Typeable Ratio
- Data.Typeable.Internal: instance [overlap ok] Typeable RealWorld
- Data.Typeable.Internal: instance [overlap ok] Typeable ST
- Data.Typeable.Internal: instance [overlap ok] Typeable STArray
- Data.Typeable.Internal: instance [overlap ok] Typeable STRef
- Data.Typeable.Internal: instance [overlap ok] Typeable TyCon
- Data.Typeable.Internal: instance [overlap ok] Typeable TypeRep
- Data.Typeable.Internal: instance [overlap ok] Typeable Word
- Data.Typeable.Internal: instance [overlap ok] Typeable Word16
- Data.Typeable.Internal: instance [overlap ok] Typeable Word32
- Data.Typeable.Internal: instance [overlap ok] Typeable Word64
- Data.Typeable.Internal: instance [overlap ok] Typeable Word8
- Data.Typeable.Internal: instance [overlap ok] Typeable []
- Data.Typeable.Internal: tyConHash :: TyCon -> {-# UNPACK #-} !Fingerprint
- Data.Typeable.Internal: tyConModule :: TyCon -> String
- Data.Typeable.Internal: tyConName :: TyCon -> String
- Data.Typeable.Internal: tyConPackage :: TyCon -> String
- Data.Unique: instance Typeable Unique
- Data.Version: Version :: [Int] -> [String] -> Version
- Data.Version: instance Eq Version
- Data.Version: instance Ord Version
- Data.Version: instance Read Version
- Data.Version: instance Show Version
- Data.Version: instance Typeable Version
- Data.Version: versionBranch :: Version -> [Int]
- Data.Version: versionTags :: Version -> [String]
- Foreign.C.Error: Errno :: CInt -> Errno
- Foreign.C.Types: CChar :: Int8 -> CChar
- Foreign.C.Types: CClock :: Int64 -> CClock
- Foreign.C.Types: CDouble :: Double -> CDouble
- Foreign.C.Types: CFloat :: Float -> CFloat
- Foreign.C.Types: CInt :: Int32 -> CInt
- Foreign.C.Types: CIntMax :: Int64 -> CIntMax
- Foreign.C.Types: CIntPtr :: Int64 -> CIntPtr
- Foreign.C.Types: CLLong :: Int64 -> CLLong
- Foreign.C.Types: CLong :: Int64 -> CLong
- Foreign.C.Types: CPtrdiff :: Int64 -> CPtrdiff
- Foreign.C.Types: CSChar :: Int8 -> CSChar
- Foreign.C.Types: CSUSeconds :: Int64 -> CSUSeconds
- Foreign.C.Types: CShort :: Int16 -> CShort
- Foreign.C.Types: CSigAtomic :: Int32 -> CSigAtomic
- Foreign.C.Types: CSize :: Word64 -> CSize
- Foreign.C.Types: CTime :: Int64 -> CTime
- Foreign.C.Types: CUChar :: Word8 -> CUChar
- Foreign.C.Types: CUInt :: Word32 -> CUInt
- Foreign.C.Types: CUIntMax :: Word64 -> CUIntMax
- Foreign.C.Types: CUIntPtr :: Word64 -> CUIntPtr
- Foreign.C.Types: CULLong :: Word64 -> CULLong
- Foreign.C.Types: CULong :: Word64 -> CULong
- Foreign.C.Types: CUSeconds :: Word32 -> CUSeconds
- Foreign.C.Types: CUShort :: Word16 -> CUShort
- Foreign.C.Types: CWchar :: Int32 -> CWchar
- Foreign.C.Types: instance Typeable CChar
- Foreign.C.Types: instance Typeable CClock
- Foreign.C.Types: instance Typeable CDouble
- Foreign.C.Types: instance Typeable CFloat
- Foreign.C.Types: instance Typeable CInt
- Foreign.C.Types: instance Typeable CIntMax
- Foreign.C.Types: instance Typeable CIntPtr
- Foreign.C.Types: instance Typeable CLLong
- Foreign.C.Types: instance Typeable CLong
- Foreign.C.Types: instance Typeable CPtrdiff
- Foreign.C.Types: instance Typeable CSChar
- Foreign.C.Types: instance Typeable CSUSeconds
- Foreign.C.Types: instance Typeable CShort
- Foreign.C.Types: instance Typeable CSigAtomic
- Foreign.C.Types: instance Typeable CSize
- Foreign.C.Types: instance Typeable CTime
- Foreign.C.Types: instance Typeable CUChar
- Foreign.C.Types: instance Typeable CUInt
- Foreign.C.Types: instance Typeable CUIntMax
- Foreign.C.Types: instance Typeable CUIntPtr
- Foreign.C.Types: instance Typeable CULLong
- Foreign.C.Types: instance Typeable CULong
- Foreign.C.Types: instance Typeable CUSeconds
- Foreign.C.Types: instance Typeable CUShort
- Foreign.C.Types: instance Typeable CWchar
- Foreign.Ptr: instance Typeable IntPtr
- Foreign.Ptr: instance Typeable WordPtr
- GHC.Conc: BlockedOnBlackHole :: BlockReason
- GHC.Conc: BlockedOnException :: BlockReason
- GHC.Conc: BlockedOnForeignCall :: BlockReason
- GHC.Conc: BlockedOnMVar :: BlockReason
- GHC.Conc: BlockedOnOther :: BlockReason
- GHC.Conc: BlockedOnSTM :: BlockReason
- GHC.Conc: STM :: (State# RealWorld -> (# State# RealWorld, a #)) -> STM a
- GHC.Conc: TVar :: (TVar# RealWorld a) -> TVar a
- GHC.Conc: ThreadBlocked :: BlockReason -> ThreadStatus
- GHC.Conc: ThreadDied :: ThreadStatus
- GHC.Conc: ThreadFinished :: ThreadStatus
- GHC.Conc: ThreadId :: ThreadId# -> ThreadId
- GHC.Conc: ThreadRunning :: ThreadStatus
- GHC.Conc.Sync: BlockedOnBlackHole :: BlockReason
- GHC.Conc.Sync: BlockedOnException :: BlockReason
- GHC.Conc.Sync: BlockedOnForeignCall :: BlockReason
- GHC.Conc.Sync: BlockedOnMVar :: BlockReason
- GHC.Conc.Sync: BlockedOnOther :: BlockReason
- GHC.Conc.Sync: BlockedOnSTM :: BlockReason
- GHC.Conc.Sync: STM :: (State# RealWorld -> (# State# RealWorld, a #)) -> STM a
- GHC.Conc.Sync: TVar :: (TVar# RealWorld a) -> TVar a
- GHC.Conc.Sync: ThreadBlocked :: BlockReason -> ThreadStatus
- GHC.Conc.Sync: ThreadDied :: ThreadStatus
- GHC.Conc.Sync: ThreadFinished :: ThreadStatus
- GHC.Conc.Sync: ThreadId :: ThreadId# -> ThreadId
- GHC.Conc.Sync: ThreadRunning :: ThreadStatus
- GHC.Conc.Sync: instance Typeable STM
- GHC.Conc.Sync: instance Typeable TVar
- GHC.Conc.Sync: instance Typeable ThreadId
- GHC.Event: registerFd_ :: EventManager -> IOCallback -> Fd -> Event -> IO (FdKey, Bool)
- GHC.Exts: C# :: Char# -> Char
- GHC.Exts: D# :: Double# -> Double
- GHC.Exts: Down :: a -> Down a
- GHC.Exts: F# :: Float# -> Float
- GHC.Exts: ForceSpecConstr :: SpecConstrAnnotation
- GHC.Exts: FunPtr :: Addr# -> FunPtr a
- GHC.Exts: I# :: Int# -> Int
- GHC.Exts: NoSpecConstr :: SpecConstrAnnotation
- GHC.Exts: Ptr :: Addr# -> Ptr a
- GHC.Exts: W# :: Word# -> Word
- GHC.Exts: instance Typeable SpecConstrAnnotation
- GHC.Fingerprint: Fingerprint :: {-# UNPACK #-} !Word64 -> {-# UNPACK #-} !Word64 -> Fingerprint
- GHC.Fingerprint.Type: Fingerprint :: {-# UNPACK #-} !Word64 -> {-# UNPACK #-} !Word64 -> Fingerprint
- GHC.Generics: (:*:) :: f p -> g p -> (:*:) f g p
- GHC.Generics: Arity :: Int -> Arity
- GHC.Generics: Comp1 :: f (g p) -> (:.:) f g p
- GHC.Generics: Infix :: Associativity -> Int -> Fixity
- GHC.Generics: K1 :: c -> K1 i c p
- GHC.Generics: L1 :: (f p) -> (:+:) f g p
- GHC.Generics: LeftAssociative :: Associativity
- GHC.Generics: M1 :: f p -> M1 i c f p
- GHC.Generics: NoArity :: Arity
- GHC.Generics: NotAssociative :: Associativity
- GHC.Generics: Par1 :: p -> Par1 p
- GHC.Generics: Prefix :: Fixity
- GHC.Generics: R1 :: (g p) -> (:+:) f g p
- GHC.Generics: Rec1 :: f p -> Rec1 f p
- GHC.Generics: RightAssociative :: Associativity
- GHC.Generics: U1 :: U1 p
- GHC.Generics: unComp1 :: (:.:) f g p -> f (g p)
- GHC.Generics: unK1 :: K1 i c p -> c
- GHC.Generics: unM1 :: M1 i c f p -> f p
- GHC.Generics: unPar1 :: Par1 p -> p
- GHC.Generics: unRec1 :: Rec1 f p -> f p
- GHC.IO.Buffer: Buffer :: !(RawBuffer e) -> BufferState -> !Int -> !Int -> !Int -> Buffer e
- GHC.IO.Buffer: ReadBuffer :: BufferState
- GHC.IO.Buffer: WriteBuffer :: BufferState
- GHC.IO.Buffer: bufL :: Buffer e -> !Int
- GHC.IO.Buffer: bufR :: Buffer e -> !Int
- GHC.IO.Buffer: bufRaw :: Buffer e -> !(RawBuffer e)
- GHC.IO.Buffer: bufSize :: Buffer e -> !Int
- GHC.IO.Buffer: bufState :: Buffer e -> BufferState
- GHC.IO.Device: AbsoluteSeek :: SeekMode
- GHC.IO.Device: Directory :: IODeviceType
- GHC.IO.Device: RawDevice :: IODeviceType
- GHC.IO.Device: RegularFile :: IODeviceType
- GHC.IO.Device: RelativeSeek :: SeekMode
- GHC.IO.Device: SeekFromEnd :: SeekMode
- GHC.IO.Device: Stream :: IODeviceType
- GHC.IO.Encoding: BufferCodec :: CodeBuffer from to -> (Buffer from -> Buffer to -> IO (Buffer from, Buffer to)) -> IO () -> IO state -> (state -> IO ()) -> BufferCodec from to state
- GHC.IO.Encoding: InputUnderflow :: CodingProgress
- GHC.IO.Encoding: InvalidSequence :: CodingProgress
- GHC.IO.Encoding: OutputUnderflow :: CodingProgress
- GHC.IO.Encoding: TextEncoding :: String -> IO (TextDecoder dstate) -> IO (TextEncoder estate) -> TextEncoding
- GHC.IO.Encoding: close :: BufferCodec from to state -> IO ()
- GHC.IO.Encoding: encode :: BufferCodec from to state -> CodeBuffer from to
- GHC.IO.Encoding: getState :: BufferCodec from to state -> IO state
- GHC.IO.Encoding: mkTextDecoder :: TextEncoding -> IO (TextDecoder dstate)
- GHC.IO.Encoding: mkTextEncoder :: TextEncoding -> IO (TextEncoder estate)
- GHC.IO.Encoding: recover :: BufferCodec from to state -> Buffer from -> Buffer to -> IO (Buffer from, Buffer to)
- GHC.IO.Encoding: setState :: BufferCodec from to state -> state -> IO ()
- GHC.IO.Encoding: textEncodingName :: TextEncoding -> String
- GHC.IO.Encoding.Failure: ErrorOnCodingFailure :: CodingFailureMode
- GHC.IO.Encoding.Failure: IgnoreCodingFailure :: CodingFailureMode
- GHC.IO.Encoding.Failure: RoundtripFailure :: CodingFailureMode
- GHC.IO.Encoding.Failure: TransliterateCodingFailure :: CodingFailureMode
- GHC.IO.Encoding.Types: BufferCodec :: CodeBuffer from to -> (Buffer from -> Buffer to -> IO (Buffer from, Buffer to)) -> IO () -> IO state -> (state -> IO ()) -> BufferCodec from to state
- GHC.IO.Encoding.Types: InputUnderflow :: CodingProgress
- GHC.IO.Encoding.Types: InvalidSequence :: CodingProgress
- GHC.IO.Encoding.Types: OutputUnderflow :: CodingProgress
- GHC.IO.Encoding.Types: TextEncoding :: String -> IO (TextDecoder dstate) -> IO (TextEncoder estate) -> TextEncoding
- GHC.IO.Encoding.Types: close :: BufferCodec from to state -> IO ()
- GHC.IO.Encoding.Types: encode :: BufferCodec from to state -> CodeBuffer from to
- GHC.IO.Encoding.Types: getState :: BufferCodec from to state -> IO state
- GHC.IO.Encoding.Types: mkTextDecoder :: TextEncoding -> IO (TextDecoder dstate)
- GHC.IO.Encoding.Types: mkTextEncoder :: TextEncoding -> IO (TextEncoder estate)
- GHC.IO.Encoding.Types: recover :: BufferCodec from to state -> Buffer from -> Buffer to -> IO (Buffer from, Buffer to)
- GHC.IO.Encoding.Types: setState :: BufferCodec from to state -> state -> IO ()
- GHC.IO.Encoding.Types: textEncodingName :: TextEncoding -> String
- GHC.IO.Handle: AbsoluteSeek :: SeekMode
- GHC.IO.Handle: BlockBuffering :: (Maybe Int) -> BufferMode
- GHC.IO.Handle: CRLF :: Newline
- GHC.IO.Handle: HandlePosn :: Handle -> HandlePosition -> HandlePosn
- GHC.IO.Handle: LF :: Newline
- GHC.IO.Handle: LineBuffering :: BufferMode
- GHC.IO.Handle: NewlineMode :: Newline -> Newline -> NewlineMode
- GHC.IO.Handle: NoBuffering :: BufferMode
- GHC.IO.Handle: RelativeSeek :: SeekMode
- GHC.IO.Handle: SeekFromEnd :: SeekMode
- GHC.IO.Handle: inputNL :: NewlineMode -> Newline
- GHC.IO.Handle: outputNL :: NewlineMode -> Newline
- GHC.Stats: GCStats :: !Int64 -> !Int64 -> !Int64 -> !Int64 -> !Int64 -> !Int64 -> !Int64 -> !Int64 -> !Int64 -> !Int64 -> !Double -> !Double -> !Double -> !Double -> !Double -> !Double -> !Int64 -> !Int64 -> GCStats
- GHC.Stats: bytesAllocated :: GCStats -> !Int64
- GHC.Stats: bytesCopied :: GCStats -> !Int64
- GHC.Stats: cpuSeconds :: GCStats -> !Double
- GHC.Stats: cumulativeBytesUsed :: GCStats -> !Int64
- GHC.Stats: currentBytesSlop :: GCStats -> !Int64
- GHC.Stats: currentBytesUsed :: GCStats -> !Int64
- GHC.Stats: gcCpuSeconds :: GCStats -> !Double
- GHC.Stats: gcWallSeconds :: GCStats -> !Double
- GHC.Stats: instance [safe] Read GCStats
- GHC.Stats: instance [safe] Show GCStats
- GHC.Stats: maxBytesSlop :: GCStats -> !Int64
- GHC.Stats: maxBytesUsed :: GCStats -> !Int64
- GHC.Stats: mutatorCpuSeconds :: GCStats -> !Double
- GHC.Stats: mutatorWallSeconds :: GCStats -> !Double
- GHC.Stats: numByteUsageSamples :: GCStats -> !Int64
- GHC.Stats: numGcs :: GCStats -> !Int64
- GHC.Stats: parMaxBytesCopied :: GCStats -> !Int64
- GHC.Stats: parTotBytesCopied :: GCStats -> !Int64
- GHC.Stats: peakMegabytesAllocated :: GCStats -> !Int64
- GHC.Stats: wallSeconds :: GCStats -> !Double
- GHC.TypeLits: SomeNat :: (Proxy n) -> SomeNat
- GHC.TypeLits: SomeSymbol :: (Proxy n) -> SomeSymbol
- Prelude: (+, *, -) :: Num a => a -> a -> a
- Prelude: EQ :: Ordering
- Prelude: False :: Bool
- Prelude: GT :: Ordering
- Prelude: Just :: a -> Maybe a
- Prelude: LT :: Ordering
- Prelude: Left :: a -> Either a b
- Prelude: Nothing :: Maybe a
- Prelude: Right :: b -> Either a b
- Prelude: True :: Bool
- Prelude: asin, atan, acos :: Floating a => a -> a
- Prelude: asinh, atanh, acosh :: Floating a => a -> a
- Prelude: exp, sqrt, log :: Floating a => a -> a
- Prelude: sin, tan, cos :: Floating a => a -> a
- Prelude: sinh, tanh, cosh :: Floating a => a -> a
- System.Console.GetOpt: NoArg :: a -> ArgDescr a
- System.Console.GetOpt: OptArg :: (Maybe String -> a) -> String -> ArgDescr a
- System.Console.GetOpt: Option :: [Char] -> [String] -> (ArgDescr a) -> String -> OptDescr a
- System.Console.GetOpt: Permute :: ArgOrder a
- System.Console.GetOpt: ReqArg :: (String -> a) -> String -> ArgDescr a
- System.Console.GetOpt: RequireOrder :: ArgOrder a
- System.Console.GetOpt: ReturnInOrder :: (String -> a) -> ArgOrder a
- System.Exit: ExitFailure :: Int -> ExitCode
- System.Exit: ExitSuccess :: ExitCode
- System.IO: AbsoluteSeek :: SeekMode
- System.IO: AppendMode :: IOMode
- System.IO: BlockBuffering :: (Maybe Int) -> BufferMode
- System.IO: CRLF :: Newline
- System.IO: LF :: Newline
- System.IO: LineBuffering :: BufferMode
- System.IO: NewlineMode :: Newline -> Newline -> NewlineMode
- System.IO: NoBuffering :: BufferMode
- System.IO: ReadMode :: IOMode
- System.IO: ReadWriteMode :: IOMode
- System.IO: RelativeSeek :: SeekMode
- System.IO: SeekFromEnd :: SeekMode
- System.IO: WriteMode :: IOMode
- System.IO: inputNL :: NewlineMode -> Newline
- System.IO: outputNL :: NewlineMode -> Newline
- System.Mem.StableName: instance Typeable StableName
- System.Posix.Types: CCc :: Word8 -> CCc
- System.Posix.Types: CDev :: Word64 -> CDev
- System.Posix.Types: CGid :: Word32 -> CGid
- System.Posix.Types: CIno :: Word64 -> CIno
- System.Posix.Types: CMode :: Word32 -> CMode
- System.Posix.Types: CNlink :: Word64 -> CNlink
- System.Posix.Types: COff :: Int64 -> COff
- System.Posix.Types: CPid :: Int32 -> CPid
- System.Posix.Types: CRLim :: Word64 -> CRLim
- System.Posix.Types: CSpeed :: Word32 -> CSpeed
- System.Posix.Types: CSsize :: Int64 -> CSsize
- System.Posix.Types: CTcflag :: Word32 -> CTcflag
- System.Posix.Types: CUid :: Word32 -> CUid
- System.Posix.Types: Fd :: CInt -> Fd
- System.Posix.Types: instance Typeable CCc
- System.Posix.Types: instance Typeable CDev
- System.Posix.Types: instance Typeable CGid
- System.Posix.Types: instance Typeable CIno
- System.Posix.Types: instance Typeable CMode
- System.Posix.Types: instance Typeable CNlink
- System.Posix.Types: instance Typeable COff
- System.Posix.Types: instance Typeable CPid
- System.Posix.Types: instance Typeable CRLim
- System.Posix.Types: instance Typeable CSpeed
- System.Posix.Types: instance Typeable CSsize
- System.Posix.Types: instance Typeable CTcflag
- System.Posix.Types: instance Typeable CUid
- System.Posix.Types: instance Typeable Fd
- System.Timeout: instance Eq Timeout
- System.Timeout: instance Exception Timeout
- System.Timeout: instance Show Timeout
- System.Timeout: instance Typeable Timeout
- Text.Printf: FieldFormat :: Maybe Int -> Maybe Int -> Maybe FormatAdjustment -> Maybe FormatSign -> Bool -> String -> Char -> FieldFormat
- Text.Printf: FormatParse :: String -> Char -> String -> FormatParse
- Text.Printf: LeftAdjust :: FormatAdjustment
- Text.Printf: SignPlus :: FormatSign
- Text.Printf: SignSpace :: FormatSign
- Text.Printf: ZeroPad :: FormatAdjustment
- Text.Printf: fmtAdjust :: FieldFormat -> Maybe FormatAdjustment
- Text.Printf: fmtAlternate :: FieldFormat -> Bool
- Text.Printf: fmtChar :: FieldFormat -> Char
- Text.Printf: fmtModifiers :: FieldFormat -> String
- Text.Printf: fmtPrecision :: FieldFormat -> Maybe Int
- Text.Printf: fmtSign :: FieldFormat -> Maybe FormatSign
- Text.Printf: fmtWidth :: FieldFormat -> Maybe Int
- Text.Printf: fpChar :: FormatParse -> Char
- Text.Printf: fpModifiers :: FormatParse -> String
- Text.Printf: fpRest :: FormatParse -> String
- Text.Printf: instance [safe] a ~ () => HPrintfType (IO a)
- Text.Printf: instance [safe] a ~ () => PrintfType (IO a)
- Text.Read: Char :: Char -> Lexeme
- Text.Read: EOF :: Lexeme
- Text.Read: Ident :: String -> Lexeme
- Text.Read: Number :: Number -> Lexeme
- Text.Read: Punc :: String -> Lexeme
- Text.Read: String :: String -> Lexeme
- Text.Read: Symbol :: String -> Lexeme
- Text.Read.Lex: Char :: Char -> Lexeme
- Text.Read.Lex: EOF :: Lexeme
- Text.Read.Lex: Ident :: String -> Lexeme
- Text.Read.Lex: Number :: Number -> Lexeme
- Text.Read.Lex: Punc :: String -> Lexeme
- Text.Read.Lex: String :: String -> Lexeme
- Text.Read.Lex: Symbol :: String -> Lexeme
+ Control.Applicative: [Const] :: a -> Const a b
+ Control.Applicative: [WrapArrow] :: a b c -> WrappedArrow a b c
+ Control.Applicative: [WrapMonad] :: m a -> WrappedMonad m a
+ Control.Applicative: [ZipList] :: [a] -> ZipList a
+ Control.Applicative: [getConst] :: Const a b -> a
+ Control.Applicative: [getZipList] :: ZipList a -> [a]
+ Control.Applicative: [unwrapArrow] :: WrappedArrow a b c -> a b c
+ Control.Applicative: [unwrapMonad] :: WrappedMonad m a -> m a
+ Control.Applicative: instance Eq a => Eq (Const a b)
+ Control.Applicative: instance Foldable (Const m)
+ Control.Applicative: instance Ord a => Ord (Const a b)
+ Control.Applicative: instance Read a => Read (Const a b)
+ Control.Applicative: instance Show a => Show (Const a b)
+ Control.Arrow: [ArrowMonad] :: (a () b) -> ArrowMonad a b
+ Control.Arrow: [Kleisli] :: (a -> m b) -> Kleisli m a b
+ Control.Arrow: [runKleisli] :: Kleisli m a b -> a -> m b
+ Control.Arrow: instance Arrow a => Applicative (ArrowMonad a)
+ Control.Arrow: instance ArrowPlus a => Alternative (ArrowMonad a)
+ Control.Exception: [AllocationLimitExceeded] :: AllocationLimitExceeded
+ Control.Exception: [AssertionFailed] :: String -> AssertionFailed
+ Control.Exception: [BlockedIndefinitelyOnMVar] :: BlockedIndefinitelyOnMVar
+ Control.Exception: [BlockedIndefinitelyOnSTM] :: BlockedIndefinitelyOnSTM
+ Control.Exception: [Deadlock] :: Deadlock
+ Control.Exception: [Denormal] :: ArithException
+ Control.Exception: [DivideByZero] :: ArithException
+ Control.Exception: [ErrorCall] :: String -> ErrorCall
+ Control.Exception: [Handler] :: (e -> IO a) -> Handler a
+ Control.Exception: [HeapOverflow] :: AsyncException
+ Control.Exception: [IndexOutOfBounds] :: String -> ArrayException
+ Control.Exception: [LossOfPrecision] :: ArithException
+ Control.Exception: [MaskedInterruptible] :: MaskingState
+ Control.Exception: [MaskedUninterruptible] :: MaskingState
+ Control.Exception: [NestedAtomically] :: NestedAtomically
+ Control.Exception: [NoMethodError] :: String -> NoMethodError
+ Control.Exception: [NonTermination] :: NonTermination
+ Control.Exception: [Overflow] :: ArithException
+ Control.Exception: [PatternMatchFail] :: String -> PatternMatchFail
+ Control.Exception: [RatioZeroDenominator] :: ArithException
+ Control.Exception: [RecConError] :: String -> RecConError
+ Control.Exception: [RecSelError] :: String -> RecSelError
+ Control.Exception: [RecUpdError] :: String -> RecUpdError
+ Control.Exception: [SomeAsyncException] :: e -> SomeAsyncException
+ Control.Exception: [SomeException] :: e -> SomeException
+ Control.Exception: [StackOverflow] :: AsyncException
+ Control.Exception: [ThreadKilled] :: AsyncException
+ Control.Exception: [UndefinedElement] :: String -> ArrayException
+ Control.Exception: [Underflow] :: ArithException
+ Control.Exception: [Unmasked] :: MaskingState
+ Control.Exception: [UserInterrupt] :: AsyncException
+ Control.Exception: data AllocationLimitExceeded
+ Control.Exception: displayException :: Exception e => e -> String
+ Control.Exception.Base: [AllocationLimitExceeded] :: AllocationLimitExceeded
+ Control.Exception.Base: [AssertionFailed] :: String -> AssertionFailed
+ Control.Exception.Base: [BlockedIndefinitelyOnMVar] :: BlockedIndefinitelyOnMVar
+ Control.Exception.Base: [BlockedIndefinitelyOnSTM] :: BlockedIndefinitelyOnSTM
+ Control.Exception.Base: [Deadlock] :: Deadlock
+ Control.Exception.Base: [Denormal] :: ArithException
+ Control.Exception.Base: [DivideByZero] :: ArithException
+ Control.Exception.Base: [ErrorCall] :: String -> ErrorCall
+ Control.Exception.Base: [HeapOverflow] :: AsyncException
+ Control.Exception.Base: [IndexOutOfBounds] :: String -> ArrayException
+ Control.Exception.Base: [LossOfPrecision] :: ArithException
+ Control.Exception.Base: [MaskedInterruptible] :: MaskingState
+ Control.Exception.Base: [MaskedUninterruptible] :: MaskingState
+ Control.Exception.Base: [NestedAtomically] :: NestedAtomically
+ Control.Exception.Base: [NoMethodError] :: String -> NoMethodError
+ Control.Exception.Base: [NonTermination] :: NonTermination
+ Control.Exception.Base: [Overflow] :: ArithException
+ Control.Exception.Base: [PatternMatchFail] :: String -> PatternMatchFail
+ Control.Exception.Base: [RatioZeroDenominator] :: ArithException
+ Control.Exception.Base: [RecConError] :: String -> RecConError
+ Control.Exception.Base: [RecSelError] :: String -> RecSelError
+ Control.Exception.Base: [RecUpdError] :: String -> RecUpdError
+ Control.Exception.Base: [SomeAsyncException] :: e -> SomeAsyncException
+ Control.Exception.Base: [SomeException] :: e -> SomeException
+ Control.Exception.Base: [StackOverflow] :: AsyncException
+ Control.Exception.Base: [ThreadKilled] :: AsyncException
+ Control.Exception.Base: [UndefinedElement] :: String -> ArrayException
+ Control.Exception.Base: [Underflow] :: ArithException
+ Control.Exception.Base: [Unmasked] :: MaskingState
+ Control.Exception.Base: [UserInterrupt] :: AsyncException
+ Control.Exception.Base: data AllocationLimitExceeded
+ Control.Exception.Base: displayException :: Exception e => e -> String
+ Control.Monad: (<$!>) :: Monad m => (a -> b) -> m a -> m b
+ Control.Monad.Instances: (<$) :: Functor f => a -> f b -> f a
+ Data.Bifunctor: bimap :: Bifunctor p => (a -> b) -> (c -> d) -> p a c -> p b d
+ Data.Bifunctor: class Bifunctor p where bimap f g = first f . second g first f = bimap f id second = bimap id
+ Data.Bifunctor: first :: Bifunctor p => (a -> b) -> p a c -> p b c
+ Data.Bifunctor: instance [safe] Bifunctor ((,,) x1)
+ Data.Bifunctor: instance [safe] Bifunctor ((,,,) x1 x2)
+ Data.Bifunctor: instance [safe] Bifunctor ((,,,,) x1 x2 x3)
+ Data.Bifunctor: instance [safe] Bifunctor ((,,,,,) x1 x2 x3 x4)
+ Data.Bifunctor: instance [safe] Bifunctor ((,,,,,,) x1 x2 x3 x4 x5)
+ Data.Bifunctor: instance [safe] Bifunctor (,)
+ Data.Bifunctor: instance [safe] Bifunctor Const
+ Data.Bifunctor: instance [safe] Bifunctor Either
+ Data.Bifunctor: second :: Bifunctor p => (b -> c) -> p a b -> p a c
+ Data.Bits: countLeadingZeros :: FiniteBits b => b -> Int
+ Data.Bits: countTrailingZeros :: FiniteBits b => b -> Int
+ Data.Bits: toIntegralSized :: (Integral a, Integral b, Bits a, Bits b) => a -> Maybe b
+ Data.Bool: [False] :: Bool
+ Data.Bool: [True] :: Bool
+ Data.Char: [ClosePunctuation] :: GeneralCategory
+ Data.Char: [ConnectorPunctuation] :: GeneralCategory
+ Data.Char: [Control] :: GeneralCategory
+ Data.Char: [CurrencySymbol] :: GeneralCategory
+ Data.Char: [DashPunctuation] :: GeneralCategory
+ Data.Char: [DecimalNumber] :: GeneralCategory
+ Data.Char: [EnclosingMark] :: GeneralCategory
+ Data.Char: [FinalQuote] :: GeneralCategory
+ Data.Char: [Format] :: GeneralCategory
+ Data.Char: [InitialQuote] :: GeneralCategory
+ Data.Char: [LetterNumber] :: GeneralCategory
+ Data.Char: [LineSeparator] :: GeneralCategory
+ Data.Char: [LowercaseLetter] :: GeneralCategory
+ Data.Char: [MathSymbol] :: GeneralCategory
+ Data.Char: [ModifierLetter] :: GeneralCategory
+ Data.Char: [ModifierSymbol] :: GeneralCategory
+ Data.Char: [NonSpacingMark] :: GeneralCategory
+ Data.Char: [NotAssigned] :: GeneralCategory
+ Data.Char: [OpenPunctuation] :: GeneralCategory
+ Data.Char: [OtherLetter] :: GeneralCategory
+ Data.Char: [OtherNumber] :: GeneralCategory
+ Data.Char: [OtherPunctuation] :: GeneralCategory
+ Data.Char: [OtherSymbol] :: GeneralCategory
+ Data.Char: [ParagraphSeparator] :: GeneralCategory
+ Data.Char: [PrivateUse] :: GeneralCategory
+ Data.Char: [Space] :: GeneralCategory
+ Data.Char: [SpacingCombiningMark] :: GeneralCategory
+ Data.Char: [Surrogate] :: GeneralCategory
+ Data.Char: [TitlecaseLetter] :: GeneralCategory
+ Data.Char: [UppercaseLetter] :: GeneralCategory
+ Data.Complex: [:+] :: !a -> !a -> Complex a
+ Data.Complex: instance Storable a => Storable (Complex a)
+ Data.Data: [AlgConstr] :: ConIndex -> ConstrRep
+ Data.Data: [AlgRep] :: [Constr] -> DataRep
+ Data.Data: [CharConstr] :: Char -> ConstrRep
+ Data.Data: [CharRep] :: DataRep
+ Data.Data: [FloatConstr] :: Rational -> ConstrRep
+ Data.Data: [FloatRep] :: DataRep
+ Data.Data: [Infix] :: Fixity
+ Data.Data: [IntConstr] :: Integer -> ConstrRep
+ Data.Data: [IntRep] :: DataRep
+ Data.Data: [NoRep] :: DataRep
+ Data.Data: [Prefix] :: Fixity
+ Data.Either: [Left] :: a -> Either a b
+ Data.Either: [Right] :: b -> Either a b
+ Data.Either: instance Applicative (Either e)
+ Data.Fixed: [MkFixed] :: Integer -> Fixed a
+ Data.Foldable: instance Ord a => Monoid (Max a)
+ Data.Foldable: instance Ord a => Monoid (Min a)
+ Data.Foldable: length :: Foldable t => t a -> Int
+ Data.Foldable: null :: Foldable t => t a -> Bool
+ Data.Function: (&) :: a -> (a -> b) -> b
+ Data.Functor.Identity: [Identity] :: a -> Identity a
+ Data.Functor.Identity: [runIdentity] :: Identity a -> a
+ Data.Functor.Identity: instance Applicative Identity
+ Data.Functor.Identity: instance Constructor C1_0Identity
+ Data.Functor.Identity: instance Data a => Data (Identity a)
+ Data.Functor.Identity: instance Datatype D1Identity
+ Data.Functor.Identity: instance Eq a => Eq (Identity a)
+ Data.Functor.Identity: instance Foldable Identity
+ Data.Functor.Identity: instance Functor Identity
+ Data.Functor.Identity: instance Generic (Identity a)
+ Data.Functor.Identity: instance Generic1 Identity
+ Data.Functor.Identity: instance Monad Identity
+ Data.Functor.Identity: instance MonadFix Identity
+ Data.Functor.Identity: instance MonadZip Identity
+ Data.Functor.Identity: instance Ord a => Ord (Identity a)
+ Data.Functor.Identity: instance Read a => Read (Identity a)
+ Data.Functor.Identity: instance Selector S1_0_0Identity
+ Data.Functor.Identity: instance Show a => Show (Identity a)
+ Data.Functor.Identity: instance Traversable Identity
+ Data.Functor.Identity: newtype Identity a
+ Data.List: isSubsequenceOf :: (Eq a) => [a] -> [a] -> Bool
+ Data.List: scanl' :: (b -> a -> b) -> b -> [a] -> [b]
+ Data.List: sortOn :: Ord b => (a -> b) -> [a] -> [a]
+ Data.List: uncons :: [a] -> Maybe (a, [a])
+ Data.Maybe: [Just] :: a -> Maybe a
+ Data.Maybe: [Nothing] :: Maybe a
+ Data.Monoid: [All] :: Bool -> All
+ Data.Monoid: [Alt] :: f a -> Alt f a
+ Data.Monoid: [Any] :: Bool -> Any
+ Data.Monoid: [Dual] :: a -> Dual a
+ Data.Monoid: [Endo] :: (a -> a) -> Endo a
+ Data.Monoid: [First] :: Maybe a -> First a
+ Data.Monoid: [Last] :: Maybe a -> Last a
+ Data.Monoid: [Product] :: a -> Product a
+ Data.Monoid: [Sum] :: a -> Sum a
+ Data.Monoid: [appEndo] :: Endo a -> a -> a
+ Data.Monoid: [getAll] :: All -> Bool
+ Data.Monoid: [getAlt] :: Alt f a -> f a
+ Data.Monoid: [getAny] :: Any -> Bool
+ Data.Monoid: [getDual] :: Dual a -> a
+ Data.Monoid: [getFirst] :: First a -> Maybe a
+ Data.Monoid: [getLast] :: Last a -> Maybe a
+ Data.Monoid: [getProduct] :: Product a -> a
+ Data.Monoid: [getSum] :: Sum a -> a
+ Data.Monoid: instance Alternative f => Alternative (Alt f)
+ Data.Monoid: instance Alternative f => Monoid (Alt f a)
+ Data.Monoid: instance Applicative First
+ Data.Monoid: instance Applicative Last
+ Data.Monoid: instance Applicative f => Applicative (Alt f)
+ Data.Monoid: instance Constructor C1_0Alt
+ Data.Monoid: instance Datatype D1Alt
+ Data.Monoid: instance Functor First
+ Data.Monoid: instance Functor Last
+ Data.Monoid: instance Functor f => Functor (Alt f)
+ Data.Monoid: instance Generic1 (Alt f)
+ Data.Monoid: instance Monad First
+ Data.Monoid: instance Monad Last
+ Data.Monoid: instance Monad f => Monad (Alt f)
+ Data.Monoid: instance MonadPlus f => MonadPlus (Alt f)
+ Data.Monoid: instance Selector S1_0_0Alt
+ Data.Monoid: instance forall (k :: BOX) (f :: k -> *) (a :: k). Enum (f a) => Enum (Alt f a)
+ Data.Monoid: instance forall (k :: BOX) (f :: k -> *) (a :: k). Eq (f a) => Eq (Alt f a)
+ Data.Monoid: instance forall (k :: BOX) (f :: k -> *) (a :: k). Generic (Alt f a)
+ Data.Monoid: instance forall (k :: BOX) (f :: k -> *) (a :: k). Num (f a) => Num (Alt f a)
+ Data.Monoid: instance forall (k :: BOX) (f :: k -> *) (a :: k). Ord (f a) => Ord (Alt f a)
+ Data.Monoid: instance forall (k :: BOX) (f :: k -> *) (a :: k). Read (f a) => Read (Alt f a)
+ Data.Monoid: instance forall (k :: BOX) (f :: k -> *) (a :: k). Show (f a) => Show (Alt f a)
+ Data.Monoid: newtype Alt f a
+ Data.Ord: [Down] :: a -> Down a
+ Data.Ord: [EQ] :: Ordering
+ Data.Ord: [GT] :: Ordering
+ Data.Ord: [LT] :: Ordering
+ Data.Proxy: [KProxy] :: KProxy
+ Data.Proxy: [Proxy] :: Proxy t
+ Data.Proxy: instance Applicative Proxy
+ Data.Proxy: instance forall (k :: BOX) (s :: k). Bounded (Proxy s)
+ Data.Proxy: instance forall (k :: BOX) (s :: k). Enum (Proxy s)
+ Data.Proxy: instance forall (k :: BOX) (s :: k). Eq (Proxy s)
+ Data.Proxy: instance forall (k :: BOX) (s :: k). Ix (Proxy s)
+ Data.Proxy: instance forall (k :: BOX) (s :: k). Monoid (Proxy s)
+ Data.Proxy: instance forall (k :: BOX) (s :: k). Ord (Proxy s)
+ Data.Proxy: instance forall (k :: BOX) (s :: k). Read (Proxy s)
+ Data.Proxy: instance forall (k :: BOX) (s :: k). Show (Proxy s)
+ Data.Type.Coercion: [Coercion] :: Coercion a b
+ Data.Type.Coercion: instance forall (k :: BOX) (a :: k) (b :: k). Coercible a b => Bounded (Coercion a b)
+ Data.Type.Coercion: instance forall (k :: BOX) (a :: k) (b :: k). Coercible a b => Enum (Coercion a b)
+ Data.Type.Coercion: instance forall (k :: BOX) (a :: k) (b :: k). Coercible a b => Read (Coercion a b)
+ Data.Type.Coercion: instance forall (k :: BOX) (a :: k) (b :: k). Eq (Coercion a b)
+ Data.Type.Coercion: instance forall (k :: BOX) (a :: k) (b :: k). Ord (Coercion a b)
+ Data.Type.Coercion: instance forall (k :: BOX) (a :: k) (b :: k). Show (Coercion a b)
+ Data.Type.Coercion: instance forall (k :: BOX) (a :: k). TestCoercion ((:~:) a)
+ Data.Type.Coercion: instance forall (k :: BOX) (a :: k). TestCoercion (Coercion a)
+ Data.Type.Equality: [Refl] :: a :~: a
+ Data.Type.Equality: instance forall (k :: BOX) (a :: k) (b :: k). (a ~ b) => Bounded (a :~: b)
+ Data.Type.Equality: instance forall (k :: BOX) (a :: k) (b :: k). (a ~ b) => Enum (a :~: b)
+ Data.Type.Equality: instance forall (k :: BOX) (a :: k) (b :: k). (a ~ b) => Read (a :~: b)
+ Data.Type.Equality: instance forall (k :: BOX) (a :: k) (b :: k). Eq (a :~: b)
+ Data.Type.Equality: instance forall (k :: BOX) (a :: k) (b :: k). Ord (a :~: b)
+ Data.Type.Equality: instance forall (k :: BOX) (a :: k) (b :: k). Show (a :~: b)
+ Data.Type.Equality: instance forall (k :: BOX) (a :: k). TestEquality ((:~:) a)
+ Data.Typeable: [Proxy] :: Proxy t
+ Data.Typeable: [Refl] :: a :~: a
+ Data.Typeable: rnfTyCon :: TyCon -> ()
+ Data.Typeable: rnfTypeRep :: TypeRep -> ()
+ Data.Typeable: tyConFingerprint :: TyCon -> Fingerprint
+ Data.Typeable: typeRepFingerprint :: TypeRep -> Fingerprint
+ Data.Typeable.Internal: [Fingerprint] :: {-# UNPACK #-} !Word64 -> {-# UNPACK #-} !Word64 -> Fingerprint
+ Data.Typeable.Internal: [Proxy] :: Proxy t
+ Data.Typeable.Internal: [TyCon] :: {-# UNPACK #-} !Fingerprint -> String -> String -> String -> TyCon
+ Data.Typeable.Internal: [TypeRep] :: {-# UNPACK #-} !Fingerprint -> TyCon -> [KindRep] -> [TypeRep] -> TypeRep
+ Data.Typeable.Internal: [tyConFingerprint] :: TyCon -> {-# UNPACK #-} !Fingerprint
+ Data.Typeable.Internal: [tyConModule] :: TyCon -> String
+ Data.Typeable.Internal: [tyConName] :: TyCon -> String
+ Data.Typeable.Internal: [tyConPackage] :: TyCon -> String
+ Data.Typeable.Internal: instance Eq TyCon
+ Data.Typeable.Internal: instance Eq TypeRep
+ Data.Typeable.Internal: instance Ord TyCon
+ Data.Typeable.Internal: instance Ord TypeRep
+ Data.Typeable.Internal: instance Show TyCon
+ Data.Typeable.Internal: instance Show TypeRep
+ Data.Typeable.Internal: mkPolyTyConApp :: TyCon -> [KindRep] -> [TypeRep] -> TypeRep
+ Data.Typeable.Internal: rnfTyCon :: TyCon -> ()
+ Data.Typeable.Internal: rnfTypeRep :: TypeRep -> ()
+ Data.Typeable.Internal: splitPolyTyConApp :: TypeRep -> (TyCon, [KindRep], [TypeRep])
+ Data.Typeable.Internal: type KindRep = TypeRep
+ Data.Typeable.Internal: typeLitTypeRep :: String -> TypeRep
+ Data.Typeable.Internal: typeRepFingerprint :: TypeRep -> Fingerprint
+ Data.Typeable.Internal: typeRepKinds :: TypeRep -> [KindRep]
+ Data.Version: [Version] :: [Int] -> [String] -> Version
+ Data.Version: [versionBranch] :: Version -> [Int]
+ Data.Version: [versionTags] :: Version -> [String]
+ Data.Version: instance [safe] Eq Version
+ Data.Version: instance [safe] Ord Version
+ Data.Version: instance [safe] Read Version
+ Data.Version: instance [safe] Show Version
+ Data.Version: makeVersion :: [Int] -> Version
+ Data.Void: absurd :: Void -> a
+ Data.Void: data Void
+ Data.Void: instance [safe] Data Void
+ Data.Void: instance [safe] Datatype D1Void
+ Data.Void: instance [safe] Eq Void
+ Data.Void: instance [safe] Exception Void
+ Data.Void: instance [safe] Generic Void
+ Data.Void: instance [safe] Ix Void
+ Data.Void: instance [safe] Ord Void
+ Data.Void: instance [safe] Read Void
+ Data.Void: instance [safe] Show Void
+ Data.Void: vacuous :: Functor f => f Void -> f a
+ Foreign.C.Error: [Errno] :: CInt -> Errno
+ Foreign.C.Types: [CChar] :: Int8 -> CChar
+ Foreign.C.Types: [CClock] :: Int64 -> CClock
+ Foreign.C.Types: [CDouble] :: Double -> CDouble
+ Foreign.C.Types: [CFloat] :: Float -> CFloat
+ Foreign.C.Types: [CIntMax] :: Int64 -> CIntMax
+ Foreign.C.Types: [CIntPtr] :: Int64 -> CIntPtr
+ Foreign.C.Types: [CInt] :: Int32 -> CInt
+ Foreign.C.Types: [CLLong] :: Int64 -> CLLong
+ Foreign.C.Types: [CLong] :: Int64 -> CLong
+ Foreign.C.Types: [CPtrdiff] :: Int64 -> CPtrdiff
+ Foreign.C.Types: [CSChar] :: Int8 -> CSChar
+ Foreign.C.Types: [CSUSeconds] :: Int64 -> CSUSeconds
+ Foreign.C.Types: [CShort] :: Int16 -> CShort
+ Foreign.C.Types: [CSigAtomic] :: Int32 -> CSigAtomic
+ Foreign.C.Types: [CSize] :: Word64 -> CSize
+ Foreign.C.Types: [CTime] :: Int64 -> CTime
+ Foreign.C.Types: [CUChar] :: Word8 -> CUChar
+ Foreign.C.Types: [CUIntMax] :: Word64 -> CUIntMax
+ Foreign.C.Types: [CUIntPtr] :: Word64 -> CUIntPtr
+ Foreign.C.Types: [CUInt] :: Word32 -> CUInt
+ Foreign.C.Types: [CULLong] :: Word64 -> CULLong
+ Foreign.C.Types: [CULong] :: Word64 -> CULong
+ Foreign.C.Types: [CUSeconds] :: Word32 -> CUSeconds
+ Foreign.C.Types: [CUShort] :: Word16 -> CUShort
+ Foreign.C.Types: [CWchar] :: Int32 -> CWchar
+ Foreign.Marshal.Alloc: calloc :: Storable a => IO (Ptr a)
+ Foreign.Marshal.Alloc: callocBytes :: Int -> IO (Ptr a)
+ Foreign.Marshal.Array: callocArray :: Storable a => Int -> IO (Ptr a)
+ Foreign.Marshal.Array: callocArray0 :: Storable a => Int -> IO (Ptr a)
+ Foreign.Marshal.Utils: fillBytes :: Ptr a -> Word8 -> Int -> IO ()
+ Foreign.Storable: instance (Storable a, Integral a) => Storable (Ratio a)
+ GHC.Conc: [BlockedOnBlackHole] :: BlockReason
+ GHC.Conc: [BlockedOnException] :: BlockReason
+ GHC.Conc: [BlockedOnForeignCall] :: BlockReason
+ GHC.Conc: [BlockedOnMVar] :: BlockReason
+ GHC.Conc: [BlockedOnOther] :: BlockReason
+ GHC.Conc: [BlockedOnSTM] :: BlockReason
+ GHC.Conc: [STM] :: (State# RealWorld -> (# State# RealWorld, a #)) -> STM a
+ GHC.Conc: [TVar] :: (TVar# RealWorld a) -> TVar a
+ GHC.Conc: [ThreadBlocked] :: BlockReason -> ThreadStatus
+ GHC.Conc: [ThreadDied] :: ThreadStatus
+ GHC.Conc: [ThreadFinished] :: ThreadStatus
+ GHC.Conc: [ThreadId] :: ThreadId# -> ThreadId
+ GHC.Conc: [ThreadRunning] :: ThreadStatus
+ GHC.Conc: disableAllocationLimit :: IO ()
+ GHC.Conc: enableAllocationLimit :: IO ()
+ GHC.Conc: getAllocationCounter :: IO Int64
+ GHC.Conc: setAllocationCounter :: Int64 -> IO ()
+ GHC.Conc.Sync: [BlockedOnBlackHole] :: BlockReason
+ GHC.Conc.Sync: [BlockedOnException] :: BlockReason
+ GHC.Conc.Sync: [BlockedOnForeignCall] :: BlockReason
+ GHC.Conc.Sync: [BlockedOnMVar] :: BlockReason
+ GHC.Conc.Sync: [BlockedOnOther] :: BlockReason
+ GHC.Conc.Sync: [BlockedOnSTM] :: BlockReason
+ GHC.Conc.Sync: [STM] :: (State# RealWorld -> (# State# RealWorld, a #)) -> STM a
+ GHC.Conc.Sync: [TVar] :: (TVar# RealWorld a) -> TVar a
+ GHC.Conc.Sync: [ThreadBlocked] :: BlockReason -> ThreadStatus
+ GHC.Conc.Sync: [ThreadDied] :: ThreadStatus
+ GHC.Conc.Sync: [ThreadFinished] :: ThreadStatus
+ GHC.Conc.Sync: [ThreadId] :: ThreadId# -> ThreadId
+ GHC.Conc.Sync: [ThreadRunning] :: ThreadStatus
+ GHC.Conc.Sync: disableAllocationLimit :: IO ()
+ GHC.Conc.Sync: enableAllocationLimit :: IO ()
+ GHC.Conc.Sync: getAllocationCounter :: IO Int64
+ GHC.Conc.Sync: instance Alternative STM
+ GHC.Conc.Sync: instance Applicative STM
+ GHC.Conc.Sync: setAllocationCounter :: Int64 -> IO ()
+ GHC.Event: data TimerManager
+ GHC.Exts: [C#] :: Char# -> Char
+ GHC.Exts: [D#] :: Double# -> Double
+ GHC.Exts: [Down] :: a -> Down a
+ GHC.Exts: [F#] :: Float# -> Float
+ GHC.Exts: [ForceSpecConstr] :: SpecConstrAnnotation
+ GHC.Exts: [FunPtr] :: Addr# -> FunPtr a
+ GHC.Exts: [I#] :: Int# -> Int
+ GHC.Exts: [NoSpecConstr] :: SpecConstrAnnotation
+ GHC.Exts: [Ptr] :: Addr# -> Ptr a
+ GHC.Exts: [W#] :: Word# -> Word
+ GHC.Exts: instance IsList Version
+ GHC.Fingerprint: [Fingerprint] :: {-# UNPACK #-} !Word64 -> {-# UNPACK #-} !Word64 -> Fingerprint
+ GHC.Fingerprint.Type: [Fingerprint] :: {-# UNPACK #-} !Word64 -> {-# UNPACK #-} !Word64 -> Fingerprint
+ GHC.Generics: [:*:] :: f p -> g p -> (:*:) f g p
+ GHC.Generics: [Arity] :: Int -> Arity
+ GHC.Generics: [Comp1] :: f (g p) -> (:.:) f g p
+ GHC.Generics: [Infix] :: Associativity -> Int -> Fixity
+ GHC.Generics: [K1] :: c -> K1 i c p
+ GHC.Generics: [L1] :: (f p) -> (:+:) f g p
+ GHC.Generics: [LeftAssociative] :: Associativity
+ GHC.Generics: [M1] :: f p -> M1 i c f p
+ GHC.Generics: [NoArity] :: Arity
+ GHC.Generics: [NotAssociative] :: Associativity
+ GHC.Generics: [Par1] :: p -> Par1 p
+ GHC.Generics: [Prefix] :: Fixity
+ GHC.Generics: [R1] :: (g p) -> (:+:) f g p
+ GHC.Generics: [Rec1] :: f p -> Rec1 f p
+ GHC.Generics: [RightAssociative] :: Associativity
+ GHC.Generics: [U1] :: U1 p
+ GHC.Generics: [unComp1] :: (:.:) f g p -> f (g p)
+ GHC.Generics: [unK1] :: K1 i c p -> c
+ GHC.Generics: [unM1] :: M1 i c f p -> f p
+ GHC.Generics: [unPar1] :: Par1 p -> p
+ GHC.Generics: [unRec1] :: Rec1 f p -> f p
+ GHC.IO.Buffer: [Buffer] :: !(RawBuffer e) -> BufferState -> !Int -> !Int -> !Int -> Buffer e
+ GHC.IO.Buffer: [ReadBuffer] :: BufferState
+ GHC.IO.Buffer: [WriteBuffer] :: BufferState
+ GHC.IO.Buffer: [bufL] :: Buffer e -> !Int
+ GHC.IO.Buffer: [bufR] :: Buffer e -> !Int
+ GHC.IO.Buffer: [bufRaw] :: Buffer e -> !(RawBuffer e)
+ GHC.IO.Buffer: [bufSize] :: Buffer e -> !Int
+ GHC.IO.Buffer: [bufState] :: Buffer e -> BufferState
+ GHC.IO.Device: [AbsoluteSeek] :: SeekMode
+ GHC.IO.Device: [Directory] :: IODeviceType
+ GHC.IO.Device: [RawDevice] :: IODeviceType
+ GHC.IO.Device: [RegularFile] :: IODeviceType
+ GHC.IO.Device: [RelativeSeek] :: SeekMode
+ GHC.IO.Device: [SeekFromEnd] :: SeekMode
+ GHC.IO.Device: [Stream] :: IODeviceType
+ GHC.IO.Encoding: [BufferCodec] :: CodeBuffer from to -> (Buffer from -> Buffer to -> IO (Buffer from, Buffer to)) -> IO () -> IO state -> (state -> IO ()) -> BufferCodec from to state
+ GHC.IO.Encoding: [InputUnderflow] :: CodingProgress
+ GHC.IO.Encoding: [InvalidSequence] :: CodingProgress
+ GHC.IO.Encoding: [OutputUnderflow] :: CodingProgress
+ GHC.IO.Encoding: [TextEncoding] :: String -> IO (TextDecoder dstate) -> IO (TextEncoder estate) -> TextEncoding
+ GHC.IO.Encoding: [close] :: BufferCodec from to state -> IO ()
+ GHC.IO.Encoding: [encode] :: BufferCodec from to state -> CodeBuffer from to
+ GHC.IO.Encoding: [getState] :: BufferCodec from to state -> IO state
+ GHC.IO.Encoding: [mkTextDecoder] :: TextEncoding -> IO (TextDecoder dstate)
+ GHC.IO.Encoding: [mkTextEncoder] :: TextEncoding -> IO (TextEncoder estate)
+ GHC.IO.Encoding: [recover] :: BufferCodec from to state -> Buffer from -> Buffer to -> IO (Buffer from, Buffer to)
+ GHC.IO.Encoding: [setState] :: BufferCodec from to state -> state -> IO ()
+ GHC.IO.Encoding: [textEncodingName] :: TextEncoding -> String
+ GHC.IO.Encoding.Failure: [ErrorOnCodingFailure] :: CodingFailureMode
+ GHC.IO.Encoding.Failure: [IgnoreCodingFailure] :: CodingFailureMode
+ GHC.IO.Encoding.Failure: [RoundtripFailure] :: CodingFailureMode
+ GHC.IO.Encoding.Failure: [TransliterateCodingFailure] :: CodingFailureMode
+ GHC.IO.Encoding.Types: [BufferCodec] :: CodeBuffer from to -> (Buffer from -> Buffer to -> IO (Buffer from, Buffer to)) -> IO () -> IO state -> (state -> IO ()) -> BufferCodec from to state
+ GHC.IO.Encoding.Types: [InputUnderflow] :: CodingProgress
+ GHC.IO.Encoding.Types: [InvalidSequence] :: CodingProgress
+ GHC.IO.Encoding.Types: [OutputUnderflow] :: CodingProgress
+ GHC.IO.Encoding.Types: [TextEncoding] :: String -> IO (TextDecoder dstate) -> IO (TextEncoder estate) -> TextEncoding
+ GHC.IO.Encoding.Types: [close] :: BufferCodec from to state -> IO ()
+ GHC.IO.Encoding.Types: [encode] :: BufferCodec from to state -> CodeBuffer from to
+ GHC.IO.Encoding.Types: [getState] :: BufferCodec from to state -> IO state
+ GHC.IO.Encoding.Types: [mkTextDecoder] :: TextEncoding -> IO (TextDecoder dstate)
+ GHC.IO.Encoding.Types: [mkTextEncoder] :: TextEncoding -> IO (TextEncoder estate)
+ GHC.IO.Encoding.Types: [recover] :: BufferCodec from to state -> Buffer from -> Buffer to -> IO (Buffer from, Buffer to)
+ GHC.IO.Encoding.Types: [setState] :: BufferCodec from to state -> state -> IO ()
+ GHC.IO.Encoding.Types: [textEncodingName] :: TextEncoding -> String
+ GHC.IO.Handle: [AbsoluteSeek] :: SeekMode
+ GHC.IO.Handle: [BlockBuffering] :: (Maybe Int) -> BufferMode
+ GHC.IO.Handle: [CRLF] :: Newline
+ GHC.IO.Handle: [HandlePosn] :: Handle -> HandlePosition -> HandlePosn
+ GHC.IO.Handle: [LF] :: Newline
+ GHC.IO.Handle: [LineBuffering] :: BufferMode
+ GHC.IO.Handle: [NewlineMode] :: Newline -> Newline -> NewlineMode
+ GHC.IO.Handle: [NoBuffering] :: BufferMode
+ GHC.IO.Handle: [RelativeSeek] :: SeekMode
+ GHC.IO.Handle: [SeekFromEnd] :: SeekMode
+ GHC.IO.Handle: [inputNL] :: NewlineMode -> Newline
+ GHC.IO.Handle: [outputNL] :: NewlineMode -> Newline
+ GHC.Natural: [NatJ#] :: {-# UNPACK #-} !BigNat -> Natural
+ GHC.Natural: [NatS#] :: GmpLimb# -> Natural
+ GHC.Natural: data Natural
+ GHC.Natural: instance Bits Natural
+ GHC.Natural: instance Data Natural
+ GHC.Natural: instance Enum Natural
+ GHC.Natural: instance Eq Natural
+ GHC.Natural: instance Integral Natural
+ GHC.Natural: instance Ix Natural
+ GHC.Natural: instance Num Natural
+ GHC.Natural: instance Ord Natural
+ GHC.Natural: instance Read Natural
+ GHC.Natural: instance Real Natural
+ GHC.Natural: instance Show Natural
+ GHC.Natural: isValidNatural :: Natural -> Bool
+ GHC.Natural: minusNaturalMaybe :: Natural -> Natural -> Maybe Natural
+ GHC.Natural: naturalToWordMaybe :: Natural -> Maybe Word
+ GHC.Natural: powModNatural :: Natural -> Natural -> Natural -> Natural
+ GHC.Natural: wordToNatural :: Word -> Natural
+ GHC.OldList: (!!) :: [a] -> Int -> a
+ GHC.OldList: (++) :: [a] -> [a] -> [a]
+ GHC.OldList: (\\) :: (Eq a) => [a] -> [a] -> [a]
+ GHC.OldList: all :: (a -> Bool) -> [a] -> Bool
+ GHC.OldList: and :: [Bool] -> Bool
+ GHC.OldList: any :: (a -> Bool) -> [a] -> Bool
+ GHC.OldList: break :: (a -> Bool) -> [a] -> ([a], [a])
+ GHC.OldList: concat :: [[a]] -> [a]
+ GHC.OldList: concatMap :: (a -> [b]) -> [a] -> [b]
+ GHC.OldList: cycle :: [a] -> [a]
+ GHC.OldList: delete :: (Eq a) => a -> [a] -> [a]
+ GHC.OldList: deleteBy :: (a -> a -> Bool) -> a -> [a] -> [a]
+ GHC.OldList: deleteFirstsBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]
+ GHC.OldList: drop :: Int -> [a] -> [a]
+ GHC.OldList: dropWhile :: (a -> Bool) -> [a] -> [a]
+ GHC.OldList: dropWhileEnd :: (a -> Bool) -> [a] -> [a]
+ GHC.OldList: elem :: (Eq a) => a -> [a] -> Bool
+ GHC.OldList: elemIndex :: Eq a => a -> [a] -> Maybe Int
+ GHC.OldList: elemIndices :: Eq a => a -> [a] -> [Int]
+ GHC.OldList: filter :: (a -> Bool) -> [a] -> [a]
+ GHC.OldList: find :: (a -> Bool) -> [a] -> Maybe a
+ GHC.OldList: findIndex :: (a -> Bool) -> [a] -> Maybe Int
+ GHC.OldList: findIndices :: (a -> Bool) -> [a] -> [Int]
+ GHC.OldList: foldl :: (b -> a -> b) -> b -> [a] -> b
+ GHC.OldList: foldl' :: (b -> a -> b) -> b -> [a] -> b
+ GHC.OldList: foldl1 :: (a -> a -> a) -> [a] -> a
+ GHC.OldList: foldl1' :: (a -> a -> a) -> [a] -> a
+ GHC.OldList: foldr :: (a -> b -> b) -> b -> [a] -> b
+ GHC.OldList: foldr1 :: (a -> a -> a) -> [a] -> a
+ GHC.OldList: genericDrop :: (Integral i) => i -> [a] -> [a]
+ GHC.OldList: genericIndex :: (Integral i) => [a] -> i -> a
+ GHC.OldList: genericLength :: (Num i) => [a] -> i
+ GHC.OldList: genericReplicate :: (Integral i) => i -> a -> [a]
+ GHC.OldList: genericSplitAt :: (Integral i) => i -> [a] -> ([a], [a])
+ GHC.OldList: genericTake :: (Integral i) => i -> [a] -> [a]
+ GHC.OldList: group :: Eq a => [a] -> [[a]]
+ GHC.OldList: groupBy :: (a -> a -> Bool) -> [a] -> [[a]]
+ GHC.OldList: head :: [a] -> a
+ GHC.OldList: init :: [a] -> [a]
+ GHC.OldList: inits :: [a] -> [[a]]
+ GHC.OldList: insert :: Ord a => a -> [a] -> [a]
+ GHC.OldList: insertBy :: (a -> a -> Ordering) -> a -> [a] -> [a]
+ GHC.OldList: intercalate :: [a] -> [[a]] -> [a]
+ GHC.OldList: intersect :: (Eq a) => [a] -> [a] -> [a]
+ GHC.OldList: intersectBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]
+ GHC.OldList: intersperse :: a -> [a] -> [a]
+ GHC.OldList: isInfixOf :: (Eq a) => [a] -> [a] -> Bool
+ GHC.OldList: isPrefixOf :: (Eq a) => [a] -> [a] -> Bool
+ GHC.OldList: isSuffixOf :: (Eq a) => [a] -> [a] -> Bool
+ GHC.OldList: iterate :: (a -> a) -> a -> [a]
+ GHC.OldList: last :: [a] -> a
+ GHC.OldList: length :: [a] -> Int
+ GHC.OldList: lines :: String -> [String]
+ GHC.OldList: lookup :: (Eq a) => a -> [(a, b)] -> Maybe b
+ GHC.OldList: map :: (a -> b) -> [a] -> [b]
+ GHC.OldList: mapAccumL :: (acc -> x -> (acc, y)) -> acc -> [x] -> (acc, [y])
+ GHC.OldList: mapAccumR :: (acc -> x -> (acc, y)) -> acc -> [x] -> (acc, [y])
+ GHC.OldList: maximum :: (Ord a) => [a] -> a
+ GHC.OldList: maximumBy :: (a -> a -> Ordering) -> [a] -> a
+ GHC.OldList: minimum :: (Ord a) => [a] -> a
+ GHC.OldList: minimumBy :: (a -> a -> Ordering) -> [a] -> a
+ GHC.OldList: notElem :: (Eq a) => a -> [a] -> Bool
+ GHC.OldList: nub :: (Eq a) => [a] -> [a]
+ GHC.OldList: nubBy :: (a -> a -> Bool) -> [a] -> [a]
+ GHC.OldList: null :: [a] -> Bool
+ GHC.OldList: or :: [Bool] -> Bool
+ GHC.OldList: partition :: (a -> Bool) -> [a] -> ([a], [a])
+ GHC.OldList: permutations :: [a] -> [[a]]
+ GHC.OldList: product :: (Num a) => [a] -> a
+ GHC.OldList: repeat :: a -> [a]
+ GHC.OldList: replicate :: Int -> a -> [a]
+ GHC.OldList: reverse :: [a] -> [a]
+ GHC.OldList: scanl :: (b -> a -> b) -> b -> [a] -> [b]
+ GHC.OldList: scanl' :: (b -> a -> b) -> b -> [a] -> [b]
+ GHC.OldList: scanl1 :: (a -> a -> a) -> [a] -> [a]
+ GHC.OldList: scanr :: (a -> b -> b) -> b -> [a] -> [b]
+ GHC.OldList: scanr1 :: (a -> a -> a) -> [a] -> [a]
+ GHC.OldList: sort :: (Ord a) => [a] -> [a]
+ GHC.OldList: sortBy :: (a -> a -> Ordering) -> [a] -> [a]
+ GHC.OldList: sortOn :: Ord b => (a -> b) -> [a] -> [a]
+ GHC.OldList: span :: (a -> Bool) -> [a] -> ([a], [a])
+ GHC.OldList: splitAt :: Int -> [a] -> ([a], [a])
+ GHC.OldList: stripPrefix :: Eq a => [a] -> [a] -> Maybe [a]
+ GHC.OldList: subsequences :: [a] -> [[a]]
+ GHC.OldList: sum :: (Num a) => [a] -> a
+ GHC.OldList: tail :: [a] -> [a]
+ GHC.OldList: tails :: [a] -> [[a]]
+ GHC.OldList: take :: Int -> [a] -> [a]
+ GHC.OldList: takeWhile :: (a -> Bool) -> [a] -> [a]
+ GHC.OldList: transpose :: [[a]] -> [[a]]
+ GHC.OldList: uncons :: [a] -> Maybe (a, [a])
+ GHC.OldList: unfoldr :: (b -> Maybe (a, b)) -> b -> [a]
+ GHC.OldList: union :: (Eq a) => [a] -> [a] -> [a]
+ GHC.OldList: unionBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]
+ GHC.OldList: unlines :: [String] -> String
+ GHC.OldList: unwords :: [String] -> String
+ GHC.OldList: unzip :: [(a, b)] -> ([a], [b])
+ GHC.OldList: unzip3 :: [(a, b, c)] -> ([a], [b], [c])
+ GHC.OldList: unzip4 :: [(a, b, c, d)] -> ([a], [b], [c], [d])
+ GHC.OldList: unzip5 :: [(a, b, c, d, e)] -> ([a], [b], [c], [d], [e])
+ GHC.OldList: unzip6 :: [(a, b, c, d, e, f)] -> ([a], [b], [c], [d], [e], [f])
+ GHC.OldList: unzip7 :: [(a, b, c, d, e, f, g)] -> ([a], [b], [c], [d], [e], [f], [g])
+ GHC.OldList: words :: String -> [String]
+ GHC.OldList: zip :: [a] -> [b] -> [(a, b)]
+ GHC.OldList: zip3 :: [a] -> [b] -> [c] -> [(a, b, c)]
+ GHC.OldList: zip4 :: [a] -> [b] -> [c] -> [d] -> [(a, b, c, d)]
+ GHC.OldList: zip5 :: [a] -> [b] -> [c] -> [d] -> [e] -> [(a, b, c, d, e)]
+ GHC.OldList: zip6 :: [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [(a, b, c, d, e, f)]
+ GHC.OldList: zip7 :: [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g] -> [(a, b, c, d, e, f, g)]
+ GHC.OldList: zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
+ GHC.OldList: zipWith3 :: (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]
+ GHC.OldList: zipWith4 :: (a -> b -> c -> d -> e) -> [a] -> [b] -> [c] -> [d] -> [e]
+ GHC.OldList: zipWith5 :: (a -> b -> c -> d -> e -> f) -> [a] -> [b] -> [c] -> [d] -> [e] -> [f]
+ GHC.OldList: zipWith6 :: (a -> b -> c -> d -> e -> f -> g) -> [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g]
+ GHC.OldList: zipWith7 :: (a -> b -> c -> d -> e -> f -> g -> h) -> [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g] -> [h]
+ GHC.RTS.Flags: [CCFlags] :: DoCostCentres -> Int -> Int -> CCFlags
+ GHC.RTS.Flags: [ConcFlags] :: Time -> Int -> ConcFlags
+ GHC.RTS.Flags: [DebugFlags] :: Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> DebugFlags
+ GHC.RTS.Flags: [GCFlags] :: Maybe FilePath -> GiveGCStats -> Nat -> Nat -> Nat -> Nat -> Nat -> Nat -> Nat -> Nat -> Bool -> Double -> Double -> Nat -> Nat -> Bool -> Bool -> Double -> Bool -> Bool -> Bool -> Time -> Bool -> Word -> Word -> GCFlags
+ GHC.RTS.Flags: [MiscFlags] :: Time -> Bool -> Bool -> Word -> MiscFlags
+ GHC.RTS.Flags: [ProfFlags] :: DoHeapProfile -> Time -> Word -> Bool -> Bool -> Word -> Word -> Maybe String -> Maybe String -> Maybe String -> Maybe String -> Maybe String -> Maybe String -> Maybe String -> ProfFlags
+ GHC.RTS.Flags: [RTSFlags] :: GCFlags -> ConcFlags -> MiscFlags -> DebugFlags -> CCFlags -> ProfFlags -> TraceFlags -> TickyFlags -> RTSFlags
+ GHC.RTS.Flags: [TickyFlags] :: Bool -> Maybe FilePath -> TickyFlags
+ GHC.RTS.Flags: [TraceFlags] :: DoTrace -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> TraceFlags
+ GHC.RTS.Flags: [allocLimitGrace] :: GCFlags -> Word
+ GHC.RTS.Flags: [apply] :: DebugFlags -> Bool
+ GHC.RTS.Flags: [bioSelector] :: ProfFlags -> Maybe String
+ GHC.RTS.Flags: [block_alloc] :: DebugFlags -> Bool
+ GHC.RTS.Flags: [ccSelector] :: ProfFlags -> Maybe String
+ GHC.RTS.Flags: [ccsLength] :: ProfFlags -> Word
+ GHC.RTS.Flags: [ccsSelector] :: ProfFlags -> Maybe String
+ GHC.RTS.Flags: [compactThreshold] :: GCFlags -> Double
+ GHC.RTS.Flags: [compact] :: GCFlags -> Bool
+ GHC.RTS.Flags: [concurrentFlags] :: RTSFlags -> ConcFlags
+ GHC.RTS.Flags: [costCentreFlags] :: RTSFlags -> CCFlags
+ GHC.RTS.Flags: [ctxtSwitchTicks] :: ConcFlags -> Int
+ GHC.RTS.Flags: [ctxtSwitchTime] :: ConcFlags -> Time
+ GHC.RTS.Flags: [debugFlags] :: RTSFlags -> DebugFlags
+ GHC.RTS.Flags: [descrSelector] :: ProfFlags -> Maybe String
+ GHC.RTS.Flags: [doCostCentres] :: CCFlags -> DoCostCentres
+ GHC.RTS.Flags: [doHeapProfile] :: ProfFlags -> DoHeapProfile
+ GHC.RTS.Flags: [doIdleGC] :: GCFlags -> Bool
+ GHC.RTS.Flags: [frontpanel] :: GCFlags -> Bool
+ GHC.RTS.Flags: [gcFlags] :: RTSFlags -> GCFlags
+ GHC.RTS.Flags: [gc] :: DebugFlags -> Bool
+ GHC.RTS.Flags: [gccafs] :: DebugFlags -> Bool
+ GHC.RTS.Flags: [generations] :: GCFlags -> Nat
+ GHC.RTS.Flags: [giveStats] :: GCFlags -> GiveGCStats
+ GHC.RTS.Flags: [heapBase] :: GCFlags -> Word
+ GHC.RTS.Flags: [heapProfileIntervalTicks] :: ProfFlags -> Word
+ GHC.RTS.Flags: [heapProfileInterval] :: ProfFlags -> Time
+ GHC.RTS.Flags: [heapSizeSuggestionAuto] :: GCFlags -> Bool
+ GHC.RTS.Flags: [heapSizeSuggestion] :: GCFlags -> Nat
+ GHC.RTS.Flags: [hpc] :: DebugFlags -> Bool
+ GHC.RTS.Flags: [idleGCDelayTime] :: GCFlags -> Time
+ GHC.RTS.Flags: [includeTSOs] :: ProfFlags -> Bool
+ GHC.RTS.Flags: [initialStkSize] :: GCFlags -> Nat
+ GHC.RTS.Flags: [installSignalHandlers] :: MiscFlags -> Bool
+ GHC.RTS.Flags: [interpreter] :: DebugFlags -> Bool
+ GHC.RTS.Flags: [linkerMemBase] :: MiscFlags -> Word
+ GHC.RTS.Flags: [linker] :: DebugFlags -> Bool
+ GHC.RTS.Flags: [machineReadable] :: MiscFlags -> Bool
+ GHC.RTS.Flags: [maxHeapSize] :: GCFlags -> Nat
+ GHC.RTS.Flags: [maxRetainerSetSize] :: ProfFlags -> Word
+ GHC.RTS.Flags: [maxStkSize] :: GCFlags -> Nat
+ GHC.RTS.Flags: [minAllocAreaSize] :: GCFlags -> Nat
+ GHC.RTS.Flags: [minOldGenSize] :: GCFlags -> Nat
+ GHC.RTS.Flags: [miscFlags] :: RTSFlags -> MiscFlags
+ GHC.RTS.Flags: [modSelector] :: ProfFlags -> Maybe String
+ GHC.RTS.Flags: [msecsPerTick] :: CCFlags -> Int
+ GHC.RTS.Flags: [oldGenFactor] :: GCFlags -> Double
+ GHC.RTS.Flags: [pcFreeHeap] :: GCFlags -> Double
+ GHC.RTS.Flags: [prof] :: DebugFlags -> Bool
+ GHC.RTS.Flags: [profilerTicks] :: CCFlags -> Int
+ GHC.RTS.Flags: [profilingFlags] :: RTSFlags -> ProfFlags
+ GHC.RTS.Flags: [retainerSelector] :: ProfFlags -> Maybe String
+ GHC.RTS.Flags: [ringBell] :: GCFlags -> Bool
+ GHC.RTS.Flags: [sanity] :: DebugFlags -> Bool
+ GHC.RTS.Flags: [scheduler] :: DebugFlags -> Bool
+ GHC.RTS.Flags: [showCCSOnException] :: ProfFlags -> Bool
+ GHC.RTS.Flags: [showTickyStats] :: TickyFlags -> Bool
+ GHC.RTS.Flags: [sparksFull] :: TraceFlags -> Bool
+ GHC.RTS.Flags: [sparksSampled] :: TraceFlags -> Bool
+ GHC.RTS.Flags: [sparks] :: DebugFlags -> Bool
+ GHC.RTS.Flags: [squeezeUpdFrames] :: GCFlags -> Bool
+ GHC.RTS.Flags: [squeeze] :: DebugFlags -> Bool
+ GHC.RTS.Flags: [stable] :: DebugFlags -> Bool
+ GHC.RTS.Flags: [statsFile] :: GCFlags -> Maybe FilePath
+ GHC.RTS.Flags: [steps] :: GCFlags -> Nat
+ GHC.RTS.Flags: [stkChunkBufferSize] :: GCFlags -> Nat
+ GHC.RTS.Flags: [stkChunkSize] :: GCFlags -> Nat
+ GHC.RTS.Flags: [stm] :: DebugFlags -> Bool
+ GHC.RTS.Flags: [sweep] :: GCFlags -> Bool
+ GHC.RTS.Flags: [tickInterval] :: MiscFlags -> Time
+ GHC.RTS.Flags: [tickyFile] :: TickyFlags -> Maybe FilePath
+ GHC.RTS.Flags: [tickyFlags] :: RTSFlags -> TickyFlags
+ GHC.RTS.Flags: [timestamp] :: TraceFlags -> Bool
+ GHC.RTS.Flags: [traceFlags] :: RTSFlags -> TraceFlags
+ GHC.RTS.Flags: [traceGc] :: TraceFlags -> Bool
+ GHC.RTS.Flags: [traceScheduler] :: TraceFlags -> Bool
+ GHC.RTS.Flags: [tracing] :: TraceFlags -> DoTrace
+ GHC.RTS.Flags: [typeSelector] :: ProfFlags -> Maybe String
+ GHC.RTS.Flags: [user] :: TraceFlags -> Bool
+ GHC.RTS.Flags: [weak] :: DebugFlags -> Bool
+ GHC.RTS.Flags: data CCFlags
+ GHC.RTS.Flags: data ConcFlags
+ GHC.RTS.Flags: data DebugFlags
+ GHC.RTS.Flags: data GCFlags
+ GHC.RTS.Flags: data MiscFlags
+ GHC.RTS.Flags: data ProfFlags
+ GHC.RTS.Flags: data RTSFlags
+ GHC.RTS.Flags: data TickyFlags
+ GHC.RTS.Flags: data TraceFlags
+ GHC.RTS.Flags: getCCFlags :: IO CCFlags
+ GHC.RTS.Flags: getConcFlags :: IO ConcFlags
+ GHC.RTS.Flags: getDebugFlags :: IO DebugFlags
+ GHC.RTS.Flags: getGCFlags :: IO GCFlags
+ GHC.RTS.Flags: getMiscFlags :: IO MiscFlags
+ GHC.RTS.Flags: getProfFlags :: IO ProfFlags
+ GHC.RTS.Flags: getRTSFlags :: IO RTSFlags
+ GHC.RTS.Flags: getTickyFlags :: IO TickyFlags
+ GHC.RTS.Flags: getTraceFlags :: IO TraceFlags
+ GHC.RTS.Flags: instance Enum DoCostCentres
+ GHC.RTS.Flags: instance Enum DoHeapProfile
+ GHC.RTS.Flags: instance Enum DoTrace
+ GHC.RTS.Flags: instance Enum GiveGCStats
+ GHC.RTS.Flags: instance Show CCFlags
+ GHC.RTS.Flags: instance Show ConcFlags
+ GHC.RTS.Flags: instance Show DebugFlags
+ GHC.RTS.Flags: instance Show DoCostCentres
+ GHC.RTS.Flags: instance Show DoHeapProfile
+ GHC.RTS.Flags: instance Show DoTrace
+ GHC.RTS.Flags: instance Show GCFlags
+ GHC.RTS.Flags: instance Show GiveGCStats
+ GHC.RTS.Flags: instance Show MiscFlags
+ GHC.RTS.Flags: instance Show ProfFlags
+ GHC.RTS.Flags: instance Show RTSFlags
+ GHC.RTS.Flags: instance Show TickyFlags
+ GHC.RTS.Flags: instance Show TraceFlags
+ GHC.StaticPtr: [StaticPtrInfo] :: String -> String -> String -> (Int, Int) -> StaticPtrInfo
+ GHC.StaticPtr: [spInfoModuleName] :: StaticPtrInfo -> String
+ GHC.StaticPtr: [spInfoName] :: StaticPtrInfo -> String
+ GHC.StaticPtr: [spInfoPackageKey] :: StaticPtrInfo -> String
+ GHC.StaticPtr: [spInfoSrcLoc] :: StaticPtrInfo -> (Int, Int)
+ GHC.StaticPtr: data StaticPtr a
+ GHC.StaticPtr: data StaticPtrInfo
+ GHC.StaticPtr: deRefStaticPtr :: StaticPtr a -> a
+ GHC.StaticPtr: instance Show StaticPtrInfo
+ GHC.StaticPtr: staticKey :: StaticPtr a -> StaticKey
+ GHC.StaticPtr: staticPtrInfo :: StaticPtr a -> StaticPtrInfo
+ GHC.StaticPtr: staticPtrKeys :: IO [StaticKey]
+ GHC.StaticPtr: type StaticKey = Fingerprint
+ GHC.StaticPtr: unsafeLookupStaticPtr :: StaticKey -> IO (Maybe (StaticPtr a))
+ GHC.Stats: [GCStats] :: !Int64 -> !Int64 -> !Int64 -> !Int64 -> !Int64 -> !Int64 -> !Int64 -> !Int64 -> !Int64 -> !Int64 -> !Double -> !Double -> !Double -> !Double -> !Double -> !Double -> !Int64 -> !Int64 -> GCStats
+ GHC.Stats: [bytesAllocated] :: GCStats -> !Int64
+ GHC.Stats: [bytesCopied] :: GCStats -> !Int64
+ GHC.Stats: [cpuSeconds] :: GCStats -> !Double
+ GHC.Stats: [cumulativeBytesUsed] :: GCStats -> !Int64
+ GHC.Stats: [currentBytesSlop] :: GCStats -> !Int64
+ GHC.Stats: [currentBytesUsed] :: GCStats -> !Int64
+ GHC.Stats: [gcCpuSeconds] :: GCStats -> !Double
+ GHC.Stats: [gcWallSeconds] :: GCStats -> !Double
+ GHC.Stats: [maxBytesSlop] :: GCStats -> !Int64
+ GHC.Stats: [maxBytesUsed] :: GCStats -> !Int64
+ GHC.Stats: [mutatorCpuSeconds] :: GCStats -> !Double
+ GHC.Stats: [mutatorWallSeconds] :: GCStats -> !Double
+ GHC.Stats: [numByteUsageSamples] :: GCStats -> !Int64
+ GHC.Stats: [numGcs] :: GCStats -> !Int64
+ GHC.Stats: [parMaxBytesCopied] :: GCStats -> !Int64
+ GHC.Stats: [parTotBytesCopied] :: GCStats -> !Int64
+ GHC.Stats: [peakMegabytesAllocated] :: GCStats -> !Int64
+ GHC.Stats: [wallSeconds] :: GCStats -> !Double
+ GHC.Stats: instance Read GCStats
+ GHC.Stats: instance Show GCStats
+ GHC.TypeLits: [SomeNat] :: (Proxy n) -> SomeNat
+ GHC.TypeLits: [SomeSymbol] :: (Proxy n) -> SomeSymbol
+ GHC.TypeLits: natVal' :: KnownNat n => Proxy# n -> Integer
+ GHC.TypeLits: symbolVal' :: KnownSymbol n => Proxy# n -> String
+ Numeric.Natural: data Natural
+ Prelude: (*>) :: Applicative f => f a -> f b -> f b
+ Prelude: (+, -, *) :: Num a => a -> a -> a
+ Prelude: (<$) :: Functor f => a -> f b -> f a
+ Prelude: (<$>) :: Functor f => (a -> b) -> f a -> f b
+ Prelude: (<*) :: Applicative f => f a -> f b -> f a
+ Prelude: (<*>) :: Applicative f => f (a -> b) -> f a -> f b
+ Prelude: [EQ] :: Ordering
+ Prelude: [False] :: Bool
+ Prelude: [GT] :: Ordering
+ Prelude: [Just] :: a -> Maybe a
+ Prelude: [LT] :: Ordering
+ Prelude: [Left] :: a -> Either a b
+ Prelude: [Nothing] :: Maybe a
+ Prelude: [Right] :: b -> Either a b
+ Prelude: [True] :: Bool
+ Prelude: asin, acos, atan :: Floating a => a -> a
+ Prelude: asinh, acosh, atanh :: Floating a => a -> a
+ Prelude: class Functor f => Applicative f where a1 *> a2 = (id <$ a1) <*> a2 (<*) = liftA2 const
+ Prelude: class Foldable t where fold = foldMap id foldMap f = foldr (mappend . f) mempty foldr f z t = appEndo (foldMap (Endo #. f) t) z foldr' f z0 xs = foldl f' id xs z0 where f' k x z = k $! f x z foldl f z t = appEndo (getDual (foldMap (Dual . Endo . flip f) t)) z foldl' f z0 xs = foldr f' id xs z0 where f' x k z = k $! f z x foldr1 f xs = fromMaybe (error "foldr1: empty structure") (foldr mf Nothing xs) where mf x m = Just (case m of { Nothing -> x Just y -> f x y }) foldl1 f xs = fromMaybe (error "foldl1: empty structure") (foldl mf Nothing xs) where mf m y = Just (case m of { Nothing -> y Just x -> f x y }) toList t = build (\ c n -> foldr c n t) null = foldr (\ _ _ -> False) True length = foldl' (\ c _ -> c + 1) 0 elem = any . (==) maximum = fromMaybe (error "maximum: empty structure") . getMax . foldMap (Max #. (Just :: a -> Maybe a)) minimum = fromMaybe (error "minimum: empty structure") . getMin . foldMap (Min #. (Just :: a -> Maybe a)) sum = getSum #. foldMap Sum product = getProduct #. foldMap Product
+ Prelude: class Monoid a where mconcat = foldr mappend mempty
+ Prelude: class (Functor t, Foldable t) => Traversable t where traverse f = sequenceA . fmap f sequenceA = traverse id mapM = traverse sequence = sequenceA
+ Prelude: data Word :: *
+ Prelude: exp, log, sqrt :: Floating a => a -> a
+ Prelude: foldMap :: (Foldable t, Monoid m) => (a -> m) -> t a -> m
+ Prelude: mappend :: Monoid a => a -> a -> a
+ Prelude: mconcat :: Monoid a => [a] -> a
+ Prelude: mempty :: Monoid a => a
+ Prelude: pure :: Applicative f => a -> f a
+ Prelude: sequenceA :: (Traversable t, Applicative f) => t (f a) -> f (t a)
+ Prelude: sin, cos, tan :: Floating a => a -> a
+ Prelude: sinh, cosh, tanh :: Floating a => a -> a
+ Prelude: traverse :: (Traversable t, Applicative f) => (a -> f b) -> t a -> f (t b)
+ System.Console.GetOpt: [NoArg] :: a -> ArgDescr a
+ System.Console.GetOpt: [OptArg] :: (Maybe String -> a) -> String -> ArgDescr a
+ System.Console.GetOpt: [Option] :: [Char] -> [String] -> (ArgDescr a) -> String -> OptDescr a
+ System.Console.GetOpt: [Permute] :: ArgOrder a
+ System.Console.GetOpt: [ReqArg] :: (String -> a) -> String -> ArgDescr a
+ System.Console.GetOpt: [RequireOrder] :: ArgOrder a
+ System.Console.GetOpt: [ReturnInOrder] :: (String -> a) -> ArgOrder a
+ System.Exit: [ExitFailure] :: Int -> ExitCode
+ System.Exit: [ExitSuccess] :: ExitCode
+ System.Exit: die :: String -> IO a
+ System.IO: [AbsoluteSeek] :: SeekMode
+ System.IO: [AppendMode] :: IOMode
+ System.IO: [BlockBuffering] :: (Maybe Int) -> BufferMode
+ System.IO: [CRLF] :: Newline
+ System.IO: [LF] :: Newline
+ System.IO: [LineBuffering] :: BufferMode
+ System.IO: [NewlineMode] :: Newline -> Newline -> NewlineMode
+ System.IO: [NoBuffering] :: BufferMode
+ System.IO: [ReadMode] :: IOMode
+ System.IO: [ReadWriteMode] :: IOMode
+ System.IO: [RelativeSeek] :: SeekMode
+ System.IO: [SeekFromEnd] :: SeekMode
+ System.IO: [WriteMode] :: IOMode
+ System.IO: [inputNL] :: NewlineMode -> Newline
+ System.IO: [outputNL] :: NewlineMode -> Newline
+ System.Posix.Types: [CCc] :: Word8 -> CCc
+ System.Posix.Types: [CDev] :: Word64 -> CDev
+ System.Posix.Types: [CGid] :: Word32 -> CGid
+ System.Posix.Types: [CIno] :: Word64 -> CIno
+ System.Posix.Types: [CMode] :: Word32 -> CMode
+ System.Posix.Types: [CNlink] :: Word64 -> CNlink
+ System.Posix.Types: [COff] :: Int64 -> COff
+ System.Posix.Types: [CPid] :: Int32 -> CPid
+ System.Posix.Types: [CRLim] :: Word64 -> CRLim
+ System.Posix.Types: [CSpeed] :: Word32 -> CSpeed
+ System.Posix.Types: [CSsize] :: Int64 -> CSsize
+ System.Posix.Types: [CTcflag] :: Word32 -> CTcflag
+ System.Posix.Types: [CUid] :: Word32 -> CUid
+ System.Posix.Types: [Fd] :: CInt -> Fd
+ System.Timeout: instance [safe] Eq Timeout
+ System.Timeout: instance [safe] Exception Timeout
+ System.Timeout: instance [safe] Show Timeout
+ Text.ParserCombinators.ReadP: instance Alternative P
+ Text.ParserCombinators.ReadP: instance Alternative ReadP
+ Text.ParserCombinators.ReadP: instance Applicative P
+ Text.ParserCombinators.ReadP: instance Applicative ReadP
+ Text.ParserCombinators.ReadP: instance Functor P
+ Text.ParserCombinators.ReadPrec: instance Alternative ReadPrec
+ Text.ParserCombinators.ReadPrec: instance Applicative ReadPrec
+ Text.Printf: [FieldFormat] :: Maybe Int -> Maybe Int -> Maybe FormatAdjustment -> Maybe FormatSign -> Bool -> String -> Char -> FieldFormat
+ Text.Printf: [FormatParse] :: String -> Char -> String -> FormatParse
+ Text.Printf: [LeftAdjust] :: FormatAdjustment
+ Text.Printf: [SignPlus] :: FormatSign
+ Text.Printf: [SignSpace] :: FormatSign
+ Text.Printf: [ZeroPad] :: FormatAdjustment
+ Text.Printf: [fmtAdjust] :: FieldFormat -> Maybe FormatAdjustment
+ Text.Printf: [fmtAlternate] :: FieldFormat -> Bool
+ Text.Printf: [fmtChar] :: FieldFormat -> Char
+ Text.Printf: [fmtModifiers] :: FieldFormat -> String
+ Text.Printf: [fmtPrecision] :: FieldFormat -> Maybe Int
+ Text.Printf: [fmtSign] :: FieldFormat -> Maybe FormatSign
+ Text.Printf: [fmtWidth] :: FieldFormat -> Maybe Int
+ Text.Printf: [fpChar] :: FormatParse -> Char
+ Text.Printf: [fpModifiers] :: FormatParse -> String
+ Text.Printf: [fpRest] :: FormatParse -> String
+ Text.Printf: instance [safe] (a ~ ()) => HPrintfType (IO a)
+ Text.Printf: instance [safe] (a ~ ()) => PrintfType (IO a)
+ Text.Printf: instance [safe] PrintfArg Natural
+ Text.Read: [Char] :: Char -> Lexeme
+ Text.Read: [EOF] :: Lexeme
+ Text.Read: [Ident] :: String -> Lexeme
+ Text.Read: [Number] :: Number -> Lexeme
+ Text.Read: [Punc] :: String -> Lexeme
+ Text.Read: [String] :: String -> Lexeme
+ Text.Read: [Symbol] :: String -> Lexeme
+ Text.Read.Lex: [Char] :: Char -> Lexeme
+ Text.Read.Lex: [EOF] :: Lexeme
+ Text.Read.Lex: [Ident] :: String -> Lexeme
+ Text.Read.Lex: [Number] :: Number -> Lexeme
+ Text.Read.Lex: [Punc] :: String -> Lexeme
+ Text.Read.Lex: [String] :: String -> Lexeme
+ Text.Read.Lex: [Symbol] :: String -> Lexeme
- Control.Applicative: class Applicative f => Alternative f where some v = some_v where many_v = some_v <|> pure [] some_v = (:) <$> v <*> many_v many v = many_v where many_v = some_v <|> pure [] some_v = (:) <$> v <*> many_v
+ Control.Applicative: class Applicative f => Alternative f where some v = some_v where many_v = some_v <|> pure [] some_v = (fmap (:) v) <*> many_v many v = many_v where many_v = some_v <|> pure [] some_v = (fmap (:) v) <*> many_v
- Control.Applicative: class Functor f => Applicative f where (*>) = liftA2 (const id) (<*) = liftA2 const
+ Control.Applicative: class Functor f => Applicative f where a1 *> a2 = (id <$ a1) <*> a2 (<*) = liftA2 const
- Control.Exception: class (Typeable e, Show e) => Exception e where toException = SomeException fromException (SomeException e) = cast e
+ Control.Exception: class (Typeable e, Show e) => Exception e where toException = SomeException fromException (SomeException e) = cast e displayException = show
- Control.Exception.Base: class (Typeable e, Show e) => Exception e where toException = SomeException fromException (SomeException e) = cast e
+ Control.Exception.Base: class (Typeable e, Show e) => Exception e where toException = SomeException fromException (SomeException e) = cast e displayException = show
- Control.Monad: ap :: Monad m => m (a -> b) -> m a -> m b
+ Control.Monad: ap :: (Monad m) => m (a -> b) -> m a -> m b
- Control.Monad: class Monad m where m >> k = m >>= \ _ -> k fail s = error s
+ Control.Monad: class Applicative m => Monad m where m >> k = m >>= \ _ -> k return = pure fail s = error s
- Control.Monad: class Monad m => MonadPlus m
+ Control.Monad: class (Alternative m, Monad m) => MonadPlus m where mzero = empty mplus = (<|>)
- Control.Monad: filterM :: Monad m => (a -> m Bool) -> [a] -> m [a]
+ Control.Monad: filterM :: (Monad m) => (a -> m Bool) -> [a] -> m [a]
- Control.Monad: foldM :: Monad m => (a -> b -> m a) -> a -> [b] -> m a
+ Control.Monad: foldM :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m b
- Control.Monad: foldM_ :: Monad m => (a -> b -> m a) -> a -> [b] -> m ()
+ Control.Monad: foldM_ :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m ()
- Control.Monad: forM :: Monad m => [a] -> (a -> m b) -> m [b]
+ Control.Monad: forM :: (Traversable t, Monad m) => t a -> (a -> m b) -> m (t b)
- Control.Monad: forM_ :: Monad m => [a] -> (a -> m b) -> m ()
+ Control.Monad: forM_ :: (Foldable t, Monad m) => t a -> (a -> m b) -> m ()
- Control.Monad: forever :: Monad m => m a -> m b
+ Control.Monad: forever :: (Monad m) => m a -> m b
- Control.Monad: guard :: MonadPlus m => Bool -> m ()
+ Control.Monad: guard :: (Alternative f) => Bool -> f ()
- Control.Monad: join :: Monad m => m (m a) -> m a
+ Control.Monad: join :: (Monad m) => m (m a) -> m a
- Control.Monad: liftM :: Monad m => (a1 -> r) -> m a1 -> m r
+ Control.Monad: liftM :: (Monad m) => (a1 -> r) -> m a1 -> m r
- Control.Monad: liftM2 :: Monad m => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r
+ Control.Monad: liftM2 :: (Monad m) => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r
- Control.Monad: liftM3 :: Monad m => (a1 -> a2 -> a3 -> r) -> m a1 -> m a2 -> m a3 -> m r
+ Control.Monad: liftM3 :: (Monad m) => (a1 -> a2 -> a3 -> r) -> m a1 -> m a2 -> m a3 -> m r
- Control.Monad: liftM4 :: Monad m => (a1 -> a2 -> a3 -> a4 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m r
+ Control.Monad: liftM4 :: (Monad m) => (a1 -> a2 -> a3 -> a4 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m r
- Control.Monad: liftM5 :: Monad m => (a1 -> a2 -> a3 -> a4 -> a5 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m a5 -> m r
+ Control.Monad: liftM5 :: (Monad m) => (a1 -> a2 -> a3 -> a4 -> a5 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m a5 -> m r
- Control.Monad: mapAndUnzipM :: Monad m => (a -> m (b, c)) -> [a] -> m ([b], [c])
+ Control.Monad: mapAndUnzipM :: (Monad m) => (a -> m (b, c)) -> [a] -> m ([b], [c])
- Control.Monad: mapM :: Monad m => (a -> m b) -> [a] -> m [b]
+ Control.Monad: mapM :: (Traversable t, Monad m) => (a -> m b) -> t a -> m (t b)
- Control.Monad: mapM_ :: Monad m => (a -> m b) -> [a] -> m ()
+ Control.Monad: mapM_ :: (Foldable t, Monad m) => (a -> m b) -> t a -> m ()
- Control.Monad: mfilter :: MonadPlus m => (a -> Bool) -> m a -> m a
+ Control.Monad: mfilter :: (MonadPlus m) => (a -> Bool) -> m a -> m a
- Control.Monad: msum :: MonadPlus m => [m a] -> m a
+ Control.Monad: msum :: (Foldable t, MonadPlus m) => t (m a) -> m a
- Control.Monad: replicateM :: Monad m => Int -> m a -> m [a]
+ Control.Monad: replicateM :: (Monad m) => Int -> m a -> m [a]
- Control.Monad: replicateM_ :: Monad m => Int -> m a -> m ()
+ Control.Monad: replicateM_ :: (Monad m) => Int -> m a -> m ()
- Control.Monad: sequence :: Monad m => [m a] -> m [a]
+ Control.Monad: sequence :: (Traversable t, Monad m) => t (m a) -> m (t a)
- Control.Monad: sequence_ :: Monad m => [m a] -> m ()
+ Control.Monad: sequence_ :: (Foldable t, Monad m) => t (m a) -> m ()
- Control.Monad: unless :: Monad m => Bool -> m () -> m ()
+ Control.Monad: unless :: (Applicative f) => Bool -> f () -> f ()
- Control.Monad: when :: Monad m => Bool -> m () -> m ()
+ Control.Monad: when :: (Applicative f) => Bool -> f () -> f ()
- Control.Monad: zipWithM :: Monad m => (a -> b -> m c) -> [a] -> [b] -> m [c]
+ Control.Monad: zipWithM :: (Monad m) => (a -> b -> m c) -> [a] -> [b] -> m [c]
- Control.Monad: zipWithM_ :: Monad m => (a -> b -> m c) -> [a] -> [b] -> m ()
+ Control.Monad: zipWithM_ :: (Monad m) => (a -> b -> m c) -> [a] -> [b] -> m ()
- Control.Monad.Fix: class Monad m => MonadFix m
+ Control.Monad.Fix: class (Monad m) => MonadFix m
- Control.Monad.Instances: class Monad m where m >> k = m >>= \ _ -> k fail s = error s
+ Control.Monad.Instances: class Applicative m => Monad m where m >> k = m >>= \ _ -> k return = pure fail s = error s
- Data.Bits: class Bits b => FiniteBits b
+ Data.Bits: class Bits b => FiniteBits b where countLeadingZeros x = (w - 1) - go (w - 1) where go i | i < 0 = i | testBit x i = i | otherwise = go (i - 1) w = finiteBitSize x countTrailingZeros x = go 0 where go i | i >= w = i | testBit x i = i | otherwise = go (i + 1) w = finiteBitSize x
- Data.Coerce: coerce :: Coercible k a b => a -> b
+ Data.Coerce: coerce :: Coercible * a b => a -> b
- Data.Complex: cis :: RealFloat a => a -> Complex a
+ Data.Complex: cis :: Floating a => a -> Complex a
- Data.Complex: conjugate :: RealFloat a => Complex a -> Complex a
+ Data.Complex: conjugate :: Num a => Complex a -> Complex a
- Data.Complex: imagPart :: RealFloat a => Complex a -> a
+ Data.Complex: imagPart :: Complex a -> a
- Data.Complex: magnitude :: RealFloat a => Complex a -> a
+ Data.Complex: magnitude :: (RealFloat a) => Complex a -> a
- Data.Complex: mkPolar :: RealFloat a => a -> a -> Complex a
+ Data.Complex: mkPolar :: Floating a => a -> a -> Complex a
- Data.Complex: phase :: RealFloat a => Complex a -> a
+ Data.Complex: phase :: (RealFloat a) => Complex a -> a
- Data.Complex: polar :: RealFloat a => Complex a -> (a, a)
+ Data.Complex: polar :: (RealFloat a) => Complex a -> (a, a)
- Data.Complex: realPart :: RealFloat a => Complex a -> a
+ Data.Complex: realPart :: Complex a -> a
- Data.Fixed: mod' :: Real a => a -> a -> a
+ Data.Fixed: mod' :: (Real a) => a -> a -> a
- Data.Fixed: showFixed :: HasResolution a => Bool -> Fixed a -> String
+ Data.Fixed: showFixed :: (HasResolution a) => Bool -> Fixed a -> String
- Data.Foldable: class Foldable t where fold = foldMap id foldMap f = foldr (mappend . f) mempty foldr f z t = appEndo (foldMap (Endo . f) t) z foldr' f z0 xs = foldl f' id xs z0 where f' k x z = k $! f x z foldl f z t = appEndo (getDual (foldMap (Dual . Endo . flip f) t)) z foldl' f z0 xs = foldr f' id xs z0 where f' x k z = k $! f z x foldr1 f xs = fromMaybe (error "foldr1: empty structure") (foldr mf Nothing xs) where mf x Nothing = Just x mf x (Just y) = Just (f x y) foldl1 f xs = fromMaybe (error "foldl1: empty structure") (foldl mf Nothing xs) where mf Nothing y = Just y mf (Just x) y = Just (f x y)
+ Data.Foldable: class Foldable t where fold = foldMap id foldMap f = foldr (mappend . f) mempty foldr f z t = appEndo (foldMap (Endo #. f) t) z foldr' f z0 xs = foldl f' id xs z0 where f' k x z = k $! f x z foldl f z t = appEndo (getDual (foldMap (Dual . Endo . flip f) t)) z foldl' f z0 xs = foldr f' id xs z0 where f' x k z = k $! f z x foldr1 f xs = fromMaybe (error "foldr1: empty structure") (foldr mf Nothing xs) where mf x m = Just (case m of { Nothing -> x Just y -> f x y }) foldl1 f xs = fromMaybe (error "foldl1: empty structure") (foldl mf Nothing xs) where mf m y = Just (case m of { Nothing -> y Just x -> f x y }) toList t = build (\ c n -> foldr c n t) null = foldr (\ _ _ -> False) True length = foldl' (\ c _ -> c + 1) 0 elem = any . (==) maximum = fromMaybe (error "maximum: empty structure") . getMax . foldMap (Max #. (Just :: a -> Maybe a)) minimum = fromMaybe (error "minimum: empty structure") . getMin . foldMap (Min #. (Just :: a -> Maybe a)) sum = getSum #. foldMap Sum product = getProduct #. foldMap Product
- Data.Ix: class Ord a => Ix a where index b i | inRange b i = unsafeIndex b i | otherwise = hopelessIndexError unsafeIndex b i = index b i rangeSize b@(_l, h) | inRange b h = unsafeIndex b h + 1 | otherwise = 0 unsafeRangeSize b@(_l, h) = unsafeIndex b h + 1
+ Data.Ix: class (Ord a) => Ix a where index b i | inRange b i = unsafeIndex b i | otherwise = hopelessIndexError unsafeIndex b i = index b i rangeSize b@(_l, h) | inRange b h = unsafeIndex b h + 1 | otherwise = 0 unsafeRangeSize b@(_l, h) = unsafeIndex b h + 1
- Data.List: (\\) :: Eq a => [a] -> [a] -> [a]
+ Data.List: (\\) :: (Eq a) => [a] -> [a] -> [a]
- Data.List: all :: (a -> Bool) -> [a] -> Bool
+ Data.List: all :: Foldable t => (a -> Bool) -> t a -> Bool
- Data.List: and :: [Bool] -> Bool
+ Data.List: and :: Foldable t => t Bool -> Bool
- Data.List: any :: (a -> Bool) -> [a] -> Bool
+ Data.List: any :: Foldable t => (a -> Bool) -> t a -> Bool
- Data.List: concat :: [[a]] -> [a]
+ Data.List: concat :: Foldable t => t [a] -> [a]
- Data.List: concatMap :: (a -> [b]) -> [a] -> [b]
+ Data.List: concatMap :: Foldable t => (a -> [b]) -> t a -> [b]
- Data.List: delete :: Eq a => a -> [a] -> [a]
+ Data.List: delete :: (Eq a) => a -> [a] -> [a]
- Data.List: elem :: Eq a => a -> [a] -> Bool
+ Data.List: elem :: (Foldable t, Eq a) => a -> t a -> Bool
- Data.List: find :: (a -> Bool) -> [a] -> Maybe a
+ Data.List: find :: Foldable t => (a -> Bool) -> t a -> Maybe a
- Data.List: foldl :: (b -> a -> b) -> b -> [a] -> b
+ Data.List: foldl :: Foldable t => (b -> a -> b) -> b -> t a -> b
- Data.List: foldl' :: (b -> a -> b) -> b -> [a] -> b
+ Data.List: foldl' :: Foldable t => (b -> a -> b) -> b -> t a -> b
- Data.List: foldl1 :: (a -> a -> a) -> [a] -> a
+ Data.List: foldl1 :: Foldable t => (a -> a -> a) -> t a -> a
- Data.List: foldr :: (a -> b -> b) -> b -> [a] -> b
+ Data.List: foldr :: Foldable t => (a -> b -> b) -> b -> t a -> b
- Data.List: foldr1 :: (a -> a -> a) -> [a] -> a
+ Data.List: foldr1 :: Foldable t => (a -> a -> a) -> t a -> a
- Data.List: genericDrop :: Integral i => i -> [a] -> [a]
+ Data.List: genericDrop :: (Integral i) => i -> [a] -> [a]
- Data.List: genericIndex :: Integral i => [a] -> i -> a
+ Data.List: genericIndex :: (Integral i) => [a] -> i -> a
- Data.List: genericLength :: Num i => [a] -> i
+ Data.List: genericLength :: (Num i) => [a] -> i
- Data.List: genericReplicate :: Integral i => i -> a -> [a]
+ Data.List: genericReplicate :: (Integral i) => i -> a -> [a]
- Data.List: genericSplitAt :: Integral i => i -> [a] -> ([a], [a])
+ Data.List: genericSplitAt :: (Integral i) => i -> [a] -> ([a], [a])
- Data.List: genericTake :: Integral i => i -> [a] -> [a]
+ Data.List: genericTake :: (Integral i) => i -> [a] -> [a]
- Data.List: intersect :: Eq a => [a] -> [a] -> [a]
+ Data.List: intersect :: (Eq a) => [a] -> [a] -> [a]
- Data.List: isInfixOf :: Eq a => [a] -> [a] -> Bool
+ Data.List: isInfixOf :: (Eq a) => [a] -> [a] -> Bool
- Data.List: isPrefixOf :: Eq a => [a] -> [a] -> Bool
+ Data.List: isPrefixOf :: (Eq a) => [a] -> [a] -> Bool
- Data.List: isSuffixOf :: Eq a => [a] -> [a] -> Bool
+ Data.List: isSuffixOf :: (Eq a) => [a] -> [a] -> Bool
- Data.List: length :: [a] -> Int
+ Data.List: length :: Foldable t => t a -> Int
- Data.List: lookup :: Eq a => a -> [(a, b)] -> Maybe b
+ Data.List: lookup :: (Eq a) => a -> [(a, b)] -> Maybe b
- Data.List: mapAccumL :: (acc -> x -> (acc, y)) -> acc -> [x] -> (acc, [y])
+ Data.List: mapAccumL :: Traversable t => (a -> b -> (a, c)) -> a -> t b -> (a, t c)
- Data.List: mapAccumR :: (acc -> x -> (acc, y)) -> acc -> [x] -> (acc, [y])
+ Data.List: mapAccumR :: Traversable t => (a -> b -> (a, c)) -> a -> t b -> (a, t c)
- Data.List: maximum :: Ord a => [a] -> a
+ Data.List: maximum :: (Foldable t, Ord a) => t a -> a
- Data.List: maximumBy :: (a -> a -> Ordering) -> [a] -> a
+ Data.List: maximumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a
- Data.List: minimum :: Ord a => [a] -> a
+ Data.List: minimum :: (Foldable t, Ord a) => t a -> a
- Data.List: minimumBy :: (a -> a -> Ordering) -> [a] -> a
+ Data.List: minimumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a
- Data.List: notElem :: Eq a => a -> [a] -> Bool
+ Data.List: notElem :: (Foldable t, Eq a) => a -> t a -> Bool
- Data.List: nub :: Eq a => [a] -> [a]
+ Data.List: nub :: (Eq a) => [a] -> [a]
- Data.List: null :: [a] -> Bool
+ Data.List: null :: Foldable t => t a -> Bool
- Data.List: or :: [Bool] -> Bool
+ Data.List: or :: Foldable t => t Bool -> Bool
- Data.List: product :: Num a => [a] -> a
+ Data.List: product :: (Foldable t, Num a) => t a -> a
- Data.List: sort :: Ord a => [a] -> [a]
+ Data.List: sort :: (Ord a) => [a] -> [a]
- Data.List: sum :: Num a => [a] -> a
+ Data.List: sum :: (Foldable t, Num a) => t a -> a
- Data.List: union :: Eq a => [a] -> [a] -> [a]
+ Data.List: union :: (Eq a) => [a] -> [a] -> [a]
- Data.Ord: comparing :: Ord a => (b -> a) -> b -> b -> Ordering
+ Data.Ord: comparing :: (Ord a) => (b -> a) -> b -> b -> Ordering
- Data.Ratio: (%) :: Integral a => a -> a -> Ratio a
+ Data.Ratio: (%) :: (Integral a) => a -> a -> Ratio a
- Data.Ratio: approxRational :: RealFrac a => a -> a -> Rational
+ Data.Ratio: approxRational :: (RealFrac a) => a -> a -> Rational
- Data.Ratio: denominator :: Integral a => Ratio a -> a
+ Data.Ratio: denominator :: (Integral a) => Ratio a -> a
- Data.Ratio: numerator :: Integral a => Ratio a -> a
+ Data.Ratio: numerator :: (Integral a) => Ratio a -> a
- Data.Traversable: class (Functor t, Foldable t) => Traversable t where traverse f = sequenceA . fmap f sequenceA = traverse id mapM f = unwrapMonad . traverse (WrapMonad . f) sequence = mapM id
+ Data.Traversable: class (Functor t, Foldable t) => Traversable t where traverse f = sequenceA . fmap f sequenceA = traverse id mapM = traverse sequence = sequenceA
- Data.Type.Equality: gcastWith :: (a :~: b) -> (a ~ b => r) -> r
+ Data.Type.Equality: gcastWith :: (a :~: b) -> ((a ~ b) => r) -> r
- Debug.Trace: traceM :: Monad m => String -> m ()
+ Debug.Trace: traceM :: (Monad m) => String -> m ()
- Debug.Trace: traceShow :: Show a => a -> b -> b
+ Debug.Trace: traceShow :: (Show a) => a -> b -> b
- Debug.Trace: traceShowId :: Show a => a -> a
+ Debug.Trace: traceShowId :: (Show a) => a -> a
- GHC.Event: new :: Bool -> IO EventManager
+ GHC.Event: new :: IO EventManager
- GHC.Event: registerFd :: EventManager -> IOCallback -> Fd -> Event -> IO FdKey
+ GHC.Event: registerFd :: EventManager -> IOCallback -> Fd -> Event -> Lifetime -> IO FdKey
- GHC.Exts: coerce :: Coercible k a b => a -> b
+ GHC.Exts: coerce :: Coercible * a b => a -> b
- Numeric: floatToDigits :: RealFloat a => Integer -> a -> ([Int], Int)
+ Numeric: floatToDigits :: (RealFloat a) => Integer -> a -> ([Int], Int)
- Numeric: fromRat :: RealFloat a => Rational -> a
+ Numeric: fromRat :: (RealFloat a) => Rational -> a
- Numeric: readSigned :: Real a => ReadS a -> ReadS a
+ Numeric: readSigned :: (Real a) => ReadS a -> ReadS a
- Numeric: showEFloat :: RealFloat a => Maybe Int -> a -> ShowS
+ Numeric: showEFloat :: (RealFloat a) => Maybe Int -> a -> ShowS
- Numeric: showFFloat :: RealFloat a => Maybe Int -> a -> ShowS
+ Numeric: showFFloat :: (RealFloat a) => Maybe Int -> a -> ShowS
- Numeric: showFFloatAlt :: RealFloat a => Maybe Int -> a -> ShowS
+ Numeric: showFFloatAlt :: (RealFloat a) => Maybe Int -> a -> ShowS
- Numeric: showFloat :: RealFloat a => a -> ShowS
+ Numeric: showFloat :: (RealFloat a) => a -> ShowS
- Numeric: showGFloat :: RealFloat a => Maybe Int -> a -> ShowS
+ Numeric: showGFloat :: (RealFloat a) => Maybe Int -> a -> ShowS
- Numeric: showGFloatAlt :: RealFloat a => Maybe Int -> a -> ShowS
+ Numeric: showGFloatAlt :: (RealFloat a) => Maybe Int -> a -> ShowS
- Numeric: showSigned :: Real a => (a -> ShowS) -> Int -> a -> ShowS
+ Numeric: showSigned :: (Real a) => (a -> ShowS) -> Int -> a -> ShowS
- Prelude: all :: (a -> Bool) -> [a] -> Bool
+ Prelude: all :: Foldable t => (a -> Bool) -> t a -> Bool
- Prelude: and :: [Bool] -> Bool
+ Prelude: and :: Foldable t => t Bool -> Bool
- Prelude: any :: (a -> Bool) -> [a] -> Bool
+ Prelude: any :: Foldable t => (a -> Bool) -> t a -> Bool
- Prelude: class Fractional a => Floating a where x ** y = exp (log x * y) logBase x y = log y / log x sqrt x = x ** 0.5 tan x = sin x / cos x tanh x = sinh x / cosh x
+ Prelude: class (Fractional a) => Floating a where x ** y = exp (log x * y) logBase x y = log y / log x sqrt x = x ** 0.5 tan x = sin x / cos x tanh x = sinh x / cosh x
- Prelude: class Num a => Fractional a where recip x = 1 / x x / y = x * recip y
+ Prelude: class (Num a) => Fractional a where recip x = 1 / x x / y = x * recip y
- Prelude: class Monad m where m >> k = m >>= \ _ -> k fail s = error s
+ Prelude: class Applicative m => Monad m where m >> k = m >>= \ _ -> k return = pure fail s = error s
- Prelude: concat :: [[a]] -> [a]
+ Prelude: concat :: Foldable t => t [a] -> [a]
- Prelude: concatMap :: (a -> [b]) -> [a] -> [b]
+ Prelude: concatMap :: Foldable t => (a -> [b]) -> t a -> [b]
- Prelude: elem :: Eq a => a -> [a] -> Bool
+ Prelude: elem :: (Foldable t, Eq a) => a -> t a -> Bool
- Prelude: even :: Integral a => a -> Bool
+ Prelude: even :: (Integral a) => a -> Bool
- Prelude: foldl :: (b -> a -> b) -> b -> [a] -> b
+ Prelude: foldl :: Foldable t => (b -> a -> b) -> b -> t a -> b
- Prelude: foldl1 :: (a -> a -> a) -> [a] -> a
+ Prelude: foldl1 :: Foldable t => (a -> a -> a) -> t a -> a
- Prelude: foldr :: (a -> b -> b) -> b -> [a] -> b
+ Prelude: foldr :: Foldable t => (a -> b -> b) -> b -> t a -> b
- Prelude: foldr1 :: (a -> a -> a) -> [a] -> a
+ Prelude: foldr1 :: Foldable t => (a -> a -> a) -> t a -> a
- Prelude: gcd :: Integral a => a -> a -> a
+ Prelude: gcd :: (Integral a) => a -> a -> a
- Prelude: lcm :: Integral a => a -> a -> a
+ Prelude: lcm :: (Integral a) => a -> a -> a
- Prelude: length :: [a] -> Int
+ Prelude: length :: Foldable t => t a -> Int
- Prelude: lookup :: Eq a => a -> [(a, b)] -> Maybe b
+ Prelude: lookup :: (Eq a) => a -> [(a, b)] -> Maybe b
- Prelude: mapM :: Monad m => (a -> m b) -> [a] -> m [b]
+ Prelude: mapM :: (Traversable t, Monad m) => (a -> m b) -> t a -> m (t b)
- Prelude: mapM_ :: Monad m => (a -> m b) -> [a] -> m ()
+ Prelude: mapM_ :: (Foldable t, Monad m) => (a -> m b) -> t a -> m ()
- Prelude: maximum :: Ord a => [a] -> a
+ Prelude: maximum :: (Foldable t, Ord a) => t a -> a
- Prelude: minimum :: Ord a => [a] -> a
+ Prelude: minimum :: (Foldable t, Ord a) => t a -> a
- Prelude: notElem :: Eq a => a -> [a] -> Bool
+ Prelude: notElem :: (Foldable t, Eq a) => a -> t a -> Bool
- Prelude: null :: [a] -> Bool
+ Prelude: null :: Foldable t => t a -> Bool
- Prelude: odd :: Integral a => a -> Bool
+ Prelude: odd :: (Integral a) => a -> Bool
- Prelude: or :: [Bool] -> Bool
+ Prelude: or :: Foldable t => t Bool -> Bool
- Prelude: product :: Num a => [a] -> a
+ Prelude: product :: (Foldable t, Num a) => t a -> a
- Prelude: sequence :: Monad m => [m a] -> m [a]
+ Prelude: sequence :: (Traversable t, Monad m) => t (m a) -> m (t a)
- Prelude: sequence_ :: Monad m => [m a] -> m ()
+ Prelude: sequence_ :: (Foldable t, Monad m) => t (m a) -> m ()
- Prelude: shows :: Show a => a -> ShowS
+ Prelude: shows :: (Show a) => a -> ShowS
- Prelude: subtract :: Num a => a -> a -> a
+ Prelude: subtract :: (Num a) => a -> a -> a
- Prelude: sum :: Num a => [a] -> a
+ Prelude: sum :: (Foldable t, Num a) => t a -> a
- Text.Printf: hPrintf :: HPrintfType r => Handle -> String -> r
+ Text.Printf: hPrintf :: (HPrintfType r) => Handle -> String -> r
- Text.Printf: printf :: PrintfType r => String -> r
+ Text.Printf: printf :: (PrintfType r) => String -> r
- Text.Show: shows :: Show a => a -> ShowS
+ Text.Show: shows :: (Show a) => a -> ShowS

Files

Control/Applicative.hs view
@@ -1,6 +1,9 @@ {-# LANGUAGE Trustworthy #-} {-# LANGUAGE AutoDeriveTypeable #-} {-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE NoImplicitPrelude #-}+{-# LANGUAGE ScopedTypeVariables #-}  ----------------------------------------------------------------------------- -- |@@ -46,210 +49,49 @@     optional,     ) where -import Prelude hiding (id,(.))--import Control.Category+import Control.Category hiding ((.), id) import Control.Arrow-import Control.Monad (liftM, ap, MonadPlus(..))-import Control.Monad.ST.Safe (ST)-import qualified Control.Monad.ST.Lazy.Safe as Lazy (ST)-import Data.Functor ((<$>), (<$))-import Data.Monoid (Monoid(..))-import Data.Proxy--import Text.ParserCombinators.ReadP (ReadP)-import Text.ParserCombinators.ReadPrec (ReadPrec)+import Data.Maybe+import Data.Tuple+import Data.Eq+import Data.Ord+import Data.Foldable (Foldable(..))+import Data.Functor ((<$>)) -import GHC.Conc (STM, retry, orElse)+import GHC.Base import GHC.Generics--infixl 3 <|>-infixl 4 <*>, <*, *>, <**>---- | A functor with application, providing operations to------ * embed pure expressions ('pure'), and------ * sequence computations and combine their results ('<*>').------ A minimal complete definition must include implementations of these--- functions satisfying the following laws:------ [/identity/]------      @'pure' 'id' '<*>' v = v@------ [/composition/]------      @'pure' (.) '<*>' u '<*>' v '<*>' w = u '<*>' (v '<*>' w)@------ [/homomorphism/]------      @'pure' f '<*>' 'pure' x = 'pure' (f x)@------ [/interchange/]------      @u '<*>' 'pure' y = 'pure' ('$' y) '<*>' u@------ The other methods have the following default definitions, which may--- be overridden with equivalent specialized implementations:------   * @u '*>' v = 'pure' ('const' 'id') '<*>' u '<*>' v@------   * @u '<*' v = 'pure' 'const' '<*>' u '<*>' v@------ As a consequence of these laws, the 'Functor' instance for @f@ will satisfy------   * @'fmap' f x = 'pure' f '<*>' x@------ If @f@ is also a 'Monad', it should satisfy------   * @'pure' = 'return'@------   * @('<*>') = 'ap'@------ (which implies that 'pure' and '<*>' satisfy the applicative functor laws).--class Functor f => Applicative f where-    -- | Lift a value.-    pure :: a -> f a--    -- | Sequential application.-    (<*>) :: f (a -> b) -> f a -> f b--    -- | Sequence actions, discarding the value of the first argument.-    (*>) :: f a -> f b -> f b-    (*>) = liftA2 (const id)--    -- | Sequence actions, discarding the value of the second argument.-    (<*) :: f a -> f b -> f a-    (<*) = liftA2 const---- | A monoid on applicative functors.------ Minimal complete definition: 'empty' and '<|>'.------ If defined, 'some' and 'many' should be the least solutions--- of the equations:------ * @some v = (:) '<$>' v '<*>' many v@------ * @many v = some v '<|>' 'pure' []@-class Applicative f => Alternative f where-    -- | The identity of '<|>'-    empty :: f a-    -- | An associative binary operation-    (<|>) :: f a -> f a -> f a--    -- | One or more.-    some :: f a -> f [a]-    some v = some_v-      where-        many_v = some_v <|> pure []-        some_v = (:) <$> v <*> many_v--    -- | Zero or more.-    many :: f a -> f [a]-    many v = many_v-      where-        many_v = some_v <|> pure []-        some_v = (:) <$> v <*> many_v---- instances for Prelude types--instance Applicative Maybe where-    pure = return-    (<*>) = ap--instance Alternative Maybe where-    empty = Nothing-    Nothing <|> r = r-    l       <|> _ = l--instance Applicative [] where-    pure = return-    (<*>) = ap--instance Alternative [] where-    empty = []-    (<|>) = (++)--instance Applicative IO where-    pure = return-    (<*>) = ap--instance Applicative (ST s) where-    pure = return-    (<*>) = ap--instance Applicative (Lazy.ST s) where-    pure = return-    (<*>) = ap--instance Applicative STM where-    pure = return-    (<*>) = ap--instance Alternative STM where-    empty = retry-    (<|>) = orElse--instance Applicative ((->) a) where-    pure = const-    (<*>) f g x = f x (g x)--instance Monoid a => Applicative ((,) a) where-    pure x = (mempty, x)-    (u, f) <*> (v, x) = (u `mappend` v, f x)--instance Applicative (Either e) where-    pure          = Right-    Left  e <*> _ = Left e-    Right f <*> r = fmap f r--instance Applicative ReadP where-    pure = return-    (<*>) = ap--instance Alternative ReadP where-    empty = mzero-    (<|>) = mplus--instance Applicative ReadPrec where-    pure = return-    (<*>) = ap--instance Alternative ReadPrec where-    empty = mzero-    (<|>) = mplus+import GHC.List (repeat, zipWith)+import GHC.Read (Read(readsPrec), readParen, lex)+import GHC.Show (Show(showsPrec), showParen, showString) -instance Arrow a => Applicative (ArrowMonad a) where-   pure x = ArrowMonad (arr (const x))-   ArrowMonad f <*> ArrowMonad x = ArrowMonad (f &&& x >>> arr (uncurry id))+newtype Const a b = Const { getConst :: a }+                  deriving (Generic, Generic1, Monoid, Eq, Ord) -instance ArrowPlus a => Alternative (ArrowMonad a) where-   empty = ArrowMonad zeroArrow-   ArrowMonad x <|> ArrowMonad y = ArrowMonad (x <+> y)+instance Read a => Read (Const a b) where+    readsPrec d = readParen (d > 10)+        $ \r -> [(Const x,t) | ("Const", s) <- lex r, (x, t) <- readsPrec 11 s] --- new instances+instance Show a => Show (Const a b) where+    showsPrec d (Const x) = showParen (d > 10) $+                            showString "Const " . showsPrec 11 x -newtype Const a b = Const { getConst :: a }-                  deriving (Generic, Generic1)+instance Foldable (Const m) where+    foldMap _ _ = mempty  instance Functor (Const m) where     fmap _ (Const v) = Const v --- Added in base-4.7.0.0-instance Monoid a => Monoid (Const a b) where-    mempty = Const mempty-    mappend (Const a) (Const b) = Const (mappend a b)- instance Monoid m => Applicative (Const m) where     pure _ = Const mempty-    Const f <*> Const v = Const (f `mappend` v)+    (<*>) = coerce (mappend :: m -> m -> m)+-- This is pretty much the same as+-- Const f <*> Const v = Const (f `mappend` v)+-- but guarantees that mappend for Const a b will have the same arity+-- as the one for a; it won't create a closure to raise the arity+-- to 2.  newtype WrappedMonad m a = WrapMonad { unwrapMonad :: m a }-                         deriving (Generic, Generic1)+                         deriving (Generic, Generic1, Monad)  instance Monad m => Functor (WrappedMonad m) where     fmap f (WrapMonad v) = WrapMonad (liftM f v)@@ -258,11 +100,6 @@     pure = WrapMonad . return     WrapMonad f <*> WrapMonad v = WrapMonad (f `ap` v) --- Added in base-4.7.0.0 (GHC Trac #8218)-instance Monad m => Monad (WrappedMonad m) where-    return = WrapMonad . return-    a >>= f = WrapMonad (unwrapMonad a >>= unwrapMonad . f)- instance MonadPlus m => Alternative (WrappedMonad m) where     empty = WrapMonad mzero     WrapMonad u <|> WrapMonad v = WrapMonad (u `mplus` v)@@ -286,39 +123,13 @@ -- @f '<$>' 'ZipList' xs1 '<*>' ... '<*>' 'ZipList' xsn = 'ZipList' (zipWithn f xs1 ... xsn)@ -- newtype ZipList a = ZipList { getZipList :: [a] }-                  deriving (Show, Eq, Ord, Read, Generic, Generic1)--instance Functor ZipList where-    fmap f (ZipList xs) = ZipList (map f xs)+                  deriving (Show, Eq, Ord, Read, Functor, Generic, Generic1)  instance Applicative ZipList where     pure x = ZipList (repeat x)     ZipList fs <*> ZipList xs = ZipList (zipWith id fs xs) -instance Applicative Proxy where-    pure _ = Proxy-    {-# INLINE pure #-}-    _ <*> _ = Proxy-    {-# INLINE (<*>) #-}- -- extra functions---- | A variant of '<*>' with the arguments reversed.-(<**>) :: Applicative f => f a -> f (a -> b) -> f b-(<**>) = liftA2 (flip ($))---- | Lift a function to actions.--- This function may be used as a value for `fmap` in a `Functor` instance.-liftA :: Applicative f => (a -> b) -> f a -> f b-liftA f a = pure f <*> a---- | Lift a binary function to actions.-liftA2 :: Applicative f => (a -> b -> c) -> f a -> f b -> f c-liftA2 f a b = f <$> a <*> b---- | Lift a ternary function to actions.-liftA3 :: Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d-liftA3 f a b c = f <$> a <*> b <*> c  -- | One or none. optional :: Alternative f => f a -> f (Maybe a)
Control/Arrow.hs view
@@ -1,4 +1,6 @@ {-# LANGUAGE Trustworthy #-}+{-# LANGUAGE NoImplicitPrelude #-}+ ----------------------------------------------------------------------------- -- | -- Module      :  Control.Arrow@@ -41,11 +43,11 @@     ArrowLoop(..)     ) where -import Prelude hiding (id,(.))--import Control.Monad+import Data.Tuple ( fst, snd, uncurry )+import Data.Either import Control.Monad.Fix import Control.Category+import GHC.Base hiding ( (.), id )  infixr 5 <+> infixr 3 ***@@ -57,7 +59,7 @@  -- | The basic arrow class. ----- Minimal complete definition: 'arr' and 'first', satisfying the laws+-- Instances should satisfy the following laws: -- --  * @'arr' id = 'id'@ --@@ -191,7 +193,7 @@ -- | Choice, for arrows that support it.  This class underlies the -- @if@ and @case@ constructs in arrow notation. ----- Minimal complete definition: 'left', satisfying the laws+-- Instances should satisfy the following laws: -- --  * @'left' ('arr' f) = 'arr' ('left' f)@ --@@ -304,10 +306,18 @@ instance Arrow a => Functor (ArrowMonad a) where     fmap f (ArrowMonad m) = ArrowMonad $ m >>> arr f +instance Arrow a => Applicative (ArrowMonad a) where+   pure x = ArrowMonad (arr (const x))+   ArrowMonad f <*> ArrowMonad x = ArrowMonad (f &&& x >>> arr (uncurry id))+ instance ArrowApply a => Monad (ArrowMonad a) where     return x = ArrowMonad (arr (\_ -> x))     ArrowMonad m >>= f = ArrowMonad $         m >>> arr (\x -> let ArrowMonad h = f x in (h, ())) >>> app++instance ArrowPlus a => Alternative (ArrowMonad a) where+   empty = ArrowMonad zeroArrow+   ArrowMonad x <|> ArrowMonad y = ArrowMonad (x <+> y)  instance (ArrowApply a, ArrowPlus a) => MonadPlus (ArrowMonad a) where    mzero = ArrowMonad zeroArrow
Control/Category.hs view
@@ -1,9 +1,7 @@ {-# LANGUAGE Trustworthy #-}-{-# LANGUAGE CPP #-}--#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 706-{-# LANGUAGE PolyKinds, GADTs #-}-#endif+{-# LANGUAGE GADTs #-}+{-# LANGUAGE NoImplicitPrelude #-}+{-# LANGUAGE PolyKinds #-}  ----------------------------------------------------------------------------- -- |@@ -15,11 +13,11 @@ -- Stability   :  experimental -- Portability :  portable --- http://hackage.haskell.org/trac/ghc/ticket/1773+-- http://ghc.haskell.org/trac/ghc/ticket/1773  module Control.Category where -import qualified Prelude+import qualified GHC.Base (id,(.)) import Data.Type.Coercion import Data.Type.Equality import GHC.Prim (coerce)@@ -46,8 +44,8 @@  #-}  instance Category (->) where-    id = Prelude.id-    (.) = (Prelude..)+    id = GHC.Base.id+    (.) = (GHC.Base..)  instance Category (:~:) where   id          = Refl
Control/Concurrent.hs view
@@ -4,7 +4,6 @@            , UnboxedTuples            , ScopedTypeVariables   #-}-{-# OPTIONS_GHC -fno-warn-unused-imports #-} {-# OPTIONS_GHC -fno-warn-deprecations #-} -- kludge for the Control.Concurrent.QSem, Control.Concurrent.QSemN -- and Control.Concurrent.SampleVar imports.@@ -104,27 +103,24 @@      ) where -import Prelude- import Control.Exception.Base as Exception -import GHC.Exception import GHC.Conc hiding (threadWaitRead, threadWaitWrite,                         threadWaitReadSTM, threadWaitWriteSTM)-import qualified GHC.Conc-import GHC.IO           ( IO(..), unsafeInterleaveIO, unsafeUnmask )+import GHC.IO           ( unsafeUnmask ) import GHC.IORef        ( newIORef, readIORef, writeIORef ) import GHC.Base  import System.Posix.Types ( Fd ) import Foreign.StablePtr import Foreign.C.Types-import Control.Monad  #ifdef mingw32_HOST_OS import Foreign.C import System.IO-import Data.Maybe (Maybe(..))+import Data.Functor ( void )+#else+import qualified GHC.Conc #endif  import Control.Concurrent.MVar@@ -195,7 +191,7 @@ -- This function is useful for informing the parent when a child -- terminates, for example. ----- /Since: 4.6.0.0/+-- @since 4.6.0.0 forkFinally :: IO a -> (Either SomeException a -> IO ()) -> IO ThreadId forkFinally action and_then =   mask $ \restore ->@@ -361,8 +357,8 @@  Use this function /only/ in the rare case that you have actually observed a performance loss due to the use of bound threads. A program that-doesn't need it's main thread to be bound and makes /heavy/ use of concurrency-(e.g. a web server), might want to wrap it's @main@ action in+doesn't need its main thread to be bound and makes /heavy/ use of concurrency+(e.g. a web server), might want to wrap its @main@ action in @runInUnboundThread@.  Note that exceptions which are thrown to the current thread are thrown in turn@@ -435,7 +431,7 @@ -- is an IO action that can be used to deregister interest -- in the file descriptor. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 threadWaitReadSTM :: Fd -> IO (STM (), IO ()) threadWaitReadSTM fd #ifdef mingw32_HOST_OS@@ -459,7 +455,7 @@ -- is an IO action that can be used to deregister interest -- in the file descriptor. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 threadWaitWriteSTM :: Fd -> IO (STM (), IO ()) threadWaitWriteSTM fd #ifdef mingw32_HOST_OS
Control/Concurrent/Chan.hs view
@@ -1,6 +1,6 @@ {-# LANGUAGE Trustworthy #-} {-# LANGUAGE CPP #-}-{-# LANGUAGE DeriveDataTypeable, StandaloneDeriving #-}+{-# LANGUAGE AutoDeriveTypeable, StandaloneDeriving #-}  ----------------------------------------------------------------------------- -- |@@ -33,8 +33,6 @@         getChanContents,         writeList2Chan,    ) where--import Prelude  import System.IO.Unsafe         ( unsafeInterleaveIO ) import Control.Concurrent.MVar
Control/Concurrent/MVar.hs view
@@ -193,7 +193,7 @@   Like 'withMVar', but the @IO@ action in the second argument is executed   with asynchronous exceptions masked. -  /Since: 4.7.0.0/+  @since 4.7.0.0 -} {-# INLINE withMVarMasked #-} withMVarMasked :: MVar a -> (a -> IO b) -> IO b@@ -236,7 +236,7 @@   Like 'modifyMVar_', but the @IO@ action in the second argument is executed with   asynchronous exceptions masked. -  /Since: 4.6.0.0/+  @since 4.6.0.0 -} {-# INLINE modifyMVarMasked_ #-} modifyMVarMasked_ :: MVar a -> (a -> IO a) -> IO ()@@ -250,7 +250,7 @@   Like 'modifyMVar', but the @IO@ action in the second argument is executed with   asynchronous exceptions masked. -  /Since: 4.6.0.0/+  @since 4.6.0.0 -} {-# INLINE modifyMVarMasked #-} modifyMVarMasked :: MVar a -> (a -> IO (a,b)) -> IO b@@ -268,7 +268,7 @@ -- | Make a 'Weak' pointer to an 'MVar', using the second argument as -- a finalizer to run when 'MVar' is garbage-collected ----- /Since: 4.6.0.0/+-- @since 4.6.0.0 mkWeakMVar :: MVar a -> IO () -> IO (Weak (MVar a)) mkWeakMVar m@(MVar m#) f = IO $ \s ->   case mkWeak# m# m f s of (# s1, w #) -> (# s1, Weak w #)
Control/Concurrent/QSem.hs view
@@ -1,5 +1,5 @@-{-# LANGUAGE Trustworthy #-}-{-# LANGUAGE DeriveDataTypeable, BangPatterns #-}+{-# LANGUAGE Safe #-}+{-# LANGUAGE AutoDeriveTypeable, BangPatterns #-} {-# OPTIONS_GHC -funbox-strict-fields #-}  -----------------------------------------------------------------------------
Control/Concurrent/QSemN.hs view
@@ -1,5 +1,5 @@-{-# LANGUAGE Trustworthy #-}-{-# LANGUAGE DeriveDataTypeable, BangPatterns #-}+{-# LANGUAGE Safe #-}+{-# LANGUAGE AutoDeriveTypeable, BangPatterns #-} {-# OPTIONS_GHC -funbox-strict-fields #-}  -----------------------------------------------------------------------------
Control/Exception.hs view
@@ -48,6 +48,7 @@         NestedAtomically(..),         BlockedIndefinitelyOnMVar(..),         BlockedIndefinitelyOnSTM(..),+        AllocationLimitExceeded(..),         Deadlock(..),         NoMethodError(..),         PatternMatchFail(..),@@ -133,7 +134,6 @@  import GHC.Base import GHC.IO (unsafeUnmask)-import Data.Maybe  -- | You need this when using 'catches'. data Handler a = forall e . Exception e => Handler (e -> IO a)@@ -191,11 +191,11 @@    case use 'catch' or 'catchJust'.  The difference between using 'try' and 'catch' for recovery is that in-'catch' the handler is inside an implicit 'block' (see \"Asynchronous+'catch' the handler is inside an implicit 'mask' (see \"Asynchronous Exceptions\") which is important when catching asynchronous exceptions, but when catching other kinds of exception it is unnecessary.  Furthermore it is possible to accidentally stay inside-the implicit 'block' by tail-calling rather than returning from the+the implicit 'mask' by tail-calling rather than returning from the handler, which is why we recommend using 'try' rather than 'catch' for ordinary exception recovery. @@ -211,7 +211,7 @@ -- ----------------------------------------------------------------------------- -- Asynchronous exceptions --- | When invoked inside 'mask', this function allows a blocked+-- | When invoked inside 'mask', this function allows a masked -- asynchronous exception to be raised, if one exists.  It is -- equivalent to performing an interruptible operation (see -- #interruptible#), but does not involve any actual blocking.@@ -219,7 +219,7 @@ -- When called outside 'mask', or inside 'uninterruptibleMask', this -- function has no effect. ----- /Since: 4.4.0.0/+-- @since 4.4.0.0 allowInterrupt :: IO () allowInterrupt = unsafeUnmask $ return () @@ -259,7 +259,7 @@ >           catch (restore (...)) >                 (\e -> handler) -If you need to unblock asynchronous exceptions again in the exception+If you need to unmask asynchronous exceptions again in the exception handler, 'restore' can be used there too.  Note that 'try' and friends /do not/ have a similar default, because
Control/Exception/Base.hs view
@@ -1,13 +1,13 @@ {-# LANGUAGE Trustworthy #-} {-# LANGUAGE NoImplicitPrelude, MagicHash #-}-{-# LANGUAGE DeriveDataTypeable, StandaloneDeriving #-}+{-# LANGUAGE AutoDeriveTypeable, StandaloneDeriving #-}  ----------------------------------------------------------------------------- -- | -- Module      :  Control.Exception.Base -- Copyright   :  (c) The University of Glasgow 2001 -- License     :  BSD-style (see the file libraries/base/LICENSE)--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  experimental -- Portability :  non-portable (extended exceptions)@@ -31,6 +31,7 @@         NestedAtomically(..),         BlockedIndefinitelyOnMVar(..),         BlockedIndefinitelyOnSTM(..),+        AllocationLimitExceeded(..),         Deadlock(..),         NoMethodError(..),         PatternMatchFail(..),@@ -105,7 +106,6 @@  import Data.Dynamic import Data.Either-import Data.Maybe  ----------------------------------------------------------------------------- -- Catching exceptions@@ -388,7 +388,7 @@         :: Addr# -> a   -- All take a UTF8-encoded C string  recSelError              s = throw (RecSelError ("No match in record selector "-			                         ++ unpackCStringUtf8# s))  -- No location info unfortunately+                                                 ++ unpackCStringUtf8# s))  -- No location info unfortunately runtimeError             s = error (unpackCStringUtf8# s)                   -- No location info unfortunately absentError              s = error ("Oops!  Entered absent arg " ++ unpackCStringUtf8# s) 
Control/Monad.hs view
@@ -6,7 +6,7 @@ -- Module      :  Control.Monad -- Copyright   :  (c) The University of Glasgow 2001 -- License     :  BSD-style (see the file libraries/base/LICENSE)--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  provisional -- Portability :  portable@@ -20,11 +20,7 @@        Functor(fmap)     , Monad((>>=), (>>), return, fail)--    , MonadPlus (-          mzero-        , mplus-        )+    , MonadPlus(mzero, mplus)     -- * Functions      -- ** Naming conventions@@ -74,104 +70,37 @@      , ap -    ) where--import Data.Maybe--import GHC.List-import GHC.Base--infixr 1 =<<---- -------------------------------------------------------------------------------- Prelude monad functions---- | Same as '>>=', but with the arguments interchanged.-{-# SPECIALISE (=<<) :: (a -> [b]) -> [a] -> [b] #-}-(=<<)           :: Monad m => (a -> m b) -> m a -> m b-f =<< x         = x >>= f---- | Evaluate each action in the sequence from left to right,--- and collect the results.-sequence       :: Monad m => [m a] -> m [a] -{-# INLINE sequence #-}-sequence ms = foldr k (return []) ms-            where-              k m m' = do { x <- m; xs <- m'; return (x:xs) }---- | Evaluate each action in the sequence from left to right,--- and ignore the results.-sequence_        :: Monad m => [m a] -> m () -{-# INLINE sequence_ #-}-sequence_ ms     =  foldr (>>) (return ()) ms---- | @'mapM' f@ is equivalent to @'sequence' . 'map' f@.-mapM            :: Monad m => (a -> m b) -> [a] -> m [b]-{-# INLINE mapM #-}-mapM f as       =  sequence (map f as)---- | @'mapM_' f@ is equivalent to @'sequence_' . 'map' f@.-mapM_           :: Monad m => (a -> m b) -> [a] -> m ()-{-# INLINE mapM_ #-}-mapM_ f as      =  sequence_ (map f as)---- -------------------------------------------------------------------------------- The MonadPlus class definition---- | Monads that also support choice and failure.-class Monad m => MonadPlus m where-   -- | the identity of 'mplus'.  It should also satisfy the equations-   ---   -- > mzero >>= f  =  mzero-   -- > v >> mzero   =  mzero-   ---   mzero :: m a -   -- | an associative operation-   mplus :: m a -> m a -> m a+    -- ** Strict monadic functions -instance MonadPlus [] where-   mzero = []-   mplus = (++)+    , (<$!>)+    ) where -instance MonadPlus Maybe where-   mzero = Nothing+import Data.Foldable ( Foldable, sequence_, msum, mapM_, foldlM, forM_ )+import Data.Functor ( void )+import Data.Traversable ( forM, mapM, sequence ) -   Nothing `mplus` ys  = ys-   xs      `mplus` _ys = xs+import GHC.Base hiding ( mapM, sequence )+import GHC.List ( zipWith, unzip, replicate )  -- ----------------------------------------------------------------------------- -- Functions mandated by the Prelude --- | @'guard' b@ is @'return' ()@ if @b@ is 'True',--- and 'mzero' if @b@ is 'False'.-guard           :: (MonadPlus m) => Bool -> m ()-guard True      =  return ()-guard False     =  mzero+-- | @'guard' b@ is @'pure' ()@ if @b@ is 'True',+-- and 'empty' if @b@ is 'False'.+guard           :: (Alternative f) => Bool -> f ()+guard True      =  pure ()+guard False     =  empty  -- | This generalizes the list-based 'filter' function. +{-# INLINE filterM #-} filterM          :: (Monad m) => (a -> m Bool) -> [a] -> m [a]-filterM _ []     =  return []-filterM p (x:xs) =  do-   flg <- p x-   ys  <- filterM p xs-   return (if flg then x:ys else ys)---- | 'forM' is 'mapM' with its arguments flipped-forM            :: Monad m => [a] -> (a -> m b) -> m [b]-{-# INLINE forM #-}-forM            = flip mapM---- | 'forM_' is 'mapM_' with its arguments flipped-forM_           :: Monad m => [a] -> (a -> m b) -> m ()-{-# INLINE forM_ #-}-forM_           = flip mapM_---- | This generalizes the list-based 'concat' function.--msum        :: MonadPlus m => [m a] -> m a-{-# INLINE msum #-}-msum        =  foldr mplus mzero+filterM p        = foldr go (return [])+  where+    go x r = do+      flg <- p x+      ys <- r+      return (if flg then x:ys else ys)  infixr 1 <=<, >=> @@ -190,31 +119,24 @@ -- Use explicit sharing here, as it is prevents a space leak regardless of -- optimizations. --- | @'void' value@ discards or ignores the result of evaluation, such as the return value of an 'IO' action.-void :: Functor f => f a -> f ()-void = fmap (const ())- -- ----------------------------------------------------------------------------- -- Other monad functions --- | The 'join' function is the conventional monad join operator. It is used to--- remove one level of monadic structure, projecting its bound argument into the--- outer level.-join              :: (Monad m) => m (m a) -> m a-join x            =  x >>= id- -- | The 'mapAndUnzipM' function maps its first argument over a list, returning -- the result as a pair of lists. This function is mainly used with complicated -- data structures or a state-transforming monad. mapAndUnzipM      :: (Monad m) => (a -> m (b,c)) -> [a] -> m ([b], [c])+{-# INLINE mapAndUnzipM #-} mapAndUnzipM f xs =  sequence (map f xs) >>= return . unzip  -- | The 'zipWithM' function generalizes 'zipWith' to arbitrary monads. zipWithM          :: (Monad m) => (a -> b -> m c) -> [a] -> [b] -> m [c]+{-# INLINE zipWithM #-} zipWithM f xs ys  =  sequence (zipWith f xs ys)  -- | 'zipWithM_' is the extension of 'zipWithM' which ignores the final result. zipWithM_         :: (Monad m) => (a -> b -> m c) -> [a] -> [b] -> m ()+{-# INLINE zipWithM_ #-} zipWithM_ f xs ys =  sequence_ (zipWith f xs ys)  {- | The 'foldM' function is analogous to 'foldl', except that its result is@@ -225,7 +147,7 @@  >       foldM f a1 [x1, x2, ..., xm] -==  +==  >       do >         a2 <- f a1 x1@@ -234,82 +156,56 @@ >         f am xm  If right-to-left evaluation is required, the input list should be reversed.++Note: 'foldM' is the same as 'foldlM' -} -foldM             :: (Monad m) => (a -> b -> m a) -> a -> [b] -> m a-foldM _ a []      =  return a-foldM f a (x:xs)  =  f a x >>= \fax -> foldM f fax xs+foldM          :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m b+{-# INLINEABLE foldM #-}+{-# SPECIALISE foldM :: (a -> b -> IO a) -> a -> [b] -> IO a #-}+{-# SPECIALISE foldM :: (a -> b -> Maybe a) -> a -> [b] -> Maybe a #-}+foldM          = foldlM  -- | Like 'foldM', but discards the result.-foldM_            :: (Monad m) => (a -> b -> m a) -> a -> [b] -> m ()-foldM_ f a xs     = foldM f a xs >> return ()+foldM_         :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m ()+{-# INLINEABLE foldM_ #-}+{-# SPECIALISE foldM_ :: (a -> b -> IO a) -> a -> [b] -> IO () #-}+{-# SPECIALISE foldM_ :: (a -> b -> Maybe a) -> a -> [b] -> Maybe () #-}+foldM_ f a xs  = foldlM f a xs >> return ()  -- | @'replicateM' n act@ performs the action @n@ times, -- gathering the results. replicateM        :: (Monad m) => Int -> m a -> m [a]+{-# INLINEABLE replicateM #-}+{-# SPECIALISE replicateM :: Int -> IO a -> IO [a] #-}+{-# SPECIALISE replicateM :: Int -> Maybe a -> Maybe [a] #-} replicateM n x    = sequence (replicate n x)  -- | Like 'replicateM', but discards the result. replicateM_       :: (Monad m) => Int -> m a -> m ()+{-# INLINEABLE replicateM_ #-}+{-# SPECIALISE replicateM_ :: Int -> IO a -> IO () #-}+{-# SPECIALISE replicateM_ :: Int -> Maybe a -> Maybe () #-} replicateM_ n x   = sequence_ (replicate n x) -{- | Conditional execution of monadic expressions. For example, -->       when debug (putStr "Debugging\n")--will output the string @Debugging\\n@ if the Boolean value @debug@ is 'True',-and otherwise do nothing.--}--when              :: (Monad m) => Bool -> m () -> m ()-when p s          =  if p then s else return ()- -- | The reverse of 'when'.--unless            :: (Monad m) => Bool -> m () -> m ()-unless p s        =  if p then return () else s+unless            :: (Applicative f) => Bool -> f () -> f ()+{-# INLINEABLE unless #-}+{-# SPECIALISE unless :: Bool -> IO () -> IO () #-}+{-# SPECIALISE unless :: Bool -> Maybe () -> Maybe () #-}+unless p s        =  if p then pure () else s --- | Promote a function to a monad.-liftM   :: (Monad m) => (a1 -> r) -> m a1 -> m r-liftM f m1              = do { x1 <- m1; return (f x1) }+infixl 4 <$!> --- | Promote a function to a monad, scanning the monadic arguments from--- left to right.  For example,------ >    liftM2 (+) [0,1] [0,2] = [0,2,1,3]--- >    liftM2 (+) (Just 1) Nothing = Nothing+-- | Strict version of 'Data.Functor.<$>'. ---liftM2  :: (Monad m) => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r-liftM2 f m1 m2          = do { x1 <- m1; x2 <- m2; return (f x1 x2) }---- | Promote a function to a monad, scanning the monadic arguments from--- left to right (cf. 'liftM2').-liftM3  :: (Monad m) => (a1 -> a2 -> a3 -> r) -> m a1 -> m a2 -> m a3 -> m r-liftM3 f m1 m2 m3       = do { x1 <- m1; x2 <- m2; x3 <- m3; return (f x1 x2 x3) }---- | Promote a function to a monad, scanning the monadic arguments from--- left to right (cf. 'liftM2').-liftM4  :: (Monad m) => (a1 -> a2 -> a3 -> a4 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m r-liftM4 f m1 m2 m3 m4    = do { x1 <- m1; x2 <- m2; x3 <- m3; x4 <- m4; return (f x1 x2 x3 x4) }---- | Promote a function to a monad, scanning the monadic arguments from--- left to right (cf. 'liftM2').-liftM5  :: (Monad m) => (a1 -> a2 -> a3 -> a4 -> a5 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m a5 -> m r-liftM5 f m1 m2 m3 m4 m5 = do { x1 <- m1; x2 <- m2; x3 <- m3; x4 <- m4; x5 <- m5; return (f x1 x2 x3 x4 x5) }--{- | In many situations, the 'liftM' operations can be replaced by uses of-'ap', which promotes function application. -->       return f `ap` x1 `ap` ... `ap` xn--is equivalent to -->       liftMn f x1 x2 ... xn---}--ap                :: (Monad m) => m (a -> b) -> m a -> m b-ap                =  liftM2 id+-- @since 4.8.0.0+(<$!>) :: Monad m => (a -> b) -> m a -> m b+{-# INLINE (<$!>) #-}+f <$!> m = do+  x <- m+  let z = f x+  z `seq` return z   -- -----------------------------------------------------------------------------@@ -322,29 +218,30 @@ -- @mfilter odd (Just 2) == Nothing@  mfilter :: (MonadPlus m) => (a -> Bool) -> m a -> m a+{-# INLINEABLE mfilter #-} mfilter p ma = do   a <- ma   if p a then return a else mzero  {- $naming -The functions in this library use the following naming conventions: +The functions in this library use the following naming conventions:  * A postfix \'@M@\' always stands for a function in the Kleisli category:   The monad type constructor @m@ is added to function results-  (modulo currying) and nowhere else.  So, for example, +  (modulo currying) and nowhere else.  So, for example,  >  filter  ::              (a ->   Bool) -> [a] ->   [a] >  filterM :: (Monad m) => (a -> m Bool) -> [a] -> m [a]  * A postfix \'@_@\' changes the result type from @(m a)@ to @(m ())@.-  Thus, for example: +  Thus, for example: ->  sequence  :: Monad m => [m a] -> m [a] ->  sequence_ :: Monad m => [m a] -> m () +>  sequence  :: Monad m => [m a] -> m [a]+>  sequence_ :: Monad m => [m a] -> m ()  * A prefix \'@m@\' generalizes an existing function to a monadic form.-  Thus, for example: +  Thus, for example:  >  sum  :: Num a       => [a]   -> a >  msum :: MonadPlus m => [m a] -> m a
Control/Monad/Fix.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE Trustworthy #-}+{-# LANGUAGE NoImplicitPrelude #-}  ----------------------------------------------------------------------------- -- |@@ -22,10 +23,13 @@         fix   ) where -import Prelude-import System.IO-import Data.Function (fix)+import Data.Either+import Data.Function ( fix )+import Data.Maybe+import GHC.Base ( Monad, error, (.) )+import GHC.List ( head, tail ) import GHC.ST+import System.IO  -- | Monads having fixed points with a \'knot-tying\' semantics. -- Instances of 'MonadFix' should satisfy the following laws:@@ -65,7 +69,7 @@                (x:_) -> x : mfix (tail . f)  instance MonadFix IO where-    mfix = fixIO +    mfix = fixIO  instance MonadFix ((->) r) where     mfix f = \ r -> let a = f a r in a
Control/Monad/Instances.hs view
@@ -17,5 +17,3 @@  module Control.Monad.Instances {-# DEPRECATED "This module now contains no instances and will be removed in the future" #-} -- deprecated in 7.8     (Functor(..),Monad(..)) where--import Prelude
Control/Monad/ST.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE Unsafe #-}+{-# LANGUAGE Trustworthy #-}  ----------------------------------------------------------------------------- -- |@@ -31,5 +31,5 @@         stToIO,     ) where -import Control.Monad.ST.Safe+import Control.Monad.ST.Imp 
Control/Monad/ST/Lazy.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE Unsafe #-}+{-# LANGUAGE Trustworthy #-}  ----------------------------------------------------------------------------- -- |@@ -30,5 +30,5 @@         stToIO,     ) where -import Control.Monad.ST.Lazy.Safe+import Control.Monad.ST.Lazy.Imp 
Control/Monad/ST/Lazy/Imp.hs view
@@ -36,11 +36,9 @@         unsafeIOToST     ) where -import Prelude- import Control.Monad.Fix -import qualified Control.Monad.ST.Safe as ST+import qualified Control.Monad.ST as ST import qualified Control.Monad.ST.Unsafe as ST  import qualified GHC.ST as GHC.ST@@ -66,11 +64,15 @@  instance Functor (ST s) where     fmap f m = ST $ \ s ->-      let +      let        ST m_a = m        (r,new_s) = m_a s       in       (f r,new_s)++instance Applicative (ST s) where+    pure = return+    (<*>) = ap  instance Monad (ST s) where 
Control/Monad/ST/Lazy/Safe.hs view
@@ -18,7 +18,7 @@ -- ----------------------------------------------------------------------------- -module Control.Monad.ST.Lazy.Safe (+module Control.Monad.ST.Lazy.Safe {-# DEPRECATED "Safe is now the default, please use Control.Monad.ST.Lazy instead" #-} (         -- * The 'ST' monad         ST,         runST,
Control/Monad/ST/Safe.hs view
@@ -18,7 +18,7 @@ -- ----------------------------------------------------------------------------- -module Control.Monad.ST.Safe (+module Control.Monad.ST.Safe {-# DEPRECATED "Safe is now the default, please use Control.Monad.ST instead" #-} (         -- * The 'ST' Monad         ST,             -- abstract         runST,
Control/Monad/ST/Strict.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE Safe #-}+ ----------------------------------------------------------------------------- -- | -- Module      :  Control.Monad.ST.Strict
Control/Monad/Zip.hs view
@@ -17,7 +17,6 @@  module Control.Monad.Zip where -import Prelude import Control.Monad (liftM)  -- | `MonadZip` type class. Minimal definition: `mzip` or `mzipWith`@@ -35,6 +34,7 @@ --   > munzip (mzip ma mb) = (ma, mb) -- class Monad m => MonadZip m where+    {-# MINIMAL mzip | mzipWith #-}      mzip :: m a -> m b -> m (a,b)     mzip = mzipWith (,)@@ -47,7 +47,6 @@     -- munzip is a member of the class because sometimes     -- you can implement it more efficiently than the     -- above default code.  See Trac #4370 comment by giorgidze-    {-# MINIMAL mzip | mzipWith #-}  instance MonadZip [] where     mzip     = zip
+ Data/Bifunctor.hs view
@@ -0,0 +1,101 @@+{-# LANGUAGE Safe #-}+{-# LANGUAGE CPP #-}++-----------------------------------------------------------------------------+-- |+-- Module      :  Data.Bifunctor+-- Copyright   :  (C) 2008-2014 Edward Kmett,+-- License     :  BSD-style (see the file LICENSE)+--+-- Maintainer  :  libraries@haskell.org+-- Stability   :  provisional+-- Portability :  portable+--+-- @since 4.8.0.0+----------------------------------------------------------------------------+module Data.Bifunctor+  ( Bifunctor(..)+  ) where++import Control.Applicative  ( Const(..) )++-- | Formally, the class 'Bifunctor' represents a bifunctor+-- from @Hask@ -> @Hask@.+--+-- Intuitively it is a bifunctor where both the first and second+-- arguments are covariant.+--+-- You can define a 'Bifunctor' by either defining 'bimap' or by+-- defining both 'first' and 'second'.+--+-- If you supply 'bimap', you should ensure that:+--+-- @'bimap' 'id' 'id' ≡ 'id'@+--+-- If you supply 'first' and 'second', ensure:+--+-- @+-- 'first' 'id' ≡ 'id'+-- 'second' 'id' ≡ 'id'+-- @+--+-- If you supply both, you should also ensure:+--+-- @'bimap' f g ≡ 'first' f '.' 'second' g@+--+-- These ensure by parametricity:+--+-- @+-- 'bimap'  (f '.' g) (h '.' i) ≡ 'bimap' f h '.' 'bimap' g i+-- 'first'  (f '.' g) ≡ 'first'  f '.' 'first'  g+-- 'second' (f '.' g) ≡ 'second' f '.' 'second' g+-- @+--+-- @since 4.8.0.0+class Bifunctor p where+    {-# MINIMAL bimap | first, second #-}++    -- | Map over both arguments at the same time.+    --+    -- @'bimap' f g ≡ 'first' f '.' 'second' g@+    bimap :: (a -> b) -> (c -> d) -> p a c -> p b d+    bimap f g = first f . second g++    -- | Map covariantly over the first argument.+    --+    -- @'first' f ≡ 'bimap' f 'id'@+    first :: (a -> b) -> p a c -> p b c+    first f = bimap f id++    -- | Map covariantly over the second argument.+    --+    -- @'second' ≡ 'bimap' 'id'@+    second :: (b -> c) -> p a b -> p a c+    second = bimap id+++instance Bifunctor (,) where+    bimap f g ~(a, b) = (f a, g b)++instance Bifunctor ((,,) x1) where+    bimap f g ~(x1, a, b) = (x1, f a, g b)++instance Bifunctor ((,,,) x1 x2) where+    bimap f g ~(x1, x2, a, b) = (x1, x2, f a, g b)++instance Bifunctor ((,,,,) x1 x2 x3) where+    bimap f g ~(x1, x2, x3, a, b) = (x1, x2, x3, f a, g b)++instance Bifunctor ((,,,,,) x1 x2 x3 x4) where+    bimap f g ~(x1, x2, x3, x4, a, b) = (x1, x2, x3, x4, f a, g b)++instance Bifunctor ((,,,,,,) x1 x2 x3 x4 x5) where+    bimap f g ~(x1, x2, x3, x4, x5, a, b) = (x1, x2, x3, x4, x5, f a, g b)+++instance Bifunctor Either where+    bimap f _ (Left a) = Left (f a)+    bimap _ g (Right b) = Right (g b)++instance Bifunctor Const where+    bimap f _ (Const a) = Const (f a)
Data/Bits.hs view
@@ -39,11 +39,16 @@     rotateL, rotateR,     popCount   ),-  FiniteBits(finiteBitSize),+  FiniteBits(+    finiteBitSize,+    countLeadingZeros,+    countTrailingZeros+  ),    bitDefault,   testBitDefault,-  popCountDefault+  popCountDefault,+  toIntegralSized  ) where  -- Defines the @Bits@ class containing bit-based operations.@@ -52,11 +57,20 @@  #include "MachDeps.h" +#ifdef MIN_VERSION_integer_gmp+# define HAVE_INTEGER_GMP1 MIN_VERSION_integer_gmp(1,0,0)+#endif+ import Data.Maybe import GHC.Enum import GHC.Num import GHC.Base+import GHC.Real +#if HAVE_INTEGER_GMP1+import GHC.Integer.GMP.Internals (bitInteger, popCountInteger)+#endif+ infixl 8 `shift`, `rotate`, `shiftL`, `shiftR`, `rotateL`, `rotateR` infixl 7 .&. infixl 6 `xor`@@ -64,19 +78,16 @@  {-# DEPRECATED bitSize "Use 'bitSizeMaybe' or 'finiteBitSize' instead" #-} -- deprecated in 7.8 -{-|-The 'Bits' class defines bitwise operations over integral types.--* Bits are numbered from 0 with bit 0 being the least-  significant bit.--Minimal complete definition: '.&.', '.|.', 'xor', 'complement',-('shift' or ('shiftL' and 'shiftR')), ('rotate' or ('rotateL' and 'rotateR')),-'bitSize', 'isSigned', 'testBit', 'bit', and 'popCount'.  The latter three can-be implemented using `testBitDefault', 'bitDefault', and 'popCountDefault', if-@a@ is also an instance of 'Num'.--}+-- | The 'Bits' class defines bitwise operations over integral types.+--+-- * Bits are numbered from 0 with bit 0 being the least+--   significant bit. class Eq a => Bits a where+    {-# MINIMAL (.&.), (.|.), xor, complement,+                (shift | (shiftL, shiftR)),+                (rotate | (rotateL, rotateR)),+                bitSize, bitSizeMaybe, isSigned, testBit, bit, popCount #-}+     -- | Bitwise \"and\"     (.&.) :: a -> a -> a @@ -145,12 +156,15 @@     -- implementation (which ought to be equivalent to 'zeroBits' for     -- types which possess a 0th bit).     ---    -- /Since: 4.7.0.0/+    -- @since 4.7.0.0     zeroBits :: a     zeroBits = clearBit (bit 0) 0      -- | @bit /i/@ is a value with the @/i/@th bit set and all other bits clear.     --+    -- Can be implemented using `bitDefault' if @a@ is also an+    -- instance of 'Num'.+    --     -- See also 'zeroBits'.     bit               :: Int -> a @@ -164,13 +178,16 @@     complementBit     :: a -> Int -> a      -- | Return 'True' if the @n@th bit of the argument is 1+    --+    -- Can be implemented using `testBitDefault' if @a@ is also an+    -- instance of 'Num'.     testBit           :: a -> Int -> Bool      {-| Return the number of bits in the type of the argument.  The actual         value of the argument is ignored.  Returns Nothing         for types that do not have a fixed bitsize, like 'Integer'. -        /Since: 4.7.0.0/+        @since 4.7.0.0         -}     bitSizeMaybe      :: a -> Maybe Int @@ -207,7 +224,7 @@          Defaults to 'shiftL' unless defined explicitly by an instance. -        /Since: 4.5.0.0/ -}+        @since 4.5.0.0 -}     unsafeShiftL            :: a -> Int -> a     {-# INLINE unsafeShiftL #-}     x `unsafeShiftL` i = x `shiftL` i@@ -236,7 +253,7 @@          Defaults to 'shiftR' unless defined explicitly by an instance. -        /Since: 4.5.0.0/ -}+        @since 4.5.0.0 -}     unsafeShiftR            :: a -> Int -> a     {-# INLINE unsafeShiftR #-}     x `unsafeShiftR` i = x `shiftR` i@@ -264,17 +281,15 @@     {-| Return the number of set bits in the argument.  This number is         known as the population count or the Hamming weight. -        /Since: 4.5.0.0/ -}-    popCount          :: a -> Int+        Can be implemented using `popCountDefault' if @a@ is also an+        instance of 'Num'. -    {-# MINIMAL (.&.), (.|.), xor, complement,-                (shift | (shiftL, shiftR)),-                (rotate | (rotateL, rotateR)),-                bitSize, bitSizeMaybe, isSigned, testBit, bit, popCount #-}+        @since 4.5.0.0 -}+    popCount          :: a -> Int  -- |The 'FiniteBits' class denotes types with a finite, fixed number of bits. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 class Bits b => FiniteBits b where     -- | Return the number of bits in the type of the argument.     -- The actual value of the argument is ignored. Moreover, 'finiteBitSize'@@ -285,9 +300,67 @@     -- 'bitSizeMaybe' = 'Just' . 'finiteBitSize'     -- @     ---    -- /Since: 4.7.0.0/+    -- @since 4.7.0.0     finiteBitSize :: b -> Int +    -- | Count number of zero bits preceding the most significant set bit.+    --+    -- @+    -- 'countLeadingZeros' ('zeroBits' :: a) = finiteBitSize ('zeroBits' :: a)+    -- @+    --+    -- 'countLeadingZeros' can be used to compute log base 2 via+    --+    -- @+    -- logBase2 x = 'finiteBitSize' x - 1 - 'countLeadingZeros' x+    -- @+    --+    -- Note: The default implementation for this method is intentionally+    -- naive. However, the instances provided for the primitive+    -- integral types are implemented using CPU specific machine+    -- instructions.+    --+    -- @since 4.8.0.0+    countLeadingZeros :: b -> Int+    countLeadingZeros x = (w-1) - go (w-1)+      where+        go i | i < 0       = i -- no bit set+             | testBit x i = i+             | otherwise   = go (i-1)++        w = finiteBitSize x++    -- | Count number of zero bits following the least significant set bit.+    --+    -- @+    -- 'countTrailingZeros' ('zeroBits' :: a) = finiteBitSize ('zeroBits' :: a)+    -- 'countTrailingZeros' . 'negate' = 'countTrailingZeros'+    -- @+    --+    -- The related+    -- <http://en.wikipedia.org/wiki/Find_first_set find-first-set operation>+    -- can be expressed in terms of 'countTrailingZeros' as follows+    --+    -- @+    -- findFirstSet x = 1 + 'countTrailingZeros' x+    -- @+    --+    -- Note: The default implementation for this method is intentionally+    -- naive. However, the instances provided for the primitive+    -- integral types are implemented using CPU specific machine+    -- instructions.+    --+    -- @since 4.8.0.0+    countTrailingZeros :: b -> Int+    countTrailingZeros x = go 0+      where+        go i | i >= w      = i+             | testBit x i = i+             | otherwise   = go (i+1)++        w = finiteBitSize x++ -- The defaults below are written with lambdas so that e.g. --     bit = bitDefault -- is fully applied, so inlining will happen@@ -296,7 +369,7 @@ -- -- Note that: @bitDefault i = 1 `shiftL` i@ ----- /Since: 4.6.0.0/+-- @since 4.6.0.0 bitDefault :: (Bits a, Num a) => Int -> a bitDefault = \i -> 1 `shiftL` i {-# INLINE bitDefault #-}@@ -305,7 +378,7 @@ -- -- Note that: @testBitDefault x i = (x .&. bit i) /= 0@ ----- /Since: 4.6.0.0/+-- @since 4.6.0.0 testBitDefault ::  (Bits a, Num a) => a -> Int -> Bool testBitDefault = \x i -> (x .&. bit i) /= 0 {-# INLINE testBitDefault #-}@@ -315,7 +388,7 @@ -- This implementation is intentionally naive. Instances are expected to provide -- an optimized implementation for their size. ----- /Since: 4.6.0.0/+-- @since 4.6.0.0 popCountDefault :: (Bits a, Num a) => a -> Int popCountDefault = go 0  where@@ -324,7 +397,7 @@ {-# INLINABLE popCountDefault #-}  --- Interpret 'Bool' as 1-bit bit-field; /Since: 4.7.0.0/+-- Interpret 'Bool' as 1-bit bit-field; @since 4.7.0.0 instance Bits Bool where     (.&.) = (&&) @@ -356,7 +429,8 @@  instance FiniteBits Bool where     finiteBitSize _ = 1-+    countTrailingZeros x = if x then 0 else 1+    countLeadingZeros  x = if x then 0 else 1  instance Bits Int where     {-# INLINE shift #-}@@ -381,7 +455,7 @@     (I# x#) `shiftR` (I# i#)       = I# (x# `iShiftRA#` i#)     (I# x#) `unsafeShiftR` (I# i#) = I# (x# `uncheckedIShiftRA#` i#) -    {-# INLINE rotate #-} 	-- See Note [Constant folding for rotate]+    {-# INLINE rotate #-}       -- See Note [Constant folding for rotate]     (I# x#) `rotate` (I# i#) =         I# ((x# `uncheckedIShiftL#` i'#) `orI#` (x# `uncheckedIShiftRL#` (wsib -# i'#)))       where@@ -396,6 +470,8 @@  instance FiniteBits Int where     finiteBitSize _ = WORD_SIZE_IN_BITS+    countLeadingZeros  (I# x#) = I# (word2Int# (clz# (int2Word# x#)))+    countTrailingZeros (I# x#) = I# (word2Int# (ctz# (int2Word# x#)))  instance Bits Word where     {-# INLINE shift #-}@@ -429,6 +505,8 @@  instance FiniteBits Word where     finiteBitSize _ = WORD_SIZE_IN_BITS+    countLeadingZeros  (W# x#) = I# (word2Int# (clz# x#))+    countTrailingZeros (W# x#) = I# (word2Int# (ctz# x#))  instance Bits Integer where    (.&.) = andInteger@@ -437,11 +515,20 @@    complement = complementInteger    shift x i@(I# i#) | i >= 0    = shiftLInteger x i#                      | otherwise = shiftRInteger x (negateInt# i#)+   shiftL x (I# i#) = shiftLInteger x i#+   shiftR x (I# i#) = shiftRInteger x i#+    testBit x (I# i) = testBitInteger x i     zeroBits   = 0++#if HAVE_INTEGER_GMP1+   bit (I# i#) = bitInteger i#+   popCount x  = I# (popCountInteger x)+#else    bit        = bitDefault    popCount   = popCountDefault+#endif     rotate x i = shift x i   -- since an Integer never wraps around @@ -449,8 +536,84 @@    bitSize _  = error "Data.Bits.bitSize(Integer)"    isSigned _ = True -{- 	Note [Constant folding for rotate]-	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+-----------------------------------------------------------------------------++-- | Attempt to convert an 'Integral' type @a@ to an 'Integral' type @b@ using+-- the size of the types as measured by 'Bits' methods.+--+-- A simpler version of this function is:+--+-- > toIntegral :: (Integral a, Integral b) => a -> Maybe b+-- > toIntegral x+-- >   | toInteger x == y = Just (fromInteger y)+-- >   | otherwise        = Nothing+-- >   where+-- >     y = toInteger x+--+-- This version requires going through 'Integer', which can be inefficient.+-- However, @toIntegralSized@ is optimized to allow GHC to statically determine+-- the relative type sizes (as measured by 'bitSizeMaybe' and 'isSigned') and+-- avoid going through 'Integer' for many types. (The implementation uses+-- 'fromIntegral', which is itself optimized with rules for @base@ types but may+-- go through 'Integer' for some type pairs.)+--+-- @since 4.8.0.0++toIntegralSized :: (Integral a, Integral b, Bits a, Bits b) => a -> Maybe b+toIntegralSized x                 -- See Note [toIntegralSized optimization]+  | maybe True (<= x) yMinBound+  , maybe True (x <=) yMaxBound = Just y+  | otherwise                   = Nothing+  where+    y = fromIntegral x++    xWidth = bitSizeMaybe x+    yWidth = bitSizeMaybe y++    yMinBound+      | isBitSubType x y = Nothing+      | isSigned x, not (isSigned y) = Just 0+      | isSigned x, isSigned y+      , Just yW <- yWidth = Just (negate $ bit (yW-1)) -- Assumes sub-type+      | otherwise = Nothing++    yMaxBound+      | isBitSubType x y = Nothing+      | isSigned x, not (isSigned y)+      , Just xW <- xWidth, Just yW <- yWidth+      , xW <= yW+1 = Nothing -- Max bound beyond a's domain+      | Just yW <- yWidth = if isSigned y+                            then Just (bit (yW-1)-1)+                            else Just (bit yW-1)+      | otherwise = Nothing+{-# INLINEABLE toIntegralSized #-}++-- | 'True' if the size of @a@ is @<=@ the size of @b@, where size is measured+-- by 'bitSizeMaybe' and 'isSigned'.+isBitSubType :: (Bits a, Bits b) => a -> b -> Bool+isBitSubType x y+  -- Reflexive+  | xWidth == yWidth, xSigned == ySigned = True++  -- Every integer is a subset of 'Integer'+  | ySigned, Nothing == yWidth                  = True+  | not xSigned, not ySigned, Nothing == yWidth = True++  -- Sub-type relations between fixed-with types+  | xSigned == ySigned,   Just xW <- xWidth, Just yW <- yWidth = xW <= yW+  | not xSigned, ySigned, Just xW <- xWidth, Just yW <- yWidth = xW <  yW++  | otherwise = False+  where+    xWidth  = bitSizeMaybe x+    xSigned = isSigned     x++    yWidth  = bitSizeMaybe y+    ySigned = isSigned     y+{-# INLINE isBitSubType #-}++{-      Note [Constant folding for rotate]+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The INLINE on the Int instance of rotate enables it to be constant folded.  For example:      sumU . mapU (`rotate` 3) . replicateU 10000000 $ (7 :: Int)@@ -474,3 +637,27 @@          } -} +-- Note [toIntegralSized optimization]+-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+-- The code in 'toIntegralSized' relies on GHC optimizing away statically+-- decidable branches.+--+-- If both integral types are statically known, GHC will be able optimize the+-- code significantly (for @-O1@ and better).+--+-- For instance (as of GHC 7.8.1) the following definitions:+--+-- > w16_to_i32 = toIntegralSized :: Word16 -> Maybe Int32+-- >+-- > i16_to_w16 = toIntegralSized :: Int16 -> Maybe Word16+--+-- are translated into the following (simplified) /GHC Core/ language:+--+-- > w16_to_i32 = \x -> Just (case x of _ { W16# x# -> I32# (word2Int# x#) })+-- >+-- > i16_to_w16 = \x -> case eta of _+-- >   { I16# b1 -> case tagToEnum# (<=# 0 b1) of _+-- >       { False -> Nothing+-- >       ; True -> Just (W16# (narrow16Word# (int2Word# b1)))+-- >       }+-- >   }
Data/Bool.hs view
@@ -6,7 +6,7 @@ -- Module      :  Data.Bool -- Copyright   :  (c) The University of Glasgow 2001 -- License     :  BSD-style (see the file libraries/base/LICENSE)--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  experimental -- Portability :  portable@@ -18,7 +18,7 @@ module Data.Bool (    -- * Booleans    Bool(..),-   -- ** Operations +   -- ** Operations    (&&),    (||),    not,@@ -28,11 +28,34 @@  import GHC.Base --- | Case analysis for the 'Bool' type.--- @bool a b p@ evaluates to @a@ when @p@ is @False@, and evaluates to @b@--- when @p@ is @True@.+-- | Case analysis for the 'Bool' type. @'bool' x y p@ evaluates to @x@+-- when @p@ is 'False', and evaluates to @y@ when @p@ is 'True'. ----- /Since: 4.7.0.0/+-- This is equivalent to @if p then y else x@; that is, one can+-- think of it as an if-then-else construct with its arguments+-- reordered.+--+-- @since 4.7.0.0+--+-- ==== __Examples__+--+-- Basic usage:+--+-- >>> bool "foo" "bar" True+-- "bar"+-- >>> bool "foo" "bar" False+-- "foo"+--+-- Confirm that @'bool' x y p@ and @if p then y else x@ are+-- equivalent:+--+-- >>> let p = True; x = "bar"; y = "foo"+-- >>> bool x y p == if p then y else x+-- True+-- >>> let p = False+-- >>> bool x y p == if p then y else x+-- True+-- bool :: a -> a -> Bool -> a bool f _ False = f bool _ t True  = t
Data/Char.hs view
@@ -62,20 +62,104 @@ import GHC.Num import GHC.Enum --- | Convert a single digit 'Char' to the corresponding 'Int'.  --- This function fails unless its argument satisfies 'isHexDigit',--- but recognises both upper and lower-case hexadecimal digits--- (i.e. @\'0\'@..@\'9\'@, @\'a\'@..@\'f\'@, @\'A\'@..@\'F\'@).+-- $setup+-- Allow the use of Prelude in doctests.+-- >>> import Prelude++-- | Convert a single digit 'Char' to the corresponding 'Int'.  This+-- function fails unless its argument satisfies 'isHexDigit', but+-- recognises both upper- and lower-case hexadecimal digits (that+-- is, @\'0\'@..@\'9\'@, @\'a\'@..@\'f\'@, @\'A\'@..@\'F\'@).+--+-- ==== __Examples__+--+-- Characters @\'0\'@ through @\'9\'@ are converted properly to+-- @0..9@:+--+-- >>> map digitToInt ['0'..'9']+-- [0,1,2,3,4,5,6,7,8,9]+--+-- Both upper- and lower-case @\'A\'@ through @\'F\'@ are converted+-- as well, to @10..15@.+--+-- >>> map digitToInt ['a'..'f']+-- [10,11,12,13,14,15]+-- >>> map digitToInt ['A'..'F']+-- [10,11,12,13,14,15]+--+-- Anything else throws an exception:+--+-- >>> digitToInt 'G'+-- *** Exception: Char.digitToInt: not a digit 'G'+-- >>> digitToInt '♥'+-- *** Exception: Char.digitToInt: not a digit '\9829'+-- digitToInt :: Char -> Int digitToInt c- | 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---- | Unicode General Categories (column 2 of the UnicodeData table)--- in the order they are listed in the Unicode standard.+  | (fromIntegral dec::Word) <= 9 = dec+  | (fromIntegral hexl::Word) <= 5 = hexl + 10+  | (fromIntegral hexu::Word) <= 5 = hexu + 10+  | otherwise = error ("Char.digitToInt: not a digit " ++ show c) -- sigh+  where+    dec = ord c - ord '0'+    hexl = ord c - ord 'a'+    hexu = ord c - ord 'A' +-- | Unicode General Categories (column 2 of the UnicodeData table) in+-- the order they are listed in the Unicode standard (the Unicode+-- Character Database, in particular).+--+-- ==== __Examples__+--+-- Basic usage:+--+-- >>> :t OtherLetter+-- OtherLetter :: GeneralCategory+--+-- 'Eq' instance:+--+-- >>> UppercaseLetter == UppercaseLetter+-- True+-- >>> UppercaseLetter == LowercaseLetter+-- False+--+-- 'Ord' instance:+--+-- >>> NonSpacingMark <= MathSymbol+-- True+--+-- 'Enum' instance:+--+-- >>> enumFromTo ModifierLetter SpacingCombiningMark+-- [ModifierLetter,OtherLetter,NonSpacingMark,SpacingCombiningMark]+--+-- 'Read' instance:+--+-- >>> read "DashPunctuation" :: GeneralCategory+-- DashPunctuation+-- >>> read "17" :: GeneralCategory+-- *** Exception: Prelude.read: no parse+--+-- 'Show' instance:+--+-- >>> show EnclosingMark+-- "EnclosingMark"+--+-- 'Bounded' instance:+--+-- >>> minBound :: GeneralCategory+-- UppercaseLetter+-- >>> maxBound :: GeneralCategory+-- NotAssigned+--+-- 'Ix' instance:+--+--  >>> import Data.Ix ( index )+--  >>> index (OtherLetter,Control) FinalQuote+--  12+--  >>> index (OtherLetter,Control) Format+--  *** Exception: Error in array index+-- data GeneralCategory         = UppercaseLetter       -- ^ Lu: Letter, Uppercase         | LowercaseLetter       -- ^ Ll: Letter, Lowercase@@ -109,15 +193,79 @@         | NotAssigned           -- ^ Cn: Other, Not Assigned         deriving (Eq, Ord, Enum, Read, Show, Bounded, Ix) --- | The Unicode general category of the character.+-- | The Unicode general category of the character. This relies on the+-- 'Enum' instance of 'GeneralCategory', which must remain in the+-- same order as the categories are presented in the Unicode+-- standard.+--+-- ==== __Examples__+--+-- Basic usage:+--+-- >>> generalCategory 'a'+-- LowercaseLetter+-- >>> generalCategory 'A'+-- UppercaseLetter+-- >>> generalCategory '0'+-- DecimalNumber+-- >>> generalCategory '%'+-- OtherPunctuation+-- >>> generalCategory '♥'+-- OtherSymbol+-- >>> generalCategory '\31'+-- Control+-- >>> generalCategory ' '+-- Space+-- generalCategory :: Char -> GeneralCategory generalCategory c = toEnum $ fromIntegral $ wgencat $ fromIntegral $ ord c  -- derived character classifiers  -- | Selects alphabetic Unicode characters (lower-case, upper-case and--- title-case letters, plus letters of caseless scripts and modifiers letters).--- This function is equivalent to 'Data.Char.isAlpha'.+-- title-case letters, plus letters of caseless scripts and+-- modifiers letters). This function is equivalent to+-- 'Data.Char.isAlpha'.+--+-- This function returns 'True' if its argument has one of the+-- following 'GeneralCategory's, or 'False' otherwise:+--+-- * 'UppercaseLetter'+-- * 'LowercaseLetter'+-- * 'TitlecaseLetter'+-- * 'ModifierLetter'+-- * 'OtherLetter'+--+-- These classes are defined in the+-- <http://www.unicode.org/reports/tr44/tr44-14.html#GC_Values_Table Unicode Character Database>,+-- part of the Unicode standard. The same document defines what is+-- and is not a \"Letter\".+--+-- ==== __Examples__+--+-- Basic usage:+--+-- >>> isLetter 'a'+-- True+-- >>> isLetter 'A'+-- True+-- >>> isLetter '0'+-- False+-- >>> isLetter '%'+-- False+-- >>> isLetter '♥'+-- False+-- >>> isLetter '\31'+-- False+--+-- Ensure that 'isLetter' and 'isAlpha' are equivalent.+--+-- >>> let chars = [(chr 0)..]+-- >>> let letters = map isLetter chars+-- >>> let alphas = map isAlpha chars+-- >>> letters == alphas+-- True+-- isLetter :: Char -> Bool isLetter c = case generalCategory c of         UppercaseLetter         -> True@@ -127,8 +275,41 @@         OtherLetter             -> True         _                       -> False --- | Selects Unicode mark characters, e.g. accents and the like, which--- combine with preceding letters.+-- | Selects Unicode mark characters, for example accents and the+-- like, which combine with preceding characters.+--+-- This function returns 'True' if its argument has one of the+-- following 'GeneralCategory's, or 'False' otherwise:+--+-- * 'NonSpacingMark'+-- * 'SpacingCombiningMark'+-- * 'EnclosingMark'+--+-- These classes are defined in the+-- <http://www.unicode.org/reports/tr44/tr44-14.html#GC_Values_Table Unicode Character Database>,+-- part of the Unicode standard. The same document defines what is+-- and is not a \"Mark\".+--+-- ==== __Examples__+--+-- Basic usage:+--+-- >>> isMark 'a'+-- False+-- >>> isMark '0'+-- False+--+-- Combining marks such as accent characters usually need to follow+-- another character before they become printable:+--+-- >>> map isMark "ò"+-- [False,True]+--+-- Puns are not necessarily supported:+--+-- >>> isMark '✓'+-- False+-- isMark :: Char -> Bool isMark c = case generalCategory c of         NonSpacingMark          -> True@@ -137,7 +318,41 @@         _                       -> False  -- | Selects Unicode numeric characters, including digits from various--- scripts, Roman numerals, etc.+-- scripts, Roman numerals, et cetera.+--+-- This function returns 'True' if its argument has one of the+-- following 'GeneralCategory's, or 'False' otherwise:+--+-- * 'DecimalNumber'+-- * 'LetterNumber'+-- * 'OtherNumber'+--+-- These classes are defined in the+-- <http://www.unicode.org/reports/tr44/tr44-14.html#GC_Values_Table Unicode Character Database>,+-- part of the Unicode standard. The same document defines what is+-- and is not a \"Number\".+--+-- ==== __Examples__+--+-- Basic usage:+--+-- >>> isNumber 'a'+-- False+-- >>> isNumber '%'+-- False+-- >>> isNumber '3'+-- True+--+-- ASCII @\'0\'@ through @\'9\'@ are all numbers:+--+-- >>> and $ map isNumber ['0'..'9']+-- True+--+-- Unicode Roman numerals are \"numbers\" as well:+--+-- >>> isNumber 'Ⅸ'+-- True+-- isNumber :: Char -> Bool isNumber c = case generalCategory c of         DecimalNumber           -> True@@ -147,6 +362,40 @@  -- | Selects Unicode punctuation characters, including various kinds -- of connectors, brackets and quotes.+--+-- This function returns 'True' if its argument has one of the+-- following 'GeneralCategory's, or 'False' otherwise:+--+-- * 'ConnectorPunctuation'+-- * 'DashPunctuation'+-- * 'OpenPunctuation'+-- * 'ClosePunctuation'+-- * 'InitialQuote'+-- * 'FinalQuote'+-- * 'OtherPunctuation'+--+-- These classes are defined in the+-- <http://www.unicode.org/reports/tr44/tr44-14.html#GC_Values_Table Unicode Character Database>,+-- part of the Unicode standard. The same document defines what is+-- and is not a \"Punctuation\".+--+-- ==== __Examples__+--+-- Basic usage:+--+-- >>> isPunctuation 'a'+-- False+-- >>> isPunctuation '7'+-- False+-- >>> isPunctuation '♥'+-- False+-- >>> isPunctuation '"'+-- True+-- >>> isPunctuation '?'+-- True+-- >>> isPunctuation '—'+-- True+-- isPunctuation :: Char -> Bool isPunctuation c = case generalCategory c of         ConnectorPunctuation    -> True@@ -160,6 +409,39 @@  -- | Selects Unicode symbol characters, including mathematical and -- currency symbols.+--+-- This function returns 'True' if its argument has one of the+-- following 'GeneralCategory's, or 'False' otherwise:+--+-- * 'MathSymbol'+-- * 'CurrencySymbol'+-- * 'ModifierSymbol'+-- * 'OtherSymbol'+--+-- These classes are defined in the+-- <http://www.unicode.org/reports/tr44/tr44-14.html#GC_Values_Table Unicode Character Database>,+-- part of the Unicode standard. The same document defines what is+-- and is not a \"Symbol\".+--+-- ==== __Examples__+--+-- Basic usage:+--+-- >>> isSymbol 'a'+-- False+-- >>> isSymbol '6'+-- False+-- >>> isSymbol '='+-- True+--+-- The definition of \"math symbol\" may be a little+-- counter-intuitive depending on one's background:+--+-- >>> isSymbol '+'+-- True+-- >>> isSymbol '-'+-- False+-- isSymbol :: Char -> Bool isSymbol c = case generalCategory c of         MathSymbol              -> True@@ -169,6 +451,43 @@         _                       -> False  -- | Selects Unicode space and separator characters.+--+-- This function returns 'True' if its argument has one of the+-- following 'GeneralCategory's, or 'False' otherwise:+--+-- * 'Space'+-- * 'LineSeparator'+-- * 'ParagraphSeparator'+--+-- These classes are defined in the+-- <http://www.unicode.org/reports/tr44/tr44-14.html#GC_Values_Table Unicode Character Database>,+-- part of the Unicode standard. The same document defines what is+-- and is not a \"Separator\".+--+-- ==== __Examples__+--+-- Basic usage:+--+-- >>> isSeparator 'a'+-- False+-- >>> isSeparator '6'+-- False+-- >>> isSeparator ' '+-- True+--+-- Warning: newlines and tab characters are not considered+-- separators.+--+-- >>> isSeparator '\n'+-- False+-- >>> isSeparator '\t'+-- False+--+-- But some more exotic characters are (like HTML's @&nbsp;@):+--+-- >>> isSeparator '\160'+-- True+-- isSeparator :: Char -> Bool isSeparator c = case generalCategory c of         Space                   -> True
Data/Coerce.hs view
@@ -1,6 +1,5 @@ {-# LANGUAGE Unsafe #-}-{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE StandaloneDeriving #-}+{-# LANGUAGE NoImplicitPrelude #-}  ----------------------------------------------------------------------------- -- |@@ -17,11 +16,15 @@ -- More in-depth information can be found on the -- <https://ghc.haskell.org/trac/ghc/wiki/Roles Roles wiki page> ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 -----------------------------------------------------------------------------  module Data.Coerce         ( -- * Safe coercions           coerce, Coercible,         ) where-import GHC.Prim (coerce, Coercible)+import GHC.Prim (coerce)+import GHC.Types (Coercible)++import GHC.Base () -- for build ordering+
Data/Complex.hs view
@@ -1,5 +1,5 @@ {-# LANGUAGE Trustworthy #-}-{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE AutoDeriveTypeable #-} {-# LANGUAGE StandaloneDeriving #-}  -----------------------------------------------------------------------------@@ -7,7 +7,7 @@ -- Module      :  Data.Complex -- Copyright   :  (c) The University of Glasgow 2001 -- License     :  BSD-style (see the file libraries/base/LICENSE)--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  provisional -- Portability :  portable@@ -34,10 +34,10 @@          )  where -import Prelude- import Data.Typeable import Data.Data (Data)+import Foreign (Storable, castPtr, peek, poke, pokeElemOff, peekElemOff, sizeOf,+                alignment)  infix  6  :+ @@ -58,27 +58,27 @@ -- Functions over Complex  -- | Extracts the real part of a complex number.-realPart :: (RealFloat a) => Complex a -> a+realPart :: Complex a -> a realPart (x :+ _) =  x  -- | Extracts the imaginary part of a complex number.-imagPart :: (RealFloat a) => Complex a -> a+imagPart :: Complex a -> a imagPart (_ :+ y) =  y  -- | The conjugate of a complex number. {-# SPECIALISE conjugate :: Complex Double -> Complex Double #-}-conjugate        :: (RealFloat a) => Complex a -> Complex a+conjugate        :: Num a => Complex a -> Complex a conjugate (x:+y) =  x :+ (-y)  -- | Form a complex number from polar components of magnitude and phase. {-# SPECIALISE mkPolar :: Double -> Double -> Complex Double #-}-mkPolar          :: (RealFloat a) => a -> a -> Complex a+mkPolar          :: Floating a => a -> a -> Complex a mkPolar r theta  =  r * cos theta :+ r * sin theta  -- | @'cis' t@ is a complex value with magnitude @1@ -- and phase @t@ (modulo @2*'pi'@). {-# SPECIALISE cis :: Double -> Complex Double #-}-cis              :: (RealFloat a) => a -> Complex a+cis              :: Floating a => a -> Complex a cis theta        =  cos theta :+ sin theta  -- | The function 'polar' takes a complex number and@@ -174,3 +174,15 @@     acosh z        =  log (z + (z+1) * sqrt ((z-1)/(z+1)))     atanh z        =  0.5 * log ((1.0+z) / (1.0-z)) +instance Storable a => Storable (Complex a) where+    sizeOf a       = 2 * sizeOf (realPart a)+    alignment a    = alignment (realPart a)+    peek p           = do+                        q <- return $ castPtr p+                        r <- peek q+                        i <- peekElemOff q 1+                        return (r :+ i)+    poke p (r :+ i)  = do+                        q <-return $  (castPtr p)+                        poke q r+                        pokeElemOff q 1 i
Data/Data.hs view
@@ -1,26 +1,26 @@-{-# LANGUAGE Trustworthy, FlexibleInstances #-}-{-# LANGUAGE RankNTypes, ScopedTypeVariables, PolyKinds #-}-{-# LANGUAGE StandaloneDeriving, DeriveDataTypeable, TypeOperators,-             GADTs #-}+{-# LANGUAGE Trustworthy #-}+{-# LANGUAGE RankNTypes, ScopedTypeVariables, PolyKinds, StandaloneDeriving,+             AutoDeriveTypeable, TypeOperators, GADTs, FlexibleInstances #-}+{-# LANGUAGE NoImplicitPrelude #-}  ----------------------------------------------------------------------------- -- | -- Module      :  Data.Data -- Copyright   :  (c) The University of Glasgow, CWI 2001--2004 -- License     :  BSD-style (see the file libraries/base/LICENSE)--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  experimental -- Portability :  non-portable (local universal quantification) ----- \"Scrap your boilerplate\" --- Generic programming in Haskell.--- See <http://www.cs.vu.nl/boilerplate/>. This module provides--- the 'Data' class with its primitives for generic programming, along--- with instances for many datatypes. It corresponds to a merge between--- the previous "Data.Generics.Basics" and almost all of --- "Data.Generics.Instances". The instances that are not present--- in this module were moved to the @Data.Generics.Instances@ module--- in the @syb@ package.+-- \"Scrap your boilerplate\" --- Generic programming in Haskell.  See+-- <http://www.haskell.org/haskellwiki/Research_papers/Generics#Scrap_your_boilerplate.21>.+-- This module provides the 'Data' class with its primitives for+-- generic programming, along with instances for many datatypes. It+-- corresponds to a merge between the previous "Data.Generics.Basics"+-- and almost all of "Data.Generics.Instances". The instances that are+-- not present in this module were moved to the+-- @Data.Generics.Instances@ module in the @syb@ package. -- -- For more information, please visit the new -- SYB wiki: <http://www.cs.uu.nl/wiki/bin/view/GenericProgramming/SYB>.@@ -40,7 +40,7 @@                 dataTypeOf,                 dataCast1,      -- mediate types and unary type constructors                 dataCast2,      -- mediate types and binary type constructors-                -- Generic maps defined in terms of gfoldl +                -- Generic maps defined in terms of gfoldl                 gmapT,                 gmapQ,                 gmapQl,@@ -106,20 +106,25 @@  ------------------------------------------------------------------------------ -import Prelude -- necessary to get dependencies right--import Data.Typeable+import Data.Either+import Data.Eq import Data.Maybe+import Data.Ord+import Data.Typeable import Data.Version( Version(..) )-import Control.Monad+import GHC.Base+import GHC.List+import GHC.Num+import GHC.Read+import GHC.Show+import Text.Read( reads )  -- Imports for the instances import Data.Int              -- So we can give Data instance for Int8, ... import Data.Type.Coercion import Data.Word             -- So we can give Data instance for Word8, ...-import GHC.Real( Ratio(..) ) -- So we can give Data instance for Ratio+import GHC.Real              -- So we can give Data instance for Ratio --import GHC.IOBase            -- So we can give Data instance for IO, Handle-import GHC.Prim import GHC.Ptr               -- So we can give Data instance for Ptr import GHC.ForeignPtr        -- So we can give Data instance for ForeignPtr --import GHC.Stable            -- So we can give Data instance for StablePtr@@ -323,7 +328,7 @@    -- | A generic query that processes the immediate subterms and returns a list   -- of results.  The list is given in the same order as originally specified-  -- in the declaratoin of the data constructors.+  -- in the declaration of the data constructors.   gmapQ :: (forall d. Data d => d -> u) -> a -> [u]   gmapQ f = gmapQr (:) [] f @@ -345,10 +350,10 @@   -- injection and projection using 'return' and '>>='.   gmapM :: forall m. Monad m => (forall d. Data d => d -> m d) -> a -> m a -  -- Use immediately the monad datatype constructor +  -- Use immediately the monad datatype constructor   -- to instantiate the type constructor c in the type of gfoldl,   -- so injection and projection is done by return and >>=.-  --  +  --   gmapM f = gfoldl k return     where       k :: Data d => m (d -> b) -> d -> m b@@ -385,8 +390,8 @@  {- -We use the same pairing trick as for gmapMp, -i.e., we use an extra Bool component to keep track of the +We use the same pairing trick as for gmapMp,+i.e., we use an extra Bool component to keep track of the fact whether an immediate subterm was processed successfully. However, we cut of mapping over subterms once a first subterm was transformed successfully.@@ -449,7 +454,7 @@  where   k :: forall b r. Data b => ID (b -> r) -> ID r   k c = ID (unID c f)- +   z :: forall r. r -> ID r   z = ID @@ -619,7 +624,7 @@   -- | Gets the field labels of a constructor.  The list of labels--- is returned in the same order as they were given in the original +-- is returned in the same order as they were given in the original -- constructor declaration. constrFields :: Constr -> [String] constrFields = confields@@ -634,7 +639,7 @@ ------------------------------------------------------------------------------ -- --      From strings to constr's and vice versa: all data types---      +-- ------------------------------------------------------------------------------  @@ -777,12 +782,12 @@  ------------------------------------------------------------------------------ -----      Non-representations for non-presentable types+--      Non-representations for non-representable types -- ------------------------------------------------------------------------------  --- | Constructs a non-representation for a non-presentable type+-- | Constructs a non-representation for a non-representable type mkNoRepType :: String -> DataType mkNoRepType str = DataType                         { tycon   = str@@ -1060,9 +1065,9 @@ ratioDataType = mkDataType "GHC.Real.Ratio" [ratioConstr]  instance (Data a, Integral a) => Data (Ratio a) where-  gfoldl k z (a :% b) = z (:%) `k` a `k` b+  gfoldl k z (a :% b) = z (%) `k` a `k` b   toConstr _ = ratioConstr-  gunfold k z c | constrIndex c == 1 = k (k (z (:%)))+  gunfold k z c | constrIndex c == 1 = k (k (z (%)))   gunfold _ _ _ = error "Data.Data.gunfold(Ratio)"   dataTypeOf _  = ratioDataType @@ -1313,7 +1318,7 @@   dataCast1 x  = gcast1 x  --------------------------------------------------------------------------------- The Data instance for Array preserves data abstraction at the cost of +-- The Data instance for Array preserves data abstraction at the cost of -- inefficiency. We omit reflection services for the sake of data abstraction. instance (Typeable a, Data a, Data b, Ix a) => Data (Array a b)  where
Data/Dynamic.hs view
@@ -1,6 +1,6 @@ {-# LANGUAGE Trustworthy #-} {-# LANGUAGE NoImplicitPrelude #-}-{-# LANGUAGE DeriveDataTypeable, StandaloneDeriving #-}+{-# LANGUAGE AutoDeriveTypeable, StandaloneDeriving #-}  ----------------------------------------------------------------------------- -- |
Data/Either.hs view
@@ -1,6 +1,6 @@ {-# LANGUAGE Trustworthy #-} {-# LANGUAGE NoImplicitPrelude #-}-{-# LANGUAGE DeriveDataTypeable, StandaloneDeriving #-}+{-# LANGUAGE AutoDeriveTypeable, StandaloneDeriving #-} {-# LANGUAGE PolyKinds, DataKinds, TypeFamilies, TypeOperators, UndecidableInstances #-}  -----------------------------------------------------------------------------@@ -34,6 +34,10 @@ import Data.Typeable import Data.Type.Equality +-- $setup+-- Allow the use of some Prelude functions in doctests.+-- >>> import Prelude ( (+), (*), length, putStrLn )+ {- -- just for testing import Test.QuickCheck@@ -48,6 +52,75 @@ either correct or an error; by convention, the 'Left' constructor is used to hold an error value and the 'Right' constructor is used to hold a correct value (mnemonic: \"right\" also means \"correct\").++==== __Examples__++The type @'Either' 'String' 'Int'@ is the type of values which can be either+a 'String' or an 'Int'. The 'Left' constructor can be used only on+'String's, and the 'Right' constructor can be used only on 'Int's:++>>> let s = Left "foo" :: Either String Int+>>> s+Left "foo"+>>> let n = Right 3 :: Either String Int+>>> n+Right 3+>>> :type s+s :: Either String Int+>>> :type n+n :: Either String Int++The 'fmap' from our 'Functor' instance will ignore 'Left' values, but+will apply the supplied function to values contained in a 'Right':++>>> let s = Left "foo" :: Either String Int+>>> let n = Right 3 :: Either String Int+>>> fmap (*2) s+Left "foo"+>>> fmap (*2) n+Right 6++The 'Monad' instance for 'Either' allows us to chain together multiple+actions which may fail, and fail overall if any of the individual+steps failed. First we'll write a function that can either parse an+'Int' from a 'Char', or fail.++>>> import Data.Char ( digitToInt, isDigit )+>>> :{+    let parseEither :: Char -> Either String Int+        parseEither c+          | isDigit c = Right (digitToInt c)+          | otherwise = Left "parse error"+>>> :}++The following should work, since both @\'1\'@ and @\'2\'@ can be+parsed as 'Int's.++>>> :{+    let parseMultiple :: Either String Int+        parseMultiple = do+          x <- parseEither '1'+          y <- parseEither '2'+          return (x + y)+>>> :}++>>> parseMultiple+Right 3++But the following should fail overall, since the first operation where+we attempt to parse @\'m\'@ as an 'Int' will fail:++>>> :{+    let parseMultiple :: Either String Int+        parseMultiple = do+          x <- parseEither 'm'+          y <- parseEither '2'+          return (x + y)+>>> :}++>>> parseMultiple+Left "parse error"+ -} data  Either a b  =  Left a | Right b   deriving (Eq, Ord, Read, Show, Typeable)@@ -56,6 +129,11 @@     fmap _ (Left x) = Left x     fmap f (Right y) = Right (f y) +instance Applicative (Either e) where+    pure          = Right+    Left  e <*> _ = Left e+    Right f <*> r = fmap f r+ instance Monad (Either e) where     return = Right     Left  l >>= _ = Left l@@ -64,27 +142,74 @@ -- | Case analysis for the 'Either' type. -- If the value is @'Left' a@, apply the first function to @a@; -- if it is @'Right' b@, apply the second function to @b@.+--+-- ==== __Examples__+--+-- We create two values of type @'Either' 'String' 'Int'@, one using the+-- 'Left' constructor and another using the 'Right' constructor. Then+-- we apply \"either\" the 'length' function (if we have a 'String')+-- or the \"times-two\" function (if we have an 'Int'):+--+-- >>> let s = Left "foo" :: Either String Int+-- >>> let n = Right 3 :: Either String Int+-- >>> either length (*2) s+-- 3+-- >>> either length (*2) n+-- 6+-- either                  :: (a -> c) -> (b -> c) -> Either a b -> c either f _ (Left x)     =  f x either _ g (Right y)    =  g y --- | Extracts from a list of 'Either' all the 'Left' elements--- All the 'Left' elements are extracted in order. +-- | Extracts from a list of 'Either' all the 'Left' elements.+-- All the 'Left' elements are extracted in order.+--+-- ==== __Examples__+--+-- Basic usage:+--+-- >>> let list = [ Left "foo", Right 3, Left "bar", Right 7, Left "baz" ]+-- >>> lefts list+-- ["foo","bar","baz"]+-- lefts   :: [Either a b] -> [a] lefts x = [a | Left a <- x] --- | Extracts from a list of 'Either' all the 'Right' elements+-- | Extracts from a list of 'Either' all the 'Right' elements. -- All the 'Right' elements are extracted in order.-+--+-- ==== __Examples__+--+-- Basic usage:+--+-- >>> let list = [ Left "foo", Right 3, Left "bar", Right 7, Left "baz" ]+-- >>> rights list+-- [3,7]+-- rights   :: [Either a b] -> [b] rights x = [a | Right a <- x] --- | Partitions a list of 'Either' into two lists+-- | Partitions a list of 'Either' into two lists. -- All the 'Left' elements are extracted, in order, to the first -- component of the output.  Similarly the 'Right' elements are extracted -- to the second component of the output.-+--+-- ==== __Examples__+--+-- Basic usage:+--+-- >>> let list = [ Left "foo", Right 3, Left "bar", Right 7, Left "baz" ]+-- >>> partitionEithers list+-- (["foo","bar","baz"],[3,7])+--+-- The pair returned by @'partitionEithers' x@ should be the same+-- pair as @('lefts' x, 'rights' x)@:+--+-- >>> let list = [ Left "foo", Right 3, Left "bar", Right 7, Left "baz" ]+-- >>> partitionEithers list == (lefts list, rights list)+-- True+-- partitionEithers :: [Either a b] -> ([a],[b]) partitionEithers = foldr (either left right) ([],[])  where@@ -93,23 +218,72 @@  -- | Return `True` if the given value is a `Left`-value, `False` otherwise. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0+--+-- ==== __Examples__+--+-- Basic usage:+--+-- >>> isLeft (Left "foo")+-- True+-- >>> isLeft (Right 3)+-- False+--+-- Assuming a 'Left' value signifies some sort of error, we can use+-- 'isLeft' to write a very simple error-reporting function that does+-- absolutely nothing in the case of success, and outputs \"ERROR\" if+-- any error occurred.+--+-- This example shows how 'isLeft' might be used to avoid pattern+-- matching when one does not care about the value contained in the+-- constructor:+--+-- >>> import Control.Monad ( when )+-- >>> let report e = when (isLeft e) $ putStrLn "ERROR"+-- >>> report (Right 1)+-- >>> report (Left "parse error")+-- ERROR+-- isLeft :: Either a b -> Bool isLeft (Left  _) = True isLeft (Right _) = False  -- | Return `True` if the given value is a `Right`-value, `False` otherwise. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0+--+-- ==== __Examples__+--+-- Basic usage:+--+-- >>> isRight (Left "foo")+-- False+-- >>> isRight (Right 3)+-- True+--+-- Assuming a 'Left' value signifies some sort of error, we can use+-- 'isRight' to write a very simple reporting function that only+-- outputs \"SUCCESS\" when a computation has succeeded.+--+-- This example shows how 'isRight' might be used to avoid pattern+-- matching when one does not care about the value contained in the+-- constructor:+--+-- >>> import Control.Monad ( when )+-- >>> let report e = when (isRight e) $ putStrLn "SUCCESS"+-- >>> report (Left "parse error")+-- >>> report (Right 1)+-- SUCCESS+-- isRight :: Either a b -> Bool isRight (Left  _) = False isRight (Right _) = True  -- instance for the == Boolean type-level equality operator type family EqEither a b where-  EqEither (Left x)  (Left y)  = x == y-  EqEither (Right x) (Right y) = x == y-  EqEither a         b         = False+  EqEither ('Left x)  ('Left y)  = x == y+  EqEither ('Right x) ('Right y) = x == y+  EqEither a         b           = 'False type instance a == b = EqEither a b  {-
Data/Fixed.hs view
@@ -1,14 +1,13 @@ {-# LANGUAGE Trustworthy #-} {-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE DeriveDataTypeable #-}-{-# OPTIONS -Wall -fno-warn-unused-binds #-}+{-# LANGUAGE AutoDeriveTypeable #-}  ----------------------------------------------------------------------------- -- | -- Module      :  Data.Fixed -- Copyright   :  (c) Ashley Yakeley 2005, 2006, 2009 -- License     :  BSD-style (see the file libraries/base/LICENSE)--- +-- -- Maintainer  :  Ashley Yakeley <ashley@semantic.org> -- Stability   :  experimental -- Portability :  portable@@ -37,8 +36,6 @@     E12,Pico ) where -import Prelude -- necessary to get dependencies right-import Data.Typeable import Data.Data import GHC.Read import Text.ParserCombinators.ReadPrec@@ -61,8 +58,8 @@     f = div' n d  -- | The type parameter should be an instance of 'HasResolution'.-newtype Fixed a = MkFixed Integer -- ^ /Since: 4.7.0.0/-        deriving (Eq,Ord,Typeable)+newtype Fixed a = MkFixed Integer -- ^ @since 4.7.0.0+        deriving (Eq,Ord)  -- We do this because the automatically derived Data instance requires (Data a) context. -- Our manual instance has the more general (Typeable a) context.@@ -146,7 +143,9 @@     -- enough digits to be unambiguous     digits = ceiling (logBase 10 (fromInteger res) :: Double)     maxnum = 10 ^ digits-    fracNum = div (d * maxnum) res+    -- read floors, so show must ceil for `read . show = id` to hold. See #9240+    fracNum = divCeil (d * maxnum) res+    divCeil x y = (x + y - 1) `div` y  instance (HasResolution a) => Show (Fixed a) where     show = showFixed False@@ -167,52 +166,44 @@           e = ceiling (logBase 10 (fromInteger r) :: Double) convertFixed _ = pfail -data E0 = E0-     deriving (Typeable)+data E0 instance HasResolution E0 where     resolution _ = 1 -- | resolution of 1, this works the same as Integer type Uni = Fixed E0 -data E1 = E1-     deriving (Typeable)+data E1 instance HasResolution E1 where     resolution _ = 10 -- | resolution of 10^-1 = .1 type Deci = Fixed E1 -data E2 = E2-     deriving (Typeable)+data E2 instance HasResolution E2 where     resolution _ = 100 -- | resolution of 10^-2 = .01, useful for many monetary currencies type Centi = Fixed E2 -data E3 = E3-     deriving (Typeable)+data E3 instance HasResolution E3 where     resolution _ = 1000 -- | resolution of 10^-3 = .001 type Milli = Fixed E3 -data E6 = E6-     deriving (Typeable)+data E6 instance HasResolution E6 where     resolution _ = 1000000 -- | resolution of 10^-6 = .000001 type Micro = Fixed E6 -data E9 = E9-     deriving (Typeable)+data E9 instance HasResolution E9 where     resolution _ = 1000000000 -- | resolution of 10^-9 = .000000001 type Nano = Fixed E9 -data E12 = E12-     deriving (Typeable)+data E12 instance HasResolution E12 where     resolution _ = 1000000000000 -- | resolution of 10^-12 = .000000000001 type Pico = Fixed E12-
Data/Foldable.hs view
@@ -1,4 +1,6 @@ {-# LANGUAGE Trustworthy #-}+{-# LANGUAGE NoImplicitPrelude #-}+{-# LANGUAGE ScopedTypeVariables #-}  ----------------------------------------------------------------------------- -- |@@ -12,12 +14,6 @@ -- -- Class of data structures that can be folded to a summary value. ----- Many of these functions generalize "Prelude", "Control.Monad" and--- "Data.List" functions of the same names from lists to any 'Foldable'--- functor.  To avoid ambiguity, either import those modules hiding--- these names or qualify uses of these function names with an alias--- for this module.--- -----------------------------------------------------------------------------  module Data.Foldable (@@ -38,43 +34,39 @@     sequence_,     msum,     -- ** Specialized folds-    toList,     concat,     concatMap,     and,     or,     any,     all,-    sum,-    product,-    maximum,     maximumBy,-    minimum,     minimumBy,     -- ** Searches-    elem,     notElem,     find     ) where -import Prelude hiding (foldl, foldr, foldl1, foldr1, mapM_, sequence_,-                elem, notElem, concat, concatMap, and, or, any, all,-                sum, product, maximum, minimum)-import qualified Prelude (foldl, foldr, foldl1, foldr1)-import qualified Data.List as List (foldl')-import Control.Applicative-import Control.Monad (MonadPlus(..))-import Data.Maybe (fromMaybe, listToMaybe)+import Data.Bool+import Data.Either+import Data.Eq+import qualified GHC.List as List+import Data.Maybe import Data.Monoid+import Data.Ord import Data.Proxy -import GHC.Exts (build)-import GHC.Arr+import GHC.Arr  ( Array(..), Ix(..), elems, numElements,+                  foldlElems, foldrElems,+                  foldlElems', foldrElems',+                  foldl1Elems, foldr1Elems)+import GHC.Base hiding ( foldr )+import GHC.Num  ( Num(..) ) +infix  4 `elem`, `notElem`+ -- | Data structures that can be folded. ----- Minimal complete definition: 'foldMap' or 'foldr'.--- -- For example, given a data type -- -- > data Tree a = Empty | Leaf a | Node (Tree a) a (Tree a)@@ -94,7 +86,32 @@ -- >    foldr f z (Leaf x) = f x z -- >    foldr f z (Node l k r) = foldr f (f k (foldr f z r)) l --+-- @Foldable@ instances are expected to satisfy the following laws:+--+-- > foldr f z t = appEndo (foldMap (Endo . f) t ) z+--+-- > foldl f z t = appEndo (getDual (foldMap (Dual . Endo . flip f) t)) z+--+-- > fold = foldMap id+--+-- @sum@, @product@, @maximum@, and @minimum@ should all be essentially+-- equivalent to @foldMap@ forms, such as+--+-- > sum = getSum . foldMap Sum+--+-- but may be less defined.+--+-- If the type is also a 'Functor' instance, it should satisfy+--+-- > foldMap f = fold . fmap f+--+-- which implies that+--+-- > foldMap f . fmap g = foldMap (f . g)+ class Foldable t where+    {-# MINIMAL foldMap | foldr #-}+     -- | Combine the elements of a structure using a monoid.     fold :: Monoid m => t m -> m     fold = foldMap id@@ -108,9 +125,9 @@     --     -- @'foldr' f z = 'Prelude.foldr' f z . 'toList'@     foldr :: (a -> b -> b) -> b -> t a -> b-    foldr f z t = appEndo (foldMap (Endo . f) t) z+    foldr f z t = appEndo (foldMap (Endo #. f) t) z -    -- | Right-associative fold of a structure, +    -- | Right-associative fold of a structure,     -- but with strict application of the operator.     foldr' :: (a -> b -> b) -> b -> t a -> b     foldr' f z0 xs = foldl f' id xs z0@@ -121,6 +138,8 @@     -- @'foldl' f z = 'Prelude.foldl' f z . 'toList'@     foldl :: (b -> a -> b) -> b -> t a -> b     foldl f z t = appEndo (getDual (foldMap (Dual . Endo . flip f) t)) z+    -- There's no point mucking around with coercions here,+    -- because flip forces us to build a new function anyway.      -- | Left-associative fold of a structure.     -- but with strict application of the operator.@@ -138,8 +157,9 @@     foldr1 f xs = fromMaybe (error "foldr1: empty structure")                     (foldr mf Nothing xs)       where-        mf x Nothing = Just x-        mf x (Just y) = Just (f x y)+        mf x m = Just (case m of+                         Nothing -> x+                         Just y  -> f x y)      -- | A variant of 'foldl' that has no base case,     -- and thus may only be applied to non-empty structures.@@ -149,10 +169,50 @@     foldl1 f xs = fromMaybe (error "foldl1: empty structure")                     (foldl mf Nothing xs)       where-        mf Nothing y = Just y-        mf (Just x) y = Just (f x y)-    {-# MINIMAL foldMap | foldr #-}+        mf m y = Just (case m of+                         Nothing -> y+                         Just x  -> f x y) +    -- | List of elements of a structure, from left to right.+    toList :: t a -> [a]+    {-# INLINE toList #-}+    toList t = build (\ c n -> foldr c n t)++    -- | Test whether the structure is empty. The default implementation is+    -- optimized for structures that are similar to cons-lists, because there+    -- is no general way to do better.+    null :: t a -> Bool+    null = foldr (\_ _ -> False) True++    -- | Returns the size/length of a finite structure as an 'Int'.  The+    -- default implementation is optimized for structures that are similar to+    -- cons-lists, because there is no general way to do better.+    length :: t a -> Int+    length = foldl' (\c _ -> c+1) 0++    -- | Does the element occur in the structure?+    elem :: Eq a => a -> t a -> Bool+    elem = any . (==)++    -- | The largest element of a non-empty structure.+    maximum :: forall a . Ord a => t a -> a+    maximum = fromMaybe (error "maximum: empty structure") .+       getMax . foldMap (Max #. (Just :: a -> Maybe a))++    -- | The least element of a non-empty structure.+    minimum :: forall a . Ord a => t a -> a+    minimum = fromMaybe (error "minimum: empty structure") .+       getMin . foldMap (Min #. (Just :: a -> Maybe a))++    -- | The 'sum' function computes the sum of the numbers of a structure.+    sum :: Num a => t a -> a+    sum = getSum #. foldMap Sum++    -- | The 'product' function computes the product of the numbers of a+    -- structure.+    product :: Num a => t a -> a+    product = getProduct #. foldMap Product+ -- instances for Prelude types  instance Foldable Maybe where@@ -163,11 +223,19 @@     foldl f z (Just x) = f z x  instance Foldable [] where-    foldr = Prelude.foldr-    foldl = Prelude.foldl-    foldl' = List.foldl'-    foldr1 = Prelude.foldr1-    foldl1 = Prelude.foldl1+    elem    = List.elem+    foldl   = List.foldl+    foldl'  = List.foldl'+    foldl1  = List.foldl1+    foldr   = List.foldr+    foldr1  = List.foldr1+    length  = List.length+    maximum = List.maximum+    minimum = List.minimum+    null    = List.null+    product = List.product+    sum     = List.sum+    toList  = id  instance Foldable (Either a) where     foldMap _ (Left _) = mempty@@ -176,16 +244,26 @@     foldr _ z (Left _) = z     foldr f z (Right y) = f y z +    length (Left _)  = 0+    length (Right _) = 1++    null             = isLeft+ instance Foldable ((,) a) where     foldMap f (_, y) = f y      foldr f z (_, y) = f y z  instance Ix i => Foldable (Array i) where-    foldr f z = Prelude.foldr f z . elems-    foldl f z = Prelude.foldl f z . elems-    foldr1 f = Prelude.foldr1 f . elems-    foldl1 f = Prelude.foldl1 f . elems+    foldr = foldrElems+    foldl = foldlElems+    foldl' = foldlElems'+    foldr' = foldrElems'+    foldl1 = foldl1Elems+    foldr1 = foldr1Elems+    toList = elems+    length = numElements+    null a = numElements a == 0  instance Foldable Proxy where     foldMap _ _ = mempty@@ -197,13 +275,42 @@     foldl _ z _ = z     {-# INLINE foldl #-}     foldl1 _ _ = error "foldl1: Proxy"-    {-# INLINE foldl1 #-}     foldr1 _ _ = error "foldr1: Proxy"-    {-# INLINE foldr1 #-}+    length _   = 0+    null _     = True+    elem _ _   = False+    sum _      = 0+    product _  = 1 -instance Foldable (Const m) where-    foldMap _ _ = mempty+-- We don't export Max and Min because, as Edward Kmett pointed out to me,+-- there are two reasonable ways to define them. One way is to use Maybe, as we+-- do here; the other way is to impose a Bounded constraint on the Monoid+-- instance. We may eventually want to add both versions, but we don't want to+-- trample on anyone's toes by imposing Max = MaxMaybe. +newtype Max a = Max {getMax :: Maybe a}+newtype Min a = Min {getMin :: Maybe a}++instance Ord a => Monoid (Max a) where+  mempty = Max Nothing++  {-# INLINE mappend #-}+  m `mappend` Max Nothing = m+  Max Nothing `mappend` n = n+  (Max m@(Just x)) `mappend` (Max n@(Just y))+    | x >= y    = Max m+    | otherwise = Max n++instance Ord a => Monoid (Min a) where+  mempty = Min Nothing++  {-# INLINE mappend #-}+  m `mappend` Min Nothing = m+  Min Nothing `mappend` n = n+  (Min m@(Just x)) `mappend` (Min n@(Just y))+    | x <= y    = Min m+    | otherwise = Min n+ -- | Monadic fold over the elements of a structure, -- associating to the right, i.e. from right to left. foldrM :: (Foldable t, Monad m) => (a -> b -> m b) -> b -> t a -> m b@@ -216,33 +323,54 @@ foldlM f z0 xs = foldr f' return xs z0   where f' x k z = f z x >>= k --- | Map each element of a structure to an action, evaluate--- these actions from left to right, and ignore the results.+-- | Map each element of a structure to an action, evaluate these+-- actions from left to right, and ignore the results. For a version+-- that doesn't ignore the results see 'Data.Traversable.traverse'. traverse_ :: (Foldable t, Applicative f) => (a -> f b) -> t a -> f () traverse_ f = foldr ((*>) . f) (pure ()) --- | 'for_' is 'traverse_' with its arguments flipped.+-- | 'for_' is 'traverse_' with its arguments flipped. For a version+-- that doesn't ignore the results see 'Data.Traversable.for'.+--+-- >>> for_ [1..4] print+-- 1+-- 2+-- 3+-- 4 for_ :: (Foldable t, Applicative f) => t a -> (a -> f b) -> f () {-# INLINE for_ #-} for_ = flip traverse_  -- | Map each element of a structure to a monadic action, evaluate--- these actions from left to right, and ignore the results.+-- these actions from left to right, and ignore the results. For a+-- version that doesn't ignore the results see+-- 'Data.Traversable.mapM'.+--+-- As of base 4.8.0.0, 'mapM_' is just 'traverse_', specialized to+-- 'Monad'. mapM_ :: (Foldable t, Monad m) => (a -> m b) -> t a -> m ()-mapM_ f = foldr ((>>) . f) (return ())+mapM_ f= foldr ((>>) . f) (return ()) --- | 'forM_' is 'mapM_' with its arguments flipped.+-- | 'forM_' is 'mapM_' with its arguments flipped. For a version that+-- doesn't ignore the results see 'Data.Traversable.forM'.+--+-- As of base 4.8.0.0, 'forM_' is just 'for_', specialized to 'Monad'. forM_ :: (Foldable t, Monad m) => t a -> (a -> m b) -> m () {-# INLINE forM_ #-} forM_ = flip mapM_ --- | Evaluate each action in the structure from left to right,--- and ignore the results.+-- | Evaluate each action in the structure from left to right, and+-- ignore the results. For a version that doesn't ignore the results+-- see 'Data.Traversable.sequenceA'. sequenceA_ :: (Foldable t, Applicative f) => t (f a) -> f () sequenceA_ = foldr (*>) (pure ())  -- | Evaluate each monadic action in the structure from left to right,--- and ignore the results.+-- and ignore the results. For a version that doesn't ignore the+-- results see 'Data.Traversable.sequence'.+--+-- As of base 4.8.0.0, 'sequence_' is just 'sequenceA_', specialized+-- to 'Monad'. sequence_ :: (Foldable t, Monad m) => t (m a) -> m () sequence_ = foldr (>>) (return ()) @@ -252,57 +380,43 @@ asum = foldr (<|>) empty  -- | The sum of a collection of actions, generalizing 'concat'.+-- As of base 4.8.0.0, 'msum' is just 'asum', specialized to 'MonadPlus'. msum :: (Foldable t, MonadPlus m) => t (m a) -> m a {-# INLINE msum #-}-msum = foldr mplus mzero---- These use foldr rather than foldMap to avoid repeated concatenation.---- | List of elements of a structure.-toList :: Foldable t => t a -> [a]-{-# INLINE toList #-}-toList t = build (\ c n -> foldr c n t)+msum = asum  -- | The concatenation of all the elements of a container of lists. concat :: Foldable t => t [a] -> [a]-concat = fold+concat xs = build (\c n -> foldr (\x y -> foldr c y x) n xs)+{-# INLINE concat #-}  -- | Map a function over all the elements of a container and concatenate -- the resulting lists. concatMap :: Foldable t => (a -> [b]) -> t a -> [b]-concatMap = foldMap+concatMap f xs = build (\c n -> foldr (\x b -> foldr c b (f x)) n xs)+{-# INLINE concatMap #-} +-- These use foldr rather than foldMap to avoid repeated concatenation.+ -- | 'and' returns the conjunction of a container of Bools.  For the -- result to be 'True', the container must be finite; 'False', however, -- results from a 'False' value finitely far from the left end. and :: Foldable t => t Bool -> Bool-and = getAll . foldMap All+and = getAll #. foldMap All  -- | 'or' returns the disjunction of a container of Bools.  For the -- result to be 'False', the container must be finite; 'True', however, -- results from a 'True' value finitely far from the left end. or :: Foldable t => t Bool -> Bool-or = getAny . foldMap Any+or = getAny #. foldMap Any  -- | Determines whether any element of the structure satisfies the predicate. any :: Foldable t => (a -> Bool) -> t a -> Bool-any p = getAny . foldMap (Any . p)+any p = getAny #. foldMap (Any #. p)  -- | Determines whether all elements of the structure satisfy the predicate. all :: Foldable t => (a -> Bool) -> t a -> Bool-all p = getAll . foldMap (All . p)---- | The 'sum' function computes the sum of the numbers of a structure.-sum :: (Foldable t, Num a) => t a -> a-sum = getSum . foldMap Sum---- | The 'product' function computes the product of the numbers of a structure.-product :: (Foldable t, Num a) => t a -> a-product = getProduct . foldMap Product---- | The largest element of a non-empty structure.-maximum :: (Foldable t, Ord a) => t a -> a-maximum = foldr1 max+all p = getAll #. foldMap (All #. p)  -- | The largest element of a non-empty structure with respect to the -- given comparison function.@@ -312,10 +426,6 @@                         GT -> x                         _  -> y --- | The least element of a non-empty structure.-minimum :: (Foldable t, Ord a) => t a -> a-minimum = foldr1 min- -- | The least element of a non-empty structure with respect to the -- given comparison function. minimumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a@@ -324,10 +434,6 @@                         GT -> y                         _  -> x --- | Does the element occur in the structure?-elem :: (Foldable t, Eq a) => a -> t a -> Bool-elem = any . (==)- -- | 'notElem' is the negation of 'elem'. notElem :: (Foldable t, Eq a) => a -> t a -> Bool notElem x = not . elem x@@ -336,5 +442,36 @@ -- the leftmost element of the structure matching the predicate, or -- 'Nothing' if there is no such element. find :: Foldable t => (a -> Bool) -> t a -> Maybe a-find p = listToMaybe . concatMap (\ x -> if p x then [x] else [])+find p = getFirst . foldMap (\ x -> First (if p x then Just x else Nothing)) +-- See Note [Function coercion]+(#.) :: Coercible b c => (b -> c) -> (a -> b) -> (a -> c)+(#.) _f = coerce+{-# INLINE (#.) #-}++{-+Note [Function coercion]+~~~~~~~~~~~~~~~~~~~~~~~~++Several functions here use (#.) instead of (.) to avoid potential efficiency+problems relating to #7542. The problem, in a nutshell:++If N is a newtype constructor, then N x will always have the same+representation as x (something similar applies for a newtype deconstructor).+However, if f is a function,++N . f = \x -> N (f x)++This looks almost the same as f, but the eta expansion lifts it--the lhs could+be _|_, but the rhs never is. This can lead to very inefficient code.  Thus we+steal a technique from Shachaf and Edward Kmett and adapt it to the current+(rather clean) setting. Instead of using  N . f,  we use  N .## f, which is+just++coerce f `asTypeOf` (N . f)++That is, we just *pretend* that f has the right type, and thanks to the safety+of coerce, the type checker guarantees that nothing really goes wrong. We still+have to be a bit careful, though: remember that #. completely ignores the+*value* of its left operand.+-}
Data/Function.hs view
@@ -1,9 +1,11 @@-{-# LANGUAGE Safe #-}+{-# LANGUAGE Trustworthy #-}+{-# LANGUAGE NoImplicitPrelude #-}  ----------------------------------------------------------------------------- -- | -- Module      :  Data.Function -- Copyright   :  Nils Anders Danielsson 2006+--             ,  Alexander Berntsen     2014 -- License     :  BSD-style (see the LICENSE file in the distribution) -- -- Maintainer  :  libraries@haskell.org@@ -18,13 +20,15 @@   ( -- * "Prelude" re-exports     id, const, (.), flip, ($)     -- * Other combinators+  , (&)   , fix   , on   ) where -import Prelude+import GHC.Base ( ($), (.), id, const, flip )  infixl 0 `on`+infixl 1 &  -- | @'fix' f@ is the least fixed point of the function @f@, -- i.e. the least defined @x@ such that @f x = x@.@@ -86,3 +90,11 @@ on :: (b -> b -> c) -> (a -> b) -> a -> a -> c (.*.) `on` f = \x y -> f x .*. f y ++-- | '&' is a reverse application operator.  This provides notational+-- convenience.  Its precedence is one higher than that of the forward+-- application operator '$', which allows '&' to be nested in '$'.+--+-- @since 4.8.0.0+(&) :: a -> (a -> b) -> b+x & f = f x
Data/Functor.hs view
@@ -1,17 +1,18 @@ {-# LANGUAGE Trustworthy #-}+{-# LANGUAGE NoImplicitPrelude #-}  ----------------------------------------------------------------------------- -- | -- Module      :  Data.Functor -- Copyright   :  (c) The University of Glasgow 2001 -- License     :  BSD-style (see the file libraries/base/LICENSE)--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  provisional -- Portability :  portable -- -- Functors: uniform action over a parameterized type, generalizing the--- 'map' function on lists.+-- 'Data.List.map' function on lists.  module Data.Functor     (@@ -22,12 +23,43 @@       void,     ) where -import Control.Monad-import GHC.Base (Functor(..))+import GHC.Base ( Functor(..), flip ) +-- $setup+-- Allow the use of Prelude in doctests.+-- >>> import Prelude+ infixl 4 <$>  -- | An infix synonym for 'fmap'.+--+-- ==== __Examples__+--+-- Convert from a @'Maybe' 'Int'@ to a @'Maybe' 'String'@ using 'show':+--+-- >>> show <$> Nothing+-- Nothing+-- >>> show <$> Just 3+-- Just "3"+--+-- Convert from an @'Either' 'Int' 'Int'@ to an @'Either' 'Int'@+-- 'String' using 'show':+--+-- >>> show <$> Left 17+-- Left 17+-- >>> show <$> Right 17+-- Right "17"+--+-- Double each element of a list:+--+-- >>> (*2) <$> [1,2,3]+-- [2,4,6]+--+-- Apply 'even' to the second element of a pair:+--+-- >>> even <$> (2,2)+-- (2,True)+-- (<$>) :: Functor f => (a -> b) -> f a -> f b (<$>) = fmap @@ -35,7 +67,77 @@  -- | Flipped version of '<$'. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0+--+-- ==== __Examples__+--+-- Replace the contents of a @'Maybe' 'Int'@ with a constant 'String':+--+-- >>> Nothing $> "foo"+-- Nothing+-- >>> Just 90210 $> "foo"+-- Just "foo"+--+-- Replace the contents of an @'Either' 'Int' 'Int'@ with a constant+-- 'String', resulting in an @'Either' 'Int' 'String'@:+--+-- >>> Left 8675309 $> "foo"+-- Left 8675309+-- >>> Right 8675309 $> "foo"+-- Right "foo"+--+-- Replace each element of a list with a constant 'String':+--+-- >>> [1,2,3] $> "foo"+-- ["foo","foo","foo"]+--+-- Replace the second element of a pair with a constant 'String':+--+-- >>> (1,2) $> "foo"+-- (1,"foo")+-- ($>) :: Functor f => f a -> b -> f b ($>) = flip (<$) +-- | @'void' value@ discards or ignores the result of evaluation, such+-- as the return value of an 'System.IO.IO' action.+--+-- ==== __Examples__+--+-- Replace the contents of a @'Maybe' 'Int'@ with unit:+--+-- >>> void Nothing+-- Nothing+-- >>> void (Just 3)+-- Just ()+--+-- Replace the contents of an @'Either' 'Int' 'Int'@ with unit,+-- resulting in an @'Either' 'Int' '()'@:+--+-- >>> void (Left 8675309)+-- Left 8675309+-- >>> void (Right 8675309)+-- Right ()+--+-- Replace every element of a list with unit:+--+-- >>> void [1,2,3]+-- [(),(),()]+--+-- Replace the second element of a pair with unit:+--+-- >>> void (1,2)+-- (1,())+--+-- Discard the result of an 'System.IO.IO' action:+--+-- >>> mapM print [1,2]+-- 1+-- 2+-- [(),()]+-- >>> void $ mapM print [1,2]+-- 1+-- 2+--+void :: Functor f => f a -> f ()+void x = () <$ x
+ Data/Functor/Identity.hs view
@@ -0,0 +1,104 @@+{-# LANGUAGE AutoDeriveTypeable #-}+{-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE DeriveTraversable #-}+{-# LANGUAGE Trustworthy #-}++-----------------------------------------------------------------------------+-- |+-- Module      :  Data.Functor.Identity+-- Copyright   :  (c) Andy Gill 2001,+--                (c) Oregon Graduate Institute of Science and Technology 2001+-- License     :  BSD-style (see the file LICENSE)+--+-- Maintainer  :  ross@soi.city.ac.uk+-- Stability   :  experimental+-- Portability :  portable+--+-- The identity functor and monad.+--+-- This trivial type constructor serves two purposes:+--+-- * It can be used with functions parameterized by functor or monad classes.+--+-- * It can be used as a base monad to which a series of monad+--   transformers may be applied to construct a composite monad.+--   Most monad transformer modules include the special case of+--   applying the transformer to 'Identity'.  For example, @State s@+--   is an abbreviation for @StateT s 'Identity'@.+--+-- @since 4.8.0.0+-----------------------------------------------------------------------------++module Data.Functor.Identity (+    Identity(..),+  ) where++import Control.Monad.Fix+import Control.Monad.Zip+import Data.Coerce+import Data.Data (Data)+import Data.Foldable+import GHC.Generics (Generic, Generic1)++-- | Identity functor and monad. (a non-strict monad)+--+-- @since 4.8.0.0+newtype Identity a = Identity { runIdentity :: a }+    deriving (Eq, Ord, Data, Traversable, Generic, Generic1)++-- | This instance would be equivalent to the derived instances of the+-- 'Identity' newtype if the 'runIdentity' field were removed+instance (Read a) => Read (Identity a) where+    readsPrec d = readParen (d > 10) $ \ r ->+        [(Identity x,t) | ("Identity",s) <- lex r, (x,t) <- readsPrec 11 s]++-- | This instance would be equivalent to the derived instances of the+-- 'Identity' newtype if the 'runIdentity' field were removed+instance (Show a) => Show (Identity a) where+    showsPrec d (Identity x) = showParen (d > 10) $+        showString "Identity " . showsPrec 11 x++-- ---------------------------------------------------------------------------+-- Identity instances for Functor and Monad++instance Foldable Identity where+    foldMap                = coerce++    elem                   = (. runIdentity) #. (==)+    foldl                  = coerce+    foldl'                 = coerce+    foldl1 _               = runIdentity+    foldr f z (Identity x) = f x z+    foldr'                 = foldr+    foldr1 _               = runIdentity+    length _               = 1+    maximum                = runIdentity+    minimum                = runIdentity+    null _                 = False+    product                = runIdentity+    sum                    = runIdentity+    toList (Identity x)    = [x]++instance Functor Identity where+    fmap     = coerce++instance Applicative Identity where+    pure     = Identity+    (<*>)    = coerce++instance Monad Identity where+    return   = Identity+    m >>= k  = k (runIdentity m)++instance MonadFix Identity where+    mfix f   = Identity (fix (runIdentity . f))++instance MonadZip Identity where+    mzipWith = coerce+    munzip   = coerce++-- | Internal (non-exported) 'Coercible' helper for 'elem'+--+-- See Note [Function coercion] in "Data.Foldable" for more details.+(#.) :: Coercible b c => (b -> c) -> (a -> b) -> a -> c+(#.) _f = coerce
Data/IORef.hs view
@@ -71,7 +71,7 @@  -- |Strict version of 'modifyIORef' ----- /Since: 4.6.0.0/+-- @since 4.6.0.0 modifyIORef' :: IORef a -> (a -> a) -> IO () modifyIORef' ref f = do     x <- readIORef ref@@ -103,18 +103,18 @@ -- | Strict version of 'atomicModifyIORef'.  This forces both the value stored -- in the 'IORef' as well as the value returned. ----- /Since: 4.6.0.0/+-- @since 4.6.0.0 atomicModifyIORef' :: IORef a -> (a -> (a,b)) -> IO b atomicModifyIORef' ref f = do-    b <- atomicModifyIORef ref-            (\x -> let (a, b) = f x-                    in (a, a `seq` b))+    b <- atomicModifyIORef ref $ \a ->+            case f a of+                v@(a',_) -> a' `seq` v     b `seq` return b  -- | Variant of 'writeIORef' with the \"barrier to reordering\" property that -- 'atomicModifyIORef' has. ----- /Since: 4.6.0.0/+-- @since 4.6.0.0 atomicWriteIORef :: IORef a -> a -> IO () atomicWriteIORef ref a = do     x <- atomicModifyIORef ref (\_ -> (a, ()))
Data/Ix.hs view
@@ -12,7 +12,7 @@ -- -- The 'Ix' class is used to map a contiguous subrange of values in -- type onto integers.  It is used primarily for array indexing--- (see the array package).+-- (see the array package).  'Ix' uses row-major order. --  ----------------------------------------------------------------------------- @@ -56,11 +56,9 @@     -- >        inRange (Yellow,Blue) Red    ==  False     --      -- * For single-constructor datatypes, the derived instance declarations-    -- are as shown for tuples in Figure 1-    -- <http://www.haskell.org/onlinelibrary/ix.html#prelude-index>.+    -- are as shown for tuples in chapter 19, section 2 of the Haskell 2010 report:+    -- <https://www.haskell.org/onlinereport/haskell2010/haskellch19.html>.      ) where---- import Prelude  import GHC.Arr
Data/List.hs view
@@ -1,12 +1,12 @@ {-# LANGUAGE Trustworthy #-}-{-# LANGUAGE CPP, NoImplicitPrelude, MagicHash, BangPatterns #-}+{-# LANGUAGE NoImplicitPrelude #-}  ----------------------------------------------------------------------------- -- | -- Module      :  Data.List -- Copyright   :  (c) The University of Glasgow 2001 -- License     :  BSD-style (see the file libraries/base/LICENSE)--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  stable -- Portability :  portable@@ -24,6 +24,7 @@    , last    , tail    , init+   , uncons    , null    , length @@ -34,7 +35,7 @@    , intersperse    , intercalate    , transpose-   +    , subsequences    , permutations @@ -64,6 +65,7 @@     -- ** Scans    , scanl+   , scanl'    , scanl1    , scanr    , scanr1@@ -105,6 +107,7 @@    , isPrefixOf    , isSuffixOf    , isInfixOf+   , isSubsequenceOf     -- * Searching lists @@ -164,6 +167,7 @@     -- ** Ordered lists    , sort+   , sortOn    , insert     -- * Generalized functions@@ -205,952 +209,33 @@     ) where -import Data.Maybe-import Data.Bits        ( (.&.) )-import Data.Char        ( isSpace )--import GHC.Num-import GHC.Real-import GHC.List-import GHC.Base--infix 5 \\ -- comment to fool cpp---- -------------------------------------------------------------------------------- List functions---- | The 'dropWhileEnd' function drops the largest suffix of a list--- in which the given predicate holds for all elements.  For example:------ > dropWhileEnd isSpace "foo\n" == "foo"--- > dropWhileEnd isSpace "foo bar" == "foo bar"--- > dropWhileEnd isSpace ("foo\n" ++ undefined) == "foo" ++ undefined------ /Since: 4.5.0.0/-dropWhileEnd :: (a -> Bool) -> [a] -> [a]-dropWhileEnd p = foldr (\x xs -> if p x && null xs then [] else x : xs) []---- | The 'stripPrefix' function drops the given prefix from a list.--- It returns 'Nothing' if the list did not start with the prefix--- given, or 'Just' the list after the prefix, if it does.------ > stripPrefix "foo" "foobar" == Just "bar"--- > stripPrefix "foo" "foo" == Just ""--- > stripPrefix "foo" "barfoo" == Nothing--- > stripPrefix "foo" "barfoobaz" == Nothing-stripPrefix :: Eq a => [a] -> [a] -> Maybe [a]-stripPrefix [] ys = Just ys-stripPrefix (x:xs) (y:ys)- | x == y = stripPrefix xs ys-stripPrefix _ _ = Nothing---- | The 'elemIndex' function returns the index of the first element--- in the given list which is equal (by '==') to the query element,--- or 'Nothing' if there is no such element.-elemIndex       :: Eq a => a -> [a] -> Maybe Int-elemIndex x     = findIndex (x==)---- | The 'elemIndices' function extends 'elemIndex', by returning the--- indices of all elements equal to the query element, in ascending order.-elemIndices     :: Eq a => a -> [a] -> [Int]-elemIndices x   = findIndices (x==)---- | The 'find' function takes a predicate and a list and returns the--- first element in the list matching the predicate, or 'Nothing' if--- there is no such element.-find            :: (a -> Bool) -> [a] -> Maybe a-find p          = listToMaybe . filter p---- | The 'findIndex' function takes a predicate and a list and returns--- the index of the first element in the list satisfying the predicate,--- or 'Nothing' if there is no such element.-findIndex       :: (a -> Bool) -> [a] -> Maybe Int-findIndex p     = listToMaybe . findIndices p---- | The 'findIndices' function extends 'findIndex', by returning the--- indices of all elements satisfying the predicate, in ascending order.-findIndices      :: (a -> Bool) -> [a] -> [Int]-#ifdef USE_REPORT_PRELUDE-findIndices p xs = [ i | (x,i) <- zip xs [0..], p x]-#else--- Efficient definition-findIndices p ls = loop 0# ls-                 where-                   loop _ [] = []-                   loop n (x:xs) | p x       = I# n : loop (n +# 1#) xs-                                 | otherwise = loop (n +# 1#) xs-#endif  /* USE_REPORT_PRELUDE */---- | The 'isPrefixOf' function takes two lists and returns 'True'--- iff the first list is a prefix of the second.-isPrefixOf              :: (Eq a) => [a] -> [a] -> Bool-isPrefixOf [] _         =  True-isPrefixOf _  []        =  False-isPrefixOf (x:xs) (y:ys)=  x == y && isPrefixOf xs ys---- | The 'isSuffixOf' function takes two lists and returns 'True'--- iff the first list is a suffix of the second.--- Both lists must be finite.-isSuffixOf              :: (Eq a) => [a] -> [a] -> Bool-isSuffixOf x y          =  reverse x `isPrefixOf` reverse y---- | The 'isInfixOf' function takes two lists and returns 'True'--- iff the first list is contained, wholly and intact,--- anywhere within the second.------ Example:------ >isInfixOf "Haskell" "I really like Haskell." == True--- >isInfixOf "Ial" "I really like Haskell." == False-isInfixOf               :: (Eq a) => [a] -> [a] -> Bool-isInfixOf needle haystack = any (isPrefixOf needle) (tails haystack)---- | /O(n^2)/. The 'nub' function removes duplicate elements from a list.--- In particular, it keeps only the first occurrence of each element.--- (The name 'nub' means \`essence\'.)--- It is a special case of 'nubBy', which allows the programmer to supply--- their own equality test.-nub                     :: (Eq a) => [a] -> [a]-#ifdef USE_REPORT_PRELUDE-nub                     =  nubBy (==)-#else--- stolen from HBC-nub l                   = nub' l []             -- '-  where-    nub' [] _           = []                    -- '-    nub' (x:xs) ls                              -- '-        | x `elem` ls   = nub' xs ls            -- '-        | otherwise     = x : nub' xs (x:ls)    -- '-#endif---- | The 'nubBy' function behaves just like 'nub', except it uses a--- user-supplied equality predicate instead of the overloaded '=='--- function.-nubBy                   :: (a -> a -> Bool) -> [a] -> [a]-#ifdef USE_REPORT_PRELUDE-nubBy eq []             =  []-nubBy eq (x:xs)         =  x : nubBy eq (filter (\ y -> not (eq x y)) xs)-#else-nubBy eq l              = nubBy' l []-  where-    nubBy' [] _         = []-    nubBy' (y:ys) xs-       | elem_by eq y xs = nubBy' ys xs-       | otherwise       = y : nubBy' ys (y:xs)---- Not exported:--- Note that we keep the call to `eq` with arguments in the--- same order as in the reference implementation--- 'xs' is the list of things we've seen so far, --- 'y' is the potential new element-elem_by :: (a -> a -> Bool) -> a -> [a] -> Bool-elem_by _  _ []         =  False-elem_by eq y (x:xs)     =  y `eq` x || elem_by eq y xs-#endif----- | 'delete' @x@ removes the first occurrence of @x@ from its list argument.--- For example,------ > delete 'a' "banana" == "bnana"------ It is a special case of 'deleteBy', which allows the programmer to--- supply their own equality test.--delete                  :: (Eq a) => a -> [a] -> [a]-delete                  =  deleteBy (==)---- | The 'deleteBy' function behaves like 'delete', but takes a--- user-supplied equality predicate.-deleteBy                :: (a -> a -> Bool) -> a -> [a] -> [a]-deleteBy _  _ []        = []-deleteBy eq x (y:ys)    = if x `eq` y then ys else y : deleteBy eq x ys---- | The '\\' function is list difference (non-associative).--- In the result of @xs@ '\\' @ys@, the first occurrence of each element of--- @ys@ in turn (if any) has been removed from @xs@.  Thus------ > (xs ++ ys) \\ xs == ys.------ It is a special case of 'deleteFirstsBy', which allows the programmer--- to supply their own equality test.--(\\)                    :: (Eq a) => [a] -> [a] -> [a]-(\\)                    =  foldl (flip delete)---- | The 'union' function returns the list union of the two lists.--- For example,------ > "dog" `union` "cow" == "dogcw"------ Duplicates, and elements of the first list, are removed from the--- the second list, but if the first list contains duplicates, so will--- the result.--- It is a special case of 'unionBy', which allows the programmer to supply--- their own equality test.--union                   :: (Eq a) => [a] -> [a] -> [a]-union                   = unionBy (==)---- | The 'unionBy' function is the non-overloaded version of 'union'.-unionBy                 :: (a -> a -> Bool) -> [a] -> [a] -> [a]-unionBy eq xs ys        =  xs ++ foldl (flip (deleteBy eq)) (nubBy eq ys) xs---- | The 'intersect' function takes the list intersection of two lists.--- For example,------ > [1,2,3,4] `intersect` [2,4,6,8] == [2,4]------ If the first list contains duplicates, so will the result.------ > [1,2,2,3,4] `intersect` [6,4,4,2] == [2,2,4]------ It is a special case of 'intersectBy', which allows the programmer to--- supply their own equality test. If the element is found in both the first--- and the second list, the element from the first list will be used.--intersect               :: (Eq a) => [a] -> [a] -> [a]-intersect               =  intersectBy (==)---- | The 'intersectBy' function is the non-overloaded version of 'intersect'.-intersectBy             :: (a -> a -> Bool) -> [a] -> [a] -> [a]-intersectBy _  [] _     =  []-intersectBy _  _  []    =  []-intersectBy eq xs ys    =  [x | x <- xs, any (eq x) ys]---- | The 'intersperse' function takes an element and a list and--- \`intersperses\' that element between the elements of the list.--- For example,------ > intersperse ',' "abcde" == "a,b,c,d,e"--intersperse             :: a -> [a] -> [a]-intersperse _   []      = []-intersperse sep (x:xs)  = x : prependToAll sep xs----- Not exported:--- We want to make every element in the 'intersperse'd list available--- as soon as possible to avoid space leaks. Experiments suggested that--- a separate top-level helper is more efficient than a local worker.-prependToAll            :: a -> [a] -> [a]-prependToAll _   []     = []-prependToAll sep (x:xs) = sep : x : prependToAll sep xs---- | 'intercalate' @xs xss@ is equivalent to @('concat' ('intersperse' xs xss))@.--- It inserts the list @xs@ in between the lists in @xss@ and concatenates the--- result.-intercalate :: [a] -> [[a]] -> [a]-intercalate xs xss = concat (intersperse xs xss)---- | The 'transpose' function transposes the rows and columns of its argument.--- For example,------ > transpose [[1,2,3],[4,5,6]] == [[1,4],[2,5],[3,6]]--transpose               :: [[a]] -> [[a]]-transpose []             = []-transpose ([]   : xss)   = transpose xss-transpose ((x:xs) : xss) = (x : [h | (h:_) <- xss]) : transpose (xs : [ t | (_:t) <- xss])----- | The 'partition' function takes a predicate a list and returns--- the pair of lists of elements which do and do not satisfy the--- predicate, respectively; i.e.,------ > partition p xs == (filter p xs, filter (not . p) xs)--partition               :: (a -> Bool) -> [a] -> ([a],[a])-{-# INLINE partition #-}-partition p xs = foldr (select p) ([],[]) xs--select :: (a -> Bool) -> a -> ([a], [a]) -> ([a], [a])-select p x ~(ts,fs) | p x       = (x:ts,fs)-                    | otherwise = (ts, x:fs)---- | The 'mapAccumL' function behaves like a combination of 'map' and--- 'foldl'; it applies a function to each element of a list, passing--- an accumulating parameter from left to right, and returning a final--- value of this accumulator together with the new list.-mapAccumL :: (acc -> x -> (acc, y)) -- Function of elt of input list-                                    -- and accumulator, returning new-                                    -- accumulator and elt of result list-          -> acc            -- Initial accumulator -          -> [x]            -- Input list-          -> (acc, [y])     -- Final accumulator and result list-mapAccumL _ s []        =  (s, [])-mapAccumL f s (x:xs)    =  (s'',y:ys)-                           where (s', y ) = f s x-                                 (s'',ys) = mapAccumL f s' xs---- | The 'mapAccumR' function behaves like a combination of 'map' and--- 'foldr'; it applies a function to each element of a list, passing--- an accumulating parameter from right to left, and returning a final--- value of this accumulator together with the new list.-mapAccumR :: (acc -> x -> (acc, y))     -- Function of elt of input list-                                        -- and accumulator, returning new-                                        -- accumulator and elt of result list-            -> acc              -- Initial accumulator-            -> [x]              -- Input list-            -> (acc, [y])               -- Final accumulator and result list-mapAccumR _ s []        =  (s, [])-mapAccumR f s (x:xs)    =  (s'', y:ys)-                           where (s'',y ) = f s' x-                                 (s', ys) = mapAccumR f s xs---- | The 'insert' function takes an element and a list and inserts the--- element into the list at the first position where it is less--- than or equal to the next element.  In particular, if the list--- is sorted before the call, the result will also be sorted.--- It is a special case of 'insertBy', which allows the programmer to--- supply their own comparison function.-insert :: Ord a => a -> [a] -> [a]-insert e ls = insertBy (compare) e ls---- | The non-overloaded version of 'insert'.-insertBy :: (a -> a -> Ordering) -> a -> [a] -> [a]-insertBy _   x [] = [x]-insertBy cmp x ys@(y:ys')- = case cmp x y of-     GT -> y : insertBy cmp x ys'-     _  -> x : ys---- | 'maximum' returns the maximum value from a list,--- which must be non-empty, finite, and of an ordered type.--- It is a special case of 'Data.List.maximumBy', which allows the--- programmer to supply their own comparison function.-maximum                 :: (Ord a) => [a] -> a-{-# NOINLINE [1] maximum #-}-maximum []              =  errorEmptyList "maximum"-maximum xs              =  foldl1 max xs--{-# RULES-  "maximumInt"     maximum = (strictMaximum :: [Int]     -> Int);-  "maximumInteger" maximum = (strictMaximum :: [Integer] -> Integer)- #-}---- We can't make the overloaded version of maximum strict without--- changing its semantics (max might not be strict), but we can for--- the version specialised to 'Int'.-strictMaximum           :: (Ord a) => [a] -> a-strictMaximum []        =  errorEmptyList "maximum"-strictMaximum xs        =  foldl1' max xs---- | 'minimum' returns the minimum value from a list,--- which must be non-empty, finite, and of an ordered type.--- It is a special case of 'Data.List.minimumBy', which allows the--- programmer to supply their own comparison function.-minimum                 :: (Ord a) => [a] -> a-{-# NOINLINE [1] minimum #-}-minimum []              =  errorEmptyList "minimum"-minimum xs              =  foldl1 min xs--{-# RULES-  "minimumInt"     minimum = (strictMinimum :: [Int]     -> Int);-  "minimumInteger" minimum = (strictMinimum :: [Integer] -> Integer)- #-}--strictMinimum           :: (Ord a) => [a] -> a-strictMinimum []        =  errorEmptyList "minimum"-strictMinimum xs        =  foldl1' min xs---- | The 'maximumBy' function takes a comparison function and a list--- and returns the greatest element of the list by the comparison function.--- The list must be finite and non-empty.-maximumBy               :: (a -> a -> Ordering) -> [a] -> a-maximumBy _ []          =  error "List.maximumBy: empty list"-maximumBy cmp xs        =  foldl1 maxBy xs-                        where-                           maxBy x y = case cmp x y of-                                       GT -> x-                                       _  -> y---- | The 'minimumBy' function takes a comparison function and a list--- and returns the least element of the list by the comparison function.--- The list must be finite and non-empty.-minimumBy               :: (a -> a -> Ordering) -> [a] -> a-minimumBy _ []          =  error "List.minimumBy: empty list"-minimumBy cmp xs        =  foldl1 minBy xs-                        where-                           minBy x y = case cmp x y of-                                       GT -> y-                                       _  -> x---- | The 'genericLength' function is an overloaded version of 'length'.  In--- particular, instead of returning an 'Int', it returns any type which is--- an instance of 'Num'.  It is, however, less efficient than 'length'.-genericLength           :: (Num i) => [a] -> i-{-# NOINLINE [1] genericLength #-}-genericLength []        =  0-genericLength (_:l)     =  1 + genericLength l--{-# RULES-  "genericLengthInt"     genericLength = (strictGenericLength :: [a] -> Int);-  "genericLengthInteger" genericLength = (strictGenericLength :: [a] -> Integer);- #-}--strictGenericLength     :: (Num i) => [b] -> i-strictGenericLength l   =  gl l 0-                        where-                           gl [] a     = a-                           gl (_:xs) a = let a' = a + 1 in a' `seq` gl xs a'---- | The 'genericTake' function is an overloaded version of 'take', which--- accepts any 'Integral' value as the number of elements to take.-genericTake             :: (Integral i) => i -> [a] -> [a]-genericTake n _ | n <= 0 = []-genericTake _ []        =  []-genericTake n (x:xs)    =  x : genericTake (n-1) xs---- | The 'genericDrop' function is an overloaded version of 'drop', which--- accepts any 'Integral' value as the number of elements to drop.-genericDrop             :: (Integral i) => i -> [a] -> [a]-genericDrop n xs | n <= 0 = xs-genericDrop _ []        =  []-genericDrop n (_:xs)    =  genericDrop (n-1) xs----- | The 'genericSplitAt' function is an overloaded version of 'splitAt', which--- accepts any 'Integral' value as the position at which to split.-genericSplitAt          :: (Integral i) => i -> [a] -> ([a], [a])-genericSplitAt n xs | n <= 0 =  ([],xs)-genericSplitAt _ []     =  ([],[])-genericSplitAt n (x:xs) =  (x:xs',xs'') where-    (xs',xs'') = genericSplitAt (n-1) xs---- | The 'genericIndex' function is an overloaded version of '!!', which--- accepts any 'Integral' value as the index.-genericIndex :: (Integral i) => [a] -> i -> a-genericIndex (x:_)  0 = x-genericIndex (_:xs) n- | n > 0     = genericIndex xs (n-1)- | otherwise = error "List.genericIndex: negative argument."-genericIndex _ _      = error "List.genericIndex: index too large."---- | The 'genericReplicate' function is an overloaded version of 'replicate',--- which accepts any 'Integral' value as the number of repetitions to make.-genericReplicate        :: (Integral i) => i -> a -> [a]-genericReplicate n x    =  genericTake n (repeat x)---- | The 'zip4' function takes four lists and returns a list of--- quadruples, analogous to 'zip'.-zip4                    :: [a] -> [b] -> [c] -> [d] -> [(a,b,c,d)]-zip4                    =  zipWith4 (,,,)---- | The 'zip5' function takes five lists and returns a list of--- five-tuples, analogous to 'zip'.-zip5                    :: [a] -> [b] -> [c] -> [d] -> [e] -> [(a,b,c,d,e)]-zip5                    =  zipWith5 (,,,,)---- | The 'zip6' function takes six lists and returns a list of six-tuples,--- analogous to 'zip'.-zip6                    :: [a] -> [b] -> [c] -> [d] -> [e] -> [f] ->-                              [(a,b,c,d,e,f)]-zip6                    =  zipWith6 (,,,,,)---- | The 'zip7' function takes seven lists and returns a list of--- seven-tuples, analogous to 'zip'.-zip7                    :: [a] -> [b] -> [c] -> [d] -> [e] -> [f] ->-                              [g] -> [(a,b,c,d,e,f,g)]-zip7                    =  zipWith7 (,,,,,,)---- | The 'zipWith4' function takes a function which combines four--- elements, as well as four lists and returns a list of their point-wise--- combination, analogous to 'zipWith'.-zipWith4                :: (a->b->c->d->e) -> [a]->[b]->[c]->[d]->[e]-zipWith4 z (a:as) (b:bs) (c:cs) (d:ds)-                        =  z a b c d : zipWith4 z as bs cs ds-zipWith4 _ _ _ _ _      =  []---- | The 'zipWith5' function takes a function which combines five--- elements, as well as five lists and returns a list of their point-wise--- combination, analogous to 'zipWith'.-zipWith5                :: (a->b->c->d->e->f) ->-                           [a]->[b]->[c]->[d]->[e]->[f]-zipWith5 z (a:as) (b:bs) (c:cs) (d:ds) (e:es)-                        =  z a b c d e : zipWith5 z as bs cs ds es-zipWith5 _ _ _ _ _ _    = []---- | The 'zipWith6' function takes a function which combines six--- elements, as well as six lists and returns a list of their point-wise--- combination, analogous to 'zipWith'.-zipWith6                :: (a->b->c->d->e->f->g) ->-                           [a]->[b]->[c]->[d]->[e]->[f]->[g]-zipWith6 z (a:as) (b:bs) (c:cs) (d:ds) (e:es) (f:fs)-                        =  z a b c d e f : zipWith6 z as bs cs ds es fs-zipWith6 _ _ _ _ _ _ _  = []---- | The 'zipWith7' function takes a function which combines seven--- elements, as well as seven lists and returns a list of their point-wise--- combination, analogous to 'zipWith'.-zipWith7                :: (a->b->c->d->e->f->g->h) ->-                           [a]->[b]->[c]->[d]->[e]->[f]->[g]->[h]-zipWith7 z (a:as) (b:bs) (c:cs) (d:ds) (e:es) (f:fs) (g:gs)-                   =  z a b c d e f g : zipWith7 z as bs cs ds es fs gs-zipWith7 _ _ _ _ _ _ _ _ = []---- | The 'unzip4' function takes a list of quadruples and returns four--- lists, analogous to 'unzip'.-unzip4                  :: [(a,b,c,d)] -> ([a],[b],[c],[d])-unzip4                  =  foldr (\(a,b,c,d) ~(as,bs,cs,ds) ->-                                        (a:as,b:bs,c:cs,d:ds))-                                 ([],[],[],[])---- | The 'unzip5' function takes a list of five-tuples and returns five--- lists, analogous to 'unzip'.-unzip5                  :: [(a,b,c,d,e)] -> ([a],[b],[c],[d],[e])-unzip5                  =  foldr (\(a,b,c,d,e) ~(as,bs,cs,ds,es) ->-                                        (a:as,b:bs,c:cs,d:ds,e:es))-                                 ([],[],[],[],[])---- | The 'unzip6' function takes a list of six-tuples and returns six--- lists, analogous to 'unzip'.-unzip6                  :: [(a,b,c,d,e,f)] -> ([a],[b],[c],[d],[e],[f])-unzip6                  =  foldr (\(a,b,c,d,e,f) ~(as,bs,cs,ds,es,fs) ->-                                        (a:as,b:bs,c:cs,d:ds,e:es,f:fs))-                                 ([],[],[],[],[],[])---- | The 'unzip7' function takes a list of seven-tuples and returns--- seven lists, analogous to 'unzip'.-unzip7          :: [(a,b,c,d,e,f,g)] -> ([a],[b],[c],[d],[e],[f],[g])-unzip7          =  foldr (\(a,b,c,d,e,f,g) ~(as,bs,cs,ds,es,fs,gs) ->-                                (a:as,b:bs,c:cs,d:ds,e:es,f:fs,g:gs))-                         ([],[],[],[],[],[],[])----- | The 'deleteFirstsBy' function takes a predicate and two lists and--- returns the first list with the first occurrence of each element of--- the second list removed.-deleteFirstsBy          :: (a -> a -> Bool) -> [a] -> [a] -> [a]-deleteFirstsBy eq       =  foldl (flip (deleteBy eq))---- | The 'group' function takes a list and returns a list of lists such--- that the concatenation of the result is equal to the argument.  Moreover,--- each sublist in the result contains only equal elements.  For example,------ > group "Mississippi" = ["M","i","ss","i","ss","i","pp","i"]------ It is a special case of 'groupBy', which allows the programmer to supply--- their own equality test.-group                   :: Eq a => [a] -> [[a]]-group                   =  groupBy (==)---- | The 'groupBy' function is the non-overloaded version of 'group'.-groupBy                 :: (a -> a -> Bool) -> [a] -> [[a]]-groupBy _  []           =  []-groupBy eq (x:xs)       =  (x:ys) : groupBy eq zs-                           where (ys,zs) = span (eq x) xs---- | The 'inits' function returns all initial segments of the argument,--- shortest first.  For example,------ > inits "abc" == ["","a","ab","abc"]------ Note that 'inits' has the following strictness property:--- @inits (xs ++ _|_) = inits xs ++ _|_@------ In particular,--- @inits _|_ = [] : _|_@-inits                   :: [a] -> [[a]]-inits                   = map toListSB . scanl' snocSB emptySB-{-# NOINLINE inits #-}---- We do not allow inits to inline, because it plays havoc with Call Arity--- if it fuses with a consumer, and it would generally lead to serious--- loss of sharing if allowed to fuse with a producer.---- | A strictly accumulating version of 'scanl'-{-# NOINLINE [1] scanl' #-}-scanl'           :: (b -> a -> b) -> b -> [a] -> [b]--- This peculiar form is needed to prevent scanl' from being rewritten--- in its own right hand side.-scanl' = scanlGo'-  where-    scanlGo' :: (b -> a -> b) -> b -> [a] -> [b]-    scanlGo' f !q ls    = q : (case ls of-                            []   -> []-                            x:xs -> scanlGo' f (f q x) xs)---- | The 'tails' function returns all final segments of the argument,--- longest first.  For example,------ > tails "abc" == ["abc", "bc", "c",""]------ Note that 'tails' has the following strictness property:--- @tails _|_ = _|_ : _|_@-tails                   :: [a] -> [[a]]-tails xs                =  xs : case xs of-                                  []      -> []-                                  _ : xs' -> tails xs'---- | The 'subsequences' function returns the list of all subsequences of the argument.------ > subsequences "abc" == ["","a","b","ab","c","ac","bc","abc"]-subsequences            :: [a] -> [[a]]-subsequences xs         =  [] : nonEmptySubsequences xs---- | The 'nonEmptySubsequences' function returns the list of all subsequences of the argument,---   except for the empty list.------ > nonEmptySubsequences "abc" == ["a","b","ab","c","ac","bc","abc"]-nonEmptySubsequences         :: [a] -> [[a]]-nonEmptySubsequences []      =  []-nonEmptySubsequences (x:xs)  =  [x] : foldr f [] (nonEmptySubsequences xs)-  where f ys r = ys : (x : ys) : r----- | The 'permutations' function returns the list of all permutations of the argument.------ > permutations "abc" == ["abc","bac","cba","bca","cab","acb"]-permutations            :: [a] -> [[a]]-permutations xs0        =  xs0 : perms xs0 []-  where-    perms []     _  = []-    perms (t:ts) is = foldr interleave (perms ts (t:is)) (permutations is)-      where interleave    xs     r = let (_,zs) = interleave' id xs r in zs-            interleave' _ []     r = (ts, r)-            interleave' f (y:ys) r = let (us,zs) = interleave' (f . (y:)) ys r-                                     in  (y:us, f (t:y:us) : zs)------------------------------------------------------------------------------------ Quick Sort algorithm taken from HBC's QSort library.---- | The 'sort' function implements a stable sorting algorithm.--- It is a special case of 'sortBy', which allows the programmer to supply--- their own comparison function.-sort :: (Ord a) => [a] -> [a]---- | The 'sortBy' function is the non-overloaded version of 'sort'.-sortBy :: (a -> a -> Ordering) -> [a] -> [a]--#ifdef USE_REPORT_PRELUDE-sort = sortBy compare-sortBy cmp = foldr (insertBy cmp) []-#else--{--GHC's mergesort replaced by a better implementation, 24/12/2009.-This code originally contributed to the nhc12 compiler by Thomas Nordin-in 2002.  Rumoured to have been based on code by Lennart Augustsson, e.g.-    http://www.mail-archive.com/haskell@haskell.org/msg01822.html-and possibly to bear similarities to a 1982 paper by Richard O'Keefe:-"A smooth applicative merge sort".--Benchmarks show it to be often 2x the speed of the previous implementation.-Fixes ticket http://hackage.haskell.org/trac/ghc/ticket/2143--}--sort = sortBy compare-sortBy cmp = mergeAll . sequences-  where-    sequences (a:b:xs)-      | a `cmp` b == GT = descending b [a]  xs-      | otherwise       = ascending  b (a:) xs-    sequences xs = [xs]--    descending a as (b:bs)-      | a `cmp` b == GT = descending b (a:as) bs-    descending a as bs  = (a:as): sequences bs--    ascending a as (b:bs)-      | a `cmp` b /= GT = ascending b (\ys -> as (a:ys)) bs-    ascending a as bs   = as [a]: sequences bs--    mergeAll [x] = x-    mergeAll xs  = mergeAll (mergePairs xs)--    mergePairs (a:b:xs) = merge a b: mergePairs xs-    mergePairs xs       = xs--    merge as@(a:as') bs@(b:bs')-      | a `cmp` b == GT = b:merge as  bs'-      | otherwise       = a:merge as' bs-    merge [] bs         = bs-    merge as []         = as--{--sortBy cmp l = mergesort cmp l-sort l = mergesort compare l--Quicksort replaced by mergesort, 14/5/2002.--From: Ian Lynagh <igloo@earth.li>--I am curious as to why the List.sort implementation in GHC is a-quicksort algorithm rather than an algorithm that guarantees n log n-time in the worst case? I have attached a mergesort implementation along-with a few scripts to time it's performance, the results of which are-shown below (* means it didn't finish successfully - in all cases this-was due to a stack overflow).--If I heap profile the random_list case with only 10000 then I see-random_list peaks at using about 2.5M of memory, whereas in the same-program using List.sort it uses only 100k.--Input style     Input length     Sort data     Sort alg    User time-stdin           10000            random_list   sort        2.82-stdin           10000            random_list   mergesort   2.96-stdin           10000            sorted        sort        31.37-stdin           10000            sorted        mergesort   1.90-stdin           10000            revsorted     sort        31.21-stdin           10000            revsorted     mergesort   1.88-stdin           100000           random_list   sort        *-stdin           100000           random_list   mergesort   *-stdin           100000           sorted        sort        *-stdin           100000           sorted        mergesort   *-stdin           100000           revsorted     sort        *-stdin           100000           revsorted     mergesort   *-func            10000            random_list   sort        0.31-func            10000            random_list   mergesort   0.91-func            10000            sorted        sort        19.09-func            10000            sorted        mergesort   0.15-func            10000            revsorted     sort        19.17-func            10000            revsorted     mergesort   0.16-func            100000           random_list   sort        3.85-func            100000           random_list   mergesort   *-func            100000           sorted        sort        5831.47-func            100000           sorted        mergesort   2.23-func            100000           revsorted     sort        5872.34-func            100000           revsorted     mergesort   2.24--mergesort :: (a -> a -> Ordering) -> [a] -> [a]-mergesort cmp = mergesort' cmp . map wrap--mergesort' :: (a -> a -> Ordering) -> [[a]] -> [a]-mergesort' _   [] = []-mergesort' _   [xs] = xs-mergesort' cmp xss = mergesort' cmp (merge_pairs cmp xss)--merge_pairs :: (a -> a -> Ordering) -> [[a]] -> [[a]]-merge_pairs _   [] = []-merge_pairs _   [xs] = [xs]-merge_pairs cmp (xs:ys:xss) = merge cmp xs ys : merge_pairs cmp xss--merge :: (a -> a -> Ordering) -> [a] -> [a] -> [a]-merge _   [] ys = ys-merge _   xs [] = xs-merge cmp (x:xs) (y:ys)- = case x `cmp` y of-        GT -> y : merge cmp (x:xs)   ys-        _  -> x : merge cmp    xs (y:ys)--wrap :: a -> [a]-wrap x = [x]----OLDER: qsort version---- qsort is stable and does not concatenate.-qsort :: (a -> a -> Ordering) -> [a] -> [a] -> [a]-qsort _   []     r = r-qsort _   [x]    r = x:r-qsort cmp (x:xs) r = qpart cmp x xs [] [] r---- qpart partitions and sorts the sublists-qpart :: (a -> a -> Ordering) -> a -> [a] -> [a] -> [a] -> [a] -> [a]-qpart cmp x [] rlt rge r =-    -- rlt and rge are in reverse order and must be sorted with an-    -- anti-stable sorting-    rqsort cmp rlt (x:rqsort cmp rge r)-qpart cmp x (y:ys) rlt rge r =-    case cmp x y of-        GT -> qpart cmp x ys (y:rlt) rge r-        _  -> qpart cmp x ys rlt (y:rge) r---- rqsort is as qsort but anti-stable, i.e. reverses equal elements-rqsort :: (a -> a -> Ordering) -> [a] -> [a] -> [a]-rqsort _   []     r = r-rqsort _   [x]    r = x:r-rqsort cmp (x:xs) r = rqpart cmp x xs [] [] r+import Data.Foldable+import Data.Traversable -rqpart :: (a -> a -> Ordering) -> a -> [a] -> [a] -> [a] -> [a] -> [a]-rqpart cmp x [] rle rgt r =-    qsort cmp rle (x:qsort cmp rgt r)-rqpart cmp x (y:ys) rle rgt r =-    case cmp y x of-        GT -> rqpart cmp x ys rle (y:rgt) r-        _  -> rqpart cmp x ys (y:rle) rgt r--}+import Data.OldList hiding ( all, and, any, concat, concatMap, elem, find,+                             foldl, foldl1, foldl', foldr, foldr1, mapAccumL,+                             mapAccumR, maximum, maximumBy, minimum, minimumBy,+                             length, notElem, null, or, product, sum ) -#endif /* USE_REPORT_PRELUDE */+import GHC.Base ( Bool(..), Eq((==)), otherwise ) --- | The 'unfoldr' function is a \`dual\' to 'foldr': while 'foldr'--- reduces a list to a summary value, 'unfoldr' builds a list from--- a seed value.  The function takes the element and returns 'Nothing'--- if it is done producing the list or returns 'Just' @(a,b)@, in which--- case, @a@ is a prepended to the list and @b@ is used as the next--- element in a recursive call.  For example,------ > iterate f == unfoldr (\x -> Just (x, f x))------ In some cases, 'unfoldr' can undo a 'foldr' operation:------ > unfoldr f' (foldr f z xs) == xs------ if the following holds:+-- | The 'isSubsequenceOf' function takes two lists and returns 'True' if the+-- first list is a subsequence of the second list. ----- > f' (f x y) = Just (x,y)--- > f' z       = Nothing+-- @'isSubsequenceOf' x y@ is equivalent to @'elem' x ('subsequences' y)@. ----- A simple use of unfoldr:+-- @since 4.8.0.0 ----- > unfoldr (\b -> if b == 0 then Nothing else Just (b, b-1)) 10--- >  [10,9,8,7,6,5,4,3,2,1]+-- ==== __Examples__ ---unfoldr      :: (b -> Maybe (a, b)) -> b -> [a]-unfoldr f b  =-  case f b of-   Just (a,new_b) -> a : unfoldr f new_b-   Nothing        -> []---- --------------------------------------------------------------------------------- | A strict version of 'foldl'.-foldl'           :: (b -> a -> b) -> b -> [a] -> b-foldl' f z0 xs0 = lgo z0 xs0-    where lgo z []     = z-          lgo z (x:xs) = let z' = f z x in z' `seq` lgo z' xs---- | 'foldl1' is a variant of 'foldl' that has no starting value argument,--- and thus must be applied to non-empty lists.-foldl1                  :: (a -> a -> a) -> [a] -> a-foldl1 f (x:xs)         =  foldl f x xs-foldl1 _ []             =  errorEmptyList "foldl1"---- | A strict version of 'foldl1'-foldl1'                  :: (a -> a -> a) -> [a] -> a-foldl1' f (x:xs)         =  foldl' f x xs-foldl1' _ []             =  errorEmptyList "foldl1'"---- -------------------------------------------------------------------------------- List sum and product--{-# SPECIALISE sum     :: [Int] -> Int #-}-{-# SPECIALISE sum     :: [Integer] -> Integer #-}-{-# INLINABLE sum #-}-{-# SPECIALISE product :: [Int] -> Int #-}-{-# SPECIALISE product :: [Integer] -> Integer #-}-{-# INLINABLE product #-}--- We make 'sum' and 'product' inlinable so that we get specialisations--- at other types.  See, for example, Trac #7507.---- | The 'sum' function computes the sum of a finite list of numbers.-sum                     :: (Num a) => [a] -> a--- | The 'product' function computes the product of a finite list of numbers.-product                 :: (Num a) => [a] -> a-#ifdef USE_REPORT_PRELUDE-sum                     =  foldl (+) 0-product                 =  foldl (*) 1-#else-sum     l       = sum' l 0-  where-    sum' []     a = a-    sum' (x:xs) a = sum' xs (a+x)-product l       = prod l 1-  where-    prod []     a = a-    prod (x:xs) a = prod xs (a*x)-#endif---- -------------------------------------------------------------------------------- Functions on strings---- | 'lines' breaks a string up into a list of strings at newline--- characters.  The resulting strings do not contain newlines.-lines                   :: String -> [String]-lines ""                =  []--- Somehow GHC doesn't detect the selector thunks in the below code,--- so s' keeps a reference to the first line via the pair and we have--- a space leak (cf. #4334).--- So we need to make GHC see the selector thunks with a trick.-lines s                 =  cons (case break (== '\n') s of-                                    (l, s') -> (l, case s' of-                                                    []      -> []-                                                    _:s''   -> lines s''))-  where-    cons ~(h, t)        =  h : t---- | 'unlines' is an inverse operation to 'lines'.--- It joins lines, after appending a terminating newline to each.-unlines                 :: [String] -> String-#ifdef USE_REPORT_PRELUDE-unlines                 =  concatMap (++ "\n")-#else--- HBC version (stolen)--- here's a more efficient version-unlines [] = []-unlines (l:ls) = l ++ '\n' : unlines ls-#endif---- | 'words' breaks a string up into a list of words, which were delimited--- by white space.-words                   :: String -> [String]-words s                 =  case dropWhile {-partain:Char.-}isSpace s of-                                "" -> []-                                s' -> w : words s''-                                      where (w, s'') =-                                             break {-partain:Char.-}isSpace s'---- | 'unwords' is an inverse operation to 'words'.--- It joins words with separating spaces.-unwords                 :: [String] -> String-#ifdef USE_REPORT_PRELUDE-unwords []              =  ""-unwords ws              =  foldr1 (\w s -> w ++ ' ':s) ws-#else--- HBC version (stolen)--- here's a more efficient version-unwords []              =  ""-unwords [w]             = w-unwords (w:ws)          = w ++ ' ' : unwords ws-#endif--{- A "SnocBuilder" is a version of Chris Okasaki's banker's queue that supports-toListSB instead of uncons. In single-threaded use, its performance-characteristics are similar to John Hughes's functional difference lists, but-likely somewhat worse. In heavily persistent settings, however, it does much-better, because it takes advantage of sharing. The banker's queue guarantees-(amortized) O(1) snoc and O(1) uncons, meaning that we can think of toListSB as-an O(1) conversion to a list-like structure a constant factor slower than-normal lists--we pay the O(n) cost incrementally as we consume the list. Using-functional difference lists, on the other hand, we would have to pay the whole-cost up front for each output list. -}--{- We store a front list, a rear list, and the length of the queue.  Because we-only snoc onto the queue and never uncons, we know it's time to rotate when the-length of the queue plus 1 is a power of 2. Note that we rely on the value of-the length field only for performance.  In the unlikely event of overflow, the-performance will suffer but the semantics will remain correct.  -}--data SnocBuilder a = SnocBuilder {-# UNPACK #-} !Word [a] [a]--{- Smart constructor that rotates the builder when lp is one minus a power of-2. Does not rotate very small builders because doing so is not worth the-trouble. The lp < 255 test goes first because the power-of-2 test gives awful-branch prediction for very small n (there are 5 powers of 2 between 1 and-16). Putting the well-predicted lp < 255 test first avoids branching on the-power-of-2 test until powers of 2 have become sufficiently rare to be predicted-well. -}--{-# INLINE sb #-}-sb :: Word -> [a] -> [a] -> SnocBuilder a-sb lp f r-  | lp < 255 || (lp .&. (lp + 1)) /= 0 = SnocBuilder lp f r-  | otherwise                          = SnocBuilder lp (f ++ reverse r) []---- The empty builder--emptySB :: SnocBuilder a-emptySB = SnocBuilder 0 [] []---- Add an element to the end of a queue.--snocSB :: SnocBuilder a -> a -> SnocBuilder a-snocSB (SnocBuilder lp f r) x = sb (lp + 1) f (x:r)---- Convert a builder to a list--toListSB :: SnocBuilder a -> [a]-toListSB (SnocBuilder _ f r) = f ++ reverse r+-- >>> isSubsequenceOf "GHC" "The Glorious Haskell Compiler"+-- True+-- >>> isSubsequenceOf ['a','d'..'z'] ['a'..'z']+-- True+-- >>> isSubsequenceOf [1..10] [10,9..0]+-- False+isSubsequenceOf :: (Eq a) => [a] -> [a] -> Bool+isSubsequenceOf []    _                    = True+isSubsequenceOf _     []                   = False+isSubsequenceOf a@(x:a') (y:b) | x == y    = isSubsequenceOf a' b+                               | otherwise = isSubsequenceOf a b
Data/Maybe.hs view
@@ -6,7 +6,7 @@ -- Module      :  Data.Maybe -- Copyright   :  (c) The University of Glasgow 2001 -- License     :  BSD-style (see the file libraries/base/LICENSE)--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  stable -- Portability :  portable@@ -33,35 +33,9 @@  import GHC.Base --- ------------------------------------------------------------------------------ The Maybe type, and instances---- | The 'Maybe' type encapsulates an optional value.  A value of type--- @'Maybe' a@ either contains a value of type @a@ (represented as @'Just' a@), --- or it is empty (represented as 'Nothing').  Using 'Maybe' is a good way to --- deal with errors or exceptional cases without resorting to drastic--- measures such as 'error'.------ The 'Maybe' type is also a monad.  It is a simple kind of error--- monad, where all errors are represented by 'Nothing'.  A richer--- error monad can be built using the 'Data.Either.Either' type.--data  Maybe a  =  Nothing | Just a-  deriving (Eq, Ord)--instance  Functor Maybe  where-    fmap _ Nothing       = Nothing-    fmap f (Just a)      = Just (f a)--instance  Monad Maybe  where-    (Just x) >>= k      = k x-    Nothing  >>= _      = Nothing--    (Just _) >>  k      = k-    Nothing  >>  _      = Nothing--    return              = Just-    fail _              = Nothing+-- $setup+-- Allow the use of some Prelude functions in doctests.+-- >>> import Prelude ( (*), odd, show, sum )  -- --------------------------------------------------------------------------- -- Functions over Maybe@@ -70,23 +44,105 @@ -- value.  If the 'Maybe' value is 'Nothing', the function returns the -- default value.  Otherwise, it applies the function to the value inside -- the 'Just' and returns the result.+--+-- ==== __Examples__+--+-- Basic usage:+--+-- >>> maybe False odd (Just 3)+-- True+--+-- >>> maybe False odd Nothing+-- False+--+-- Read an integer from a string using 'readMaybe'. If we succeed,+-- return twice the integer; that is, apply @(*2)@ to it. If instead+-- we fail to parse an integer, return @0@ by default:+--+-- >>> import Text.Read ( readMaybe )+-- >>> maybe 0 (*2) (readMaybe "5")+-- 10+-- >>> maybe 0 (*2) (readMaybe "")+-- 0+--+-- Apply 'show' to a @Maybe Int@. If we have @Just n@, we want to show+-- the underlying 'Int' @n@. But if we have 'Nothing', we return the+-- empty string instead of (for example) \"Nothing\":+--+-- >>> maybe "" show (Just 5)+-- "5"+-- >>> maybe "" show Nothing+-- ""+-- maybe :: b -> (a -> b) -> Maybe a -> b maybe n _ Nothing  = n maybe _ f (Just x) = f x  -- | The 'isJust' function returns 'True' iff its argument is of the -- form @Just _@.+--+-- ==== __Examples__+--+-- Basic usage:+--+-- >>> isJust (Just 3)+-- True+--+-- >>> isJust (Just ())+-- True+--+-- >>> isJust Nothing+-- False+--+-- Only the outer constructor is taken into consideration:+--+-- >>> isJust (Just Nothing)+-- True+-- isJust         :: Maybe a -> Bool isJust Nothing = False isJust _       = True  -- | The 'isNothing' function returns 'True' iff its argument is 'Nothing'.+--+-- ==== __Examples__+--+-- Basic usage:+--+-- >>> isNothing (Just 3)+-- False+--+-- >>> isNothing (Just ())+-- False+--+-- >>> isNothing Nothing+-- True+--+-- Only the outer constructor is taken into consideration:+--+-- >>> isNothing (Just Nothing)+-- False+-- isNothing         :: Maybe a -> Bool isNothing Nothing = True isNothing _       = False  -- | The 'fromJust' function extracts the element out of a 'Just' and -- throws an error if its argument is 'Nothing'.+--+-- ==== __Examples__+--+-- Basic usage:+--+-- >>> fromJust (Just 1)+-- 1+--+-- >>> 2 * (fromJust (Just 10))+-- 20+--+-- >>> 2 * (fromJust Nothing)+-- *** Exception: Maybe.fromJust: Nothing+-- fromJust          :: Maybe a -> a fromJust Nothing  = error "Maybe.fromJust: Nothing" -- yuck fromJust (Just x) = x@@ -94,31 +150,134 @@ -- | The 'fromMaybe' function takes a default value and and 'Maybe' -- value.  If the 'Maybe' is 'Nothing', it returns the default values; -- otherwise, it returns the value contained in the 'Maybe'.+--+-- ==== __Examples__+--+-- Basic usage:+--+-- >>> fromMaybe "" (Just "Hello, World!")+-- "Hello, World!"+--+-- >>> fromMaybe "" Nothing+-- ""+--+-- Read an integer from a string using 'readMaybe'. If we fail to+-- parse an integer, we want to return @0@ by default:+--+-- >>> import Text.Read ( readMaybe )+-- >>> fromMaybe 0 (readMaybe "5")+-- 5+-- >>> fromMaybe 0 (readMaybe "")+-- 0+-- fromMaybe     :: a -> Maybe a -> a fromMaybe d x = case x of {Nothing -> d;Just v  -> v}  -- | The 'maybeToList' function returns an empty list when given -- 'Nothing' or a singleton list when not given 'Nothing'.+--+-- ==== __Examples__+--+-- Basic usage:+--+-- >>> maybeToList (Just 7)+-- [7]+--+-- >>> maybeToList Nothing+-- []+--+-- One can use 'maybeToList' to avoid pattern matching when combined+-- with a function that (safely) works on lists:+--+-- >>> import Text.Read ( readMaybe )+-- >>> sum $ maybeToList (readMaybe "3")+-- 3+-- >>> sum $ maybeToList (readMaybe "")+-- 0+-- maybeToList            :: Maybe a -> [a] maybeToList  Nothing   = [] maybeToList  (Just x)  = [x]  -- | The 'listToMaybe' function returns 'Nothing' on an empty list -- or @'Just' a@ where @a@ is the first element of the list.+--+-- ==== __Examples__+--+-- Basic usage:+--+-- >>> listToMaybe []+-- Nothing+--+-- >>> listToMaybe [9]+-- Just 9+--+-- >>> listToMaybe [1,2,3]+-- Just 1+--+-- Composing 'maybeToList' with 'listToMaybe' should be the identity+-- on singleton/empty lists:+--+-- >>> maybeToList $ listToMaybe [5]+-- [5]+-- >>> maybeToList $ listToMaybe []+-- []+--+-- But not on lists with more than one element:+--+-- >>> maybeToList $ listToMaybe [1,2,3]+-- [1]+-- listToMaybe           :: [a] -> Maybe a listToMaybe []        =  Nothing listToMaybe (a:_)     =  Just a  -- | The 'catMaybes' function takes a list of 'Maybe's and returns--- a list of all the 'Just' values. +-- a list of all the 'Just' values.+--+-- ==== __Examples__+--+-- Basic usage:+--+-- >>> catMaybes [Just 1, Nothing, Just 3]+-- [1,3]+--+-- When constructing a list of 'Maybe' values, 'catMaybes' can be used+-- to return all of the \"success\" results (if the list is the result+-- of a 'map', then 'mapMaybe' would be more appropriate):+--+-- >>> import Text.Read ( readMaybe )+-- >>> [readMaybe x :: Maybe Int | x <- ["1", "Foo", "3"] ]+-- [Just 1,Nothing,Just 3]+-- >>> catMaybes $ [readMaybe x :: Maybe Int | x <- ["1", "Foo", "3"] ]+-- [1,3]+-- catMaybes              :: [Maybe a] -> [a] catMaybes ls = [x | Just x <- ls]  -- | The 'mapMaybe' function is a version of 'map' which can throw -- out elements.  In particular, the functional argument returns -- something of type @'Maybe' b@.  If this is 'Nothing', no element--- is added on to the result list.  If it just @'Just' b@, then @b@ is+-- is added on to the result list.  If it is @'Just' b@, then @b@ is -- included in the result list.+--+-- ==== __Examples__+--+-- Using @'mapMaybe' f x@ is a shortcut for @'catMaybes' $ 'map' f x@+-- in most cases:+--+-- >>> import Text.Read ( readMaybe )+-- >>> let readMaybeInt = readMaybe :: String -> Maybe Int+-- >>> mapMaybe readMaybeInt ["1", "Foo", "3"]+-- [1,3]+-- >>> catMaybes $ map readMaybeInt ["1", "Foo", "3"]+-- [1,3]+--+-- If we map the 'Just' constructor, the entire list should be returned:+--+-- >>> mapMaybe Just [1,2,3]+-- [1,2,3]+-- mapMaybe          :: (a -> Maybe b) -> [a] -> [b] mapMaybe _ []     = [] mapMaybe f (x:xs) =
Data/Monoid.hs view
@@ -3,6 +3,8 @@ {-# LANGUAGE AutoDeriveTypeable #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE PolyKinds #-}+{-# LANGUAGE ScopedTypeVariables #-}  ----------------------------------------------------------------------------- -- |@@ -21,21 +23,23 @@ -----------------------------------------------------------------------------  module Data.Monoid (-        -- * Monoid typeclass+        -- * 'Monoid' typeclass         Monoid(..),         (<>),         Dual(..),         Endo(..),-        -- * Bool wrappers+        -- * 'Bool' wrappers         All(..),         Any(..),-        -- * Num wrappers+        -- * 'Num' wrappers         Sum(..),         Product(..),-        -- * Maybe wrappers+        -- * 'Maybe' wrappers         -- $MaybeExamples         First(..),-        Last(..)+        Last(..),+        -- * 'Alternative' wrapper+        Alt (..)   ) where  -- Push down the module in the dependency hierarchy.@@ -45,8 +49,6 @@ import GHC.Read import GHC.Show import GHC.Generics-import Data.Maybe-import Data.Proxy  {- -- just for testing@@ -54,103 +56,18 @@ import Test.QuickCheck -- -} --- ------------------------------------------------------------------------------ | The class of monoids (types with an associative binary operation that--- has an identity).  Instances should satisfy the following laws:------  * @mappend mempty x = x@------  * @mappend x mempty = x@------  * @mappend x (mappend y z) = mappend (mappend x y) z@------  * @mconcat = 'foldr' mappend mempty@------ The method names refer to the monoid of lists under concatenation,--- but there are many other instances.------ Minimal complete definition: 'mempty' and 'mappend'.------ Some types can be viewed as a monoid in more than one way,--- e.g. both addition and multiplication on numbers.--- In such cases we often define @newtype@s and make those instances--- of 'Monoid', e.g. 'Sum' and 'Product'.--class Monoid a where-        mempty  :: a-        -- ^ Identity of 'mappend'-        mappend :: a -> a -> a-        -- ^ An associative operation-        mconcat :: [a] -> a--        -- ^ Fold a list using the monoid.-        -- For most types, the default definition for 'mconcat' will be-        -- used, but the function is included in the class definition so-        -- that an optimized version can be provided for specific types.--        mconcat = foldr mappend mempty- infixr 6 <>  -- | An infix synonym for 'mappend'. ----- /Since: 4.5.0.0/+-- @since 4.5.0.0 (<>) :: Monoid m => m -> m -> m (<>) = mappend {-# INLINE (<>) #-}  -- Monoid instances. -instance Monoid [a] where-        mempty  = []-        mappend = (++)--instance Monoid b => Monoid (a -> b) where-        mempty _ = mempty-        mappend f g x = f x `mappend` g x--instance Monoid () where-        -- Should it be strict?-        mempty        = ()-        _ `mappend` _ = ()-        mconcat _     = ()--instance (Monoid a, Monoid b) => Monoid (a,b) where-        mempty = (mempty, mempty)-        (a1,b1) `mappend` (a2,b2) =-                (a1 `mappend` a2, b1 `mappend` b2)--instance (Monoid a, Monoid b, Monoid c) => Monoid (a,b,c) where-        mempty = (mempty, mempty, mempty)-        (a1,b1,c1) `mappend` (a2,b2,c2) =-                (a1 `mappend` a2, b1 `mappend` b2, c1 `mappend` c2)--instance (Monoid a, Monoid b, Monoid c, Monoid d) => Monoid (a,b,c,d) where-        mempty = (mempty, mempty, mempty, mempty)-        (a1,b1,c1,d1) `mappend` (a2,b2,c2,d2) =-                (a1 `mappend` a2, b1 `mappend` b2,-                 c1 `mappend` c2, d1 `mappend` d2)--instance (Monoid a, Monoid b, Monoid c, Monoid d, Monoid e) =>-                Monoid (a,b,c,d,e) where-        mempty = (mempty, mempty, mempty, mempty, mempty)-        (a1,b1,c1,d1,e1) `mappend` (a2,b2,c2,d2,e2) =-                (a1 `mappend` a2, b1 `mappend` b2, c1 `mappend` c2,-                 d1 `mappend` d2, e1 `mappend` e2)---- lexicographical ordering-instance Monoid Ordering where-        mempty         = EQ-        LT `mappend` _ = LT-        EQ `mappend` y = y-        GT `mappend` _ = GT--instance Monoid (Proxy s) where-    mempty = Proxy-    mappend _ _ = Proxy-    mconcat _ = Proxy---- | The dual of a monoid, obtained by swapping the arguments of 'mappend'.+-- | The dual of a 'Monoid', obtained by swapping the arguments of 'mappend'. newtype Dual a = Dual { getDual :: a }         deriving (Eq, Ord, Read, Show, Bounded, Generic, Generic1) @@ -166,7 +83,7 @@         mempty = Endo id         Endo f `mappend` Endo g = Endo (f . g) --- | Boolean monoid under conjunction.+-- | Boolean monoid under conjunction ('&&'). newtype All = All { getAll :: Bool }         deriving (Eq, Ord, Read, Show, Bounded, Generic) @@ -174,7 +91,7 @@         mempty = All True         All x `mappend` All y = All (x && y) --- | Boolean monoid under disjunction.+-- | Boolean monoid under disjunction ('||'). newtype Any = Any { getAny :: Bool }         deriving (Eq, Ord, Read, Show, Bounded, Generic) @@ -188,7 +105,8 @@  instance Num a => Monoid (Sum a) where         mempty = Sum 0-        Sum x `mappend` Sum y = Sum (x + y)+        mappend = coerce ((+) :: a -> a -> a)+--        Sum x `mappend` Sum y = Sum (x + y)  -- | Monoid under multiplication. newtype Product a = Product { getProduct :: a }@@ -196,7 +114,8 @@  instance Num a => Monoid (Product a) where         mempty = Product 1-        Product x `mappend` Product y = Product (x * y)+        mappend = coerce ((*) :: a -> a -> a)+--        Product x `mappend` Product y = Product (x * y)  -- $MaybeExamples -- To implement @find@ or @findLast@ on any 'Foldable':@@ -229,36 +148,43 @@ --      Just (combine key value oldValue)) -- @ --- | Lift a semigroup into 'Maybe' forming a 'Monoid' according to--- <http://en.wikipedia.org/wiki/Monoid>: \"Any semigroup @S@ may be--- turned into a monoid simply by adjoining an element @e@ not in @S@--- and defining @e*e = e@ and @e*s = s = s*e@ for all @s ∈ S@.\" Since--- there is no \"Semigroup\" typeclass providing just 'mappend', we--- use 'Monoid' instead.-instance Monoid a => Monoid (Maybe a) where-  mempty = Nothing-  Nothing `mappend` m = m-  m `mappend` Nothing = m-  Just m1 `mappend` Just m2 = Just (m1 `mappend` m2) - -- | Maybe monoid returning the leftmost non-Nothing value.+--+-- @'First' a@ is isomorphic to @'Alt' 'Maybe' a@, but precedes it+-- historically. newtype First a = First { getFirst :: Maybe a }-        deriving (Eq, Ord, Read, Show, Generic, Generic1)+        deriving (Eq, Ord, Read, Show, Generic, Generic1,+                  Functor, Applicative, Monad)  instance Monoid (First a) where         mempty = First Nothing-        r@(First (Just _)) `mappend` _ = r         First Nothing `mappend` r = r+        l `mappend` _             = l  -- | Maybe monoid returning the rightmost non-Nothing value.+--+-- @'Last' a@ is isomorphic to @'Dual' ('First' a)@, and thus to+-- @'Dual' ('Alt' 'Maybe' a)@ newtype Last a = Last { getLast :: Maybe a }-        deriving (Eq, Ord, Read, Show, Generic, Generic1)+        deriving (Eq, Ord, Read, Show, Generic, Generic1,+                  Functor, Applicative, Monad)  instance Monoid (Last a) where         mempty = Last Nothing-        _ `mappend` r@(Last (Just _)) = r-        r `mappend` Last Nothing = r+        l `mappend` Last Nothing = l+        _ `mappend` r            = r++-- | Monoid under '<|>'.+--+-- @since 4.8.0.0+newtype Alt f a = Alt {getAlt :: f a}+  deriving (Generic, Generic1, Read, Show, Eq, Ord, Num, Enum,+            Monad, MonadPlus, Applicative, Alternative, Functor)++instance forall f a . Alternative f => Monoid (Alt f a) where+        mempty = Alt empty+        mappend = coerce ((<|>) :: f a -> f a -> f a)  {- {--------------------------------------------------------------------
+ Data/OldList.hs view
@@ -0,0 +1,1179 @@+{-# LANGUAGE Trustworthy #-}+{-# LANGUAGE CPP, NoImplicitPrelude, ScopedTypeVariables, MagicHash #-}++-----------------------------------------------------------------------------+-- |+-- Module      :  Data.List+-- Copyright   :  (c) The University of Glasgow 2001+-- License     :  BSD-style (see the file libraries/base/LICENSE)+--+-- Maintainer  :  libraries@haskell.org+-- Stability   :  stable+-- Portability :  portable+--+-- Operations on lists.+--+-----------------------------------------------------------------------------++module Data.OldList+   (+   -- * Basic functions++     (++)+   , head+   , last+   , tail+   , init+   , uncons+   , null+   , length++   -- * List transformations+   , map+   , reverse++   , intersperse+   , intercalate+   , transpose++   , subsequences+   , permutations++   -- * Reducing lists (folds)++   , foldl+   , foldl'+   , foldl1+   , foldl1'+   , foldr+   , foldr1++   -- ** Special folds++   , concat+   , concatMap+   , and+   , or+   , any+   , all+   , sum+   , product+   , maximum+   , minimum++   -- * Building lists++   -- ** Scans+   , scanl+   , scanl'+   , scanl1+   , scanr+   , scanr1++   -- ** Accumulating maps+   , mapAccumL+   , mapAccumR++   -- ** Infinite lists+   , iterate+   , repeat+   , replicate+   , cycle++   -- ** Unfolding+   , unfoldr++   -- * Sublists++   -- ** Extracting sublists+   , take+   , drop+   , splitAt++   , takeWhile+   , dropWhile+   , dropWhileEnd+   , span+   , break++   , stripPrefix++   , group++   , inits+   , tails++   -- ** Predicates+   , isPrefixOf+   , isSuffixOf+   , isInfixOf++   -- * Searching lists++   -- ** Searching by equality+   , elem+   , notElem+   , lookup++   -- ** Searching with a predicate+   , find+   , filter+   , partition++   -- * Indexing lists+   -- | These functions treat a list @xs@ as a indexed collection,+   -- with indices ranging from 0 to @'length' xs - 1@.++   , (!!)++   , elemIndex+   , elemIndices++   , findIndex+   , findIndices++   -- * Zipping and unzipping lists++   , zip+   , zip3+   , zip4, zip5, zip6, zip7++   , zipWith+   , zipWith3+   , zipWith4, zipWith5, zipWith6, zipWith7++   , unzip+   , unzip3+   , unzip4, unzip5, unzip6, unzip7++   -- * Special lists++   -- ** Functions on strings+   , lines+   , words+   , unlines+   , unwords++   -- ** \"Set\" operations++   , nub++   , delete+   , (\\)++   , union+   , intersect++   -- ** Ordered lists+   , sort+   , sortOn+   , insert++   -- * Generalized functions++   -- ** The \"@By@\" operations+   -- | By convention, overloaded functions have a non-overloaded+   -- counterpart whose name is suffixed with \`@By@\'.+   --+   -- It is often convenient to use these functions together with+   -- 'Data.Function.on', for instance @'sortBy' ('compare'+   -- \`on\` 'fst')@.++   -- *** User-supplied equality (replacing an @Eq@ context)+   -- | The predicate is assumed to define an equivalence.+   , nubBy+   , deleteBy+   , deleteFirstsBy+   , unionBy+   , intersectBy+   , groupBy++   -- *** User-supplied comparison (replacing an @Ord@ context)+   -- | The function is assumed to define a total ordering.+   , sortBy+   , insertBy+   , maximumBy+   , minimumBy++   -- ** The \"@generic@\" operations+   -- | The prefix \`@generic@\' indicates an overloaded function that+   -- is a generalized version of a "Prelude" function.++   , genericLength+   , genericTake+   , genericDrop+   , genericSplitAt+   , genericIndex+   , genericReplicate++   ) where++import Data.Maybe+import Data.Bits        ( (.&.) )+import Data.Char        ( isSpace )+import Data.Ord         ( comparing )+import Data.Tuple       ( fst, snd )++import GHC.Num+import GHC.Real+import GHC.List+import GHC.Base++infix 5 \\ -- comment to fool cpp: https://www.haskell.org/ghc/docs/latest/html/users_guide/options-phases.html#cpp-string-gaps++-- -----------------------------------------------------------------------------+-- List functions++-- | The 'dropWhileEnd' function drops the largest suffix of a list+-- in which the given predicate holds for all elements.  For example:+--+-- > dropWhileEnd isSpace "foo\n" == "foo"+-- > dropWhileEnd isSpace "foo bar" == "foo bar"+-- > dropWhileEnd isSpace ("foo\n" ++ undefined) == "foo" ++ undefined+--+-- @since 4.5.0.0+dropWhileEnd :: (a -> Bool) -> [a] -> [a]+dropWhileEnd p = foldr (\x xs -> if p x && null xs then [] else x : xs) []++-- | The 'stripPrefix' function drops the given prefix from a list.+-- It returns 'Nothing' if the list did not start with the prefix+-- given, or 'Just' the list after the prefix, if it does.+--+-- > stripPrefix "foo" "foobar" == Just "bar"+-- > stripPrefix "foo" "foo" == Just ""+-- > stripPrefix "foo" "barfoo" == Nothing+-- > stripPrefix "foo" "barfoobaz" == Nothing+stripPrefix :: Eq a => [a] -> [a] -> Maybe [a]+stripPrefix [] ys = Just ys+stripPrefix (x:xs) (y:ys)+ | x == y = stripPrefix xs ys+stripPrefix _ _ = Nothing++-- | The 'elemIndex' function returns the index of the first element+-- in the given list which is equal (by '==') to the query element,+-- or 'Nothing' if there is no such element.+elemIndex       :: Eq a => a -> [a] -> Maybe Int+elemIndex x     = findIndex (x==)++-- | The 'elemIndices' function extends 'elemIndex', by returning the+-- indices of all elements equal to the query element, in ascending order.+elemIndices     :: Eq a => a -> [a] -> [Int]+elemIndices x   = findIndices (x==)++-- | The 'find' function takes a predicate and a list and returns the+-- first element in the list matching the predicate, or 'Nothing' if+-- there is no such element.+find            :: (a -> Bool) -> [a] -> Maybe a+find p          = listToMaybe . filter p++-- | The 'findIndex' function takes a predicate and a list and returns+-- the index of the first element in the list satisfying the predicate,+-- or 'Nothing' if there is no such element.+findIndex       :: (a -> Bool) -> [a] -> Maybe Int+findIndex p     = listToMaybe . findIndices p++-- | The 'findIndices' function extends 'findIndex', by returning the+-- indices of all elements satisfying the predicate, in ascending order.+findIndices      :: (a -> Bool) -> [a] -> [Int]+#ifdef USE_REPORT_PRELUDE+findIndices p xs = [ i | (x,i) <- zip xs [0..], p x]+#else+-- Efficient definition, adapted from Data.Sequence+{-# INLINE findIndices #-}+findIndices p ls = build $ \c n ->+  let go x r k | p x       = I# k `c` r (k +# 1#)+               | otherwise = r (k +# 1#)+  in foldr go (\_ -> n) ls 0#+#endif  /* USE_REPORT_PRELUDE */++-- | The 'isPrefixOf' function takes two lists and returns 'True'+-- iff the first list is a prefix of the second.+isPrefixOf              :: (Eq a) => [a] -> [a] -> Bool+isPrefixOf [] _         =  True+isPrefixOf _  []        =  False+isPrefixOf (x:xs) (y:ys)=  x == y && isPrefixOf xs ys++-- | The 'isSuffixOf' function takes two lists and returns 'True' iff+-- the first list is a suffix of the second. The second list must be+-- finite.+isSuffixOf              :: (Eq a) => [a] -> [a] -> Bool+ns `isSuffixOf` hs      = maybe False id $ do+      delta <- dropLengthMaybe ns hs+      return $ ns == dropLength delta hs+      -- Since dropLengthMaybe ns hs succeeded, we know that (if hs is finite)+      -- length ns + length delta = length hs+      -- so dropping the length of delta from hs will yield a suffix exactly+      -- the length of ns.++-- A version of drop that drops the length of the first argument from the+-- second argument. If xs is longer than ys, xs will not be traversed in its+-- entirety.  dropLength is also generally faster than (drop . length)+-- Both this and dropLengthMaybe could be written as folds over their first+-- arguments, but this reduces clarity with no benefit to isSuffixOf.+dropLength :: [a] -> [b] -> [b]+dropLength [] y = y+dropLength _ [] = []+dropLength (_:x') (_:y') = dropLength x' y'++-- A version of dropLength that returns Nothing if the second list runs out of+-- elements before the first.+dropLengthMaybe :: [a] -> [b] -> Maybe [b]+dropLengthMaybe [] y = Just y+dropLengthMaybe _ [] = Nothing+dropLengthMaybe (_:x') (_:y') = dropLengthMaybe x' y'++-- | The 'isInfixOf' function takes two lists and returns 'True'+-- iff the first list is contained, wholly and intact,+-- anywhere within the second.+--+-- Example:+--+-- >isInfixOf "Haskell" "I really like Haskell." == True+-- >isInfixOf "Ial" "I really like Haskell." == False+isInfixOf               :: (Eq a) => [a] -> [a] -> Bool+isInfixOf needle haystack = any (isPrefixOf needle) (tails haystack)++-- | /O(n^2)/. The 'nub' function removes duplicate elements from a list.+-- In particular, it keeps only the first occurrence of each element.+-- (The name 'nub' means \`essence\'.)+-- It is a special case of 'nubBy', which allows the programmer to supply+-- their own equality test.+nub                     :: (Eq a) => [a] -> [a]+nub                     =  nubBy (==)++-- | The 'nubBy' function behaves just like 'nub', except it uses a+-- user-supplied equality predicate instead of the overloaded '=='+-- function.+nubBy                   :: (a -> a -> Bool) -> [a] -> [a]+#ifdef USE_REPORT_PRELUDE+nubBy eq []             =  []+nubBy eq (x:xs)         =  x : nubBy eq (filter (\ y -> not (eq x y)) xs)+#else+-- stolen from HBC+nubBy eq l              = nubBy' l []+  where+    nubBy' [] _         = []+    nubBy' (y:ys) xs+       | elem_by eq y xs = nubBy' ys xs+       | otherwise       = y : nubBy' ys (y:xs)++-- Not exported:+-- Note that we keep the call to `eq` with arguments in the+-- same order as in the reference (prelude) implementation,+-- and that this order is different from how `elem` calls (==).+-- See #2528, #3280 and #7913.+-- 'xs' is the list of things we've seen so far,+-- 'y' is the potential new element+elem_by :: (a -> a -> Bool) -> a -> [a] -> Bool+elem_by _  _ []         =  False+elem_by eq y (x:xs)     =  x `eq` y || elem_by eq y xs+#endif+++-- | 'delete' @x@ removes the first occurrence of @x@ from its list argument.+-- For example,+--+-- > delete 'a' "banana" == "bnana"+--+-- It is a special case of 'deleteBy', which allows the programmer to+-- supply their own equality test.++delete                  :: (Eq a) => a -> [a] -> [a]+delete                  =  deleteBy (==)++-- | The 'deleteBy' function behaves like 'delete', but takes a+-- user-supplied equality predicate.+deleteBy                :: (a -> a -> Bool) -> a -> [a] -> [a]+deleteBy _  _ []        = []+deleteBy eq x (y:ys)    = if x `eq` y then ys else y : deleteBy eq x ys++-- | The '\\' function is list difference (non-associative).+-- In the result of @xs@ '\\' @ys@, the first occurrence of each element of+-- @ys@ in turn (if any) has been removed from @xs@.  Thus+--+-- > (xs ++ ys) \\ xs == ys.+--+-- It is a special case of 'deleteFirstsBy', which allows the programmer+-- to supply their own equality test.++(\\)                    :: (Eq a) => [a] -> [a] -> [a]+(\\)                    =  foldl (flip delete)++-- | The 'union' function returns the list union of the two lists.+-- For example,+--+-- > "dog" `union` "cow" == "dogcw"+--+-- Duplicates, and elements of the first list, are removed from the+-- the second list, but if the first list contains duplicates, so will+-- the result.+-- It is a special case of 'unionBy', which allows the programmer to supply+-- their own equality test.++union                   :: (Eq a) => [a] -> [a] -> [a]+union                   = unionBy (==)++-- | The 'unionBy' function is the non-overloaded version of 'union'.+unionBy                 :: (a -> a -> Bool) -> [a] -> [a] -> [a]+unionBy eq xs ys        =  xs ++ foldl (flip (deleteBy eq)) (nubBy eq ys) xs++-- | The 'intersect' function takes the list intersection of two lists.+-- For example,+--+-- > [1,2,3,4] `intersect` [2,4,6,8] == [2,4]+--+-- If the first list contains duplicates, so will the result.+--+-- > [1,2,2,3,4] `intersect` [6,4,4,2] == [2,2,4]+--+-- It is a special case of 'intersectBy', which allows the programmer to+-- supply their own equality test. If the element is found in both the first+-- and the second list, the element from the first list will be used.++intersect               :: (Eq a) => [a] -> [a] -> [a]+intersect               =  intersectBy (==)++-- | The 'intersectBy' function is the non-overloaded version of 'intersect'.+intersectBy             :: (a -> a -> Bool) -> [a] -> [a] -> [a]+intersectBy _  [] _     =  []+intersectBy _  _  []    =  []+intersectBy eq xs ys    =  [x | x <- xs, any (eq x) ys]++-- | The 'intersperse' function takes an element and a list and+-- \`intersperses\' that element between the elements of the list.+-- For example,+--+-- > intersperse ',' "abcde" == "a,b,c,d,e"++intersperse             :: a -> [a] -> [a]+intersperse _   []      = []+intersperse sep (x:xs)  = x : prependToAll sep xs+++-- Not exported:+-- We want to make every element in the 'intersperse'd list available+-- as soon as possible to avoid space leaks. Experiments suggested that+-- a separate top-level helper is more efficient than a local worker.+prependToAll            :: a -> [a] -> [a]+prependToAll _   []     = []+prependToAll sep (x:xs) = sep : x : prependToAll sep xs++-- | 'intercalate' @xs xss@ is equivalent to @('concat' ('intersperse' xs xss))@.+-- It inserts the list @xs@ in between the lists in @xss@ and concatenates the+-- result.+intercalate :: [a] -> [[a]] -> [a]+intercalate xs xss = concat (intersperse xs xss)++-- | The 'transpose' function transposes the rows and columns of its argument.+-- For example,+--+-- > transpose [[1,2,3],[4,5,6]] == [[1,4],[2,5],[3,6]]+--+-- If some of the rows are shorter than the following rows, their elements are skipped:+--+-- > transpose [[10,11],[20],[],[30,31,32]] == [[10,20,30],[11,31],[32]]++transpose               :: [[a]] -> [[a]]+transpose []             = []+transpose ([]   : xss)   = transpose xss+transpose ((x:xs) : xss) = (x : [h | (h:_) <- xss]) : transpose (xs : [ t | (_:t) <- xss])+++-- | The 'partition' function takes a predicate a list and returns+-- the pair of lists of elements which do and do not satisfy the+-- predicate, respectively; i.e.,+--+-- > partition p xs == (filter p xs, filter (not . p) xs)++partition               :: (a -> Bool) -> [a] -> ([a],[a])+{-# INLINE partition #-}+partition p xs = foldr (select p) ([],[]) xs++select :: (a -> Bool) -> a -> ([a], [a]) -> ([a], [a])+select p x ~(ts,fs) | p x       = (x:ts,fs)+                    | otherwise = (ts, x:fs)++-- | The 'mapAccumL' function behaves like a combination of 'map' and+-- 'foldl'; it applies a function to each element of a list, passing+-- an accumulating parameter from left to right, and returning a final+-- value of this accumulator together with the new list.+mapAccumL :: (acc -> x -> (acc, y)) -- Function of elt of input list+                                    -- and accumulator, returning new+                                    -- accumulator and elt of result list+          -> acc            -- Initial accumulator+          -> [x]            -- Input list+          -> (acc, [y])     -- Final accumulator and result list+{-# NOINLINE [1] mapAccumL #-}+mapAccumL _ s []        =  (s, [])+mapAccumL f s (x:xs)    =  (s'',y:ys)+                           where (s', y ) = f s x+                                 (s'',ys) = mapAccumL f s' xs++{-# RULES+"mapAccumL" [~1] forall f s xs . mapAccumL f s xs = foldr (mapAccumLF f) pairWithNil xs s+"mapAccumLList" [1] forall f s xs . foldr (mapAccumLF f) pairWithNil xs s = mapAccumL f s xs+ #-}++pairWithNil :: acc -> (acc, [y])+{-# INLINE [0] pairWithNil #-}+pairWithNil x = (x, [])++mapAccumLF :: (acc -> x -> (acc, y)) -> x -> (acc -> (acc, [y])) -> acc -> (acc, [y])+{-# INLINE [0] mapAccumLF #-}+mapAccumLF f = \x r -> oneShot (\s ->+                         let (s', y)   = f s x+                             (s'', ys) = r s'+                         in (s'', y:ys))+  -- See Note [Left folds via right fold]+++-- | The 'mapAccumR' function behaves like a combination of 'map' and+-- 'foldr'; it applies a function to each element of a list, passing+-- an accumulating parameter from right to left, and returning a final+-- value of this accumulator together with the new list.+mapAccumR :: (acc -> x -> (acc, y))     -- Function of elt of input list+                                        -- and accumulator, returning new+                                        -- accumulator and elt of result list+            -> acc              -- Initial accumulator+            -> [x]              -- Input list+            -> (acc, [y])               -- Final accumulator and result list+mapAccumR _ s []        =  (s, [])+mapAccumR f s (x:xs)    =  (s'', y:ys)+                           where (s'',y ) = f s' x+                                 (s', ys) = mapAccumR f s xs++-- | The 'insert' function takes an element and a list and inserts the+-- element into the list at the first position where it is less+-- than or equal to the next element.  In particular, if the list+-- is sorted before the call, the result will also be sorted.+-- It is a special case of 'insertBy', which allows the programmer to+-- supply their own comparison function.+insert :: Ord a => a -> [a] -> [a]+insert e ls = insertBy (compare) e ls++-- | The non-overloaded version of 'insert'.+insertBy :: (a -> a -> Ordering) -> a -> [a] -> [a]+insertBy _   x [] = [x]+insertBy cmp x ys@(y:ys')+ = case cmp x y of+     GT -> y : insertBy cmp x ys'+     _  -> x : ys++-- | The 'maximumBy' function takes a comparison function and a list+-- and returns the greatest element of the list by the comparison function.+-- The list must be finite and non-empty.+maximumBy               :: (a -> a -> Ordering) -> [a] -> a+maximumBy _ []          =  error "List.maximumBy: empty list"+maximumBy cmp xs        =  foldl1 maxBy xs+                        where+                           maxBy x y = case cmp x y of+                                       GT -> x+                                       _  -> y++-- | The 'minimumBy' function takes a comparison function and a list+-- and returns the least element of the list by the comparison function.+-- The list must be finite and non-empty.+minimumBy               :: (a -> a -> Ordering) -> [a] -> a+minimumBy _ []          =  error "List.minimumBy: empty list"+minimumBy cmp xs        =  foldl1 minBy xs+                        where+                           minBy x y = case cmp x y of+                                       GT -> y+                                       _  -> x++-- | The 'genericLength' function is an overloaded version of 'length'.  In+-- particular, instead of returning an 'Int', it returns any type which is+-- an instance of 'Num'.  It is, however, less efficient than 'length'.+genericLength           :: (Num i) => [a] -> i+{-# NOINLINE [1] genericLength #-}+genericLength []        =  0+genericLength (_:l)     =  1 + genericLength l++{-# RULES+  "genericLengthInt"     genericLength = (strictGenericLength :: [a] -> Int);+  "genericLengthInteger" genericLength = (strictGenericLength :: [a] -> Integer);+ #-}++strictGenericLength     :: (Num i) => [b] -> i+strictGenericLength l   =  gl l 0+                        where+                           gl [] a     = a+                           gl (_:xs) a = let a' = a + 1 in a' `seq` gl xs a'++-- | The 'genericTake' function is an overloaded version of 'take', which+-- accepts any 'Integral' value as the number of elements to take.+genericTake             :: (Integral i) => i -> [a] -> [a]+genericTake n _ | n <= 0 = []+genericTake _ []        =  []+genericTake n (x:xs)    =  x : genericTake (n-1) xs++-- | The 'genericDrop' function is an overloaded version of 'drop', which+-- accepts any 'Integral' value as the number of elements to drop.+genericDrop             :: (Integral i) => i -> [a] -> [a]+genericDrop n xs | n <= 0 = xs+genericDrop _ []        =  []+genericDrop n (_:xs)    =  genericDrop (n-1) xs+++-- | The 'genericSplitAt' function is an overloaded version of 'splitAt', which+-- accepts any 'Integral' value as the position at which to split.+genericSplitAt          :: (Integral i) => i -> [a] -> ([a], [a])+genericSplitAt n xs | n <= 0 =  ([],xs)+genericSplitAt _ []     =  ([],[])+genericSplitAt n (x:xs) =  (x:xs',xs'') where+    (xs',xs'') = genericSplitAt (n-1) xs++-- | The 'genericIndex' function is an overloaded version of '!!', which+-- accepts any 'Integral' value as the index.+genericIndex :: (Integral i) => [a] -> i -> a+genericIndex (x:_)  0 = x+genericIndex (_:xs) n+ | n > 0     = genericIndex xs (n-1)+ | otherwise = error "List.genericIndex: negative argument."+genericIndex _ _      = error "List.genericIndex: index too large."++-- | The 'genericReplicate' function is an overloaded version of 'replicate',+-- which accepts any 'Integral' value as the number of repetitions to make.+genericReplicate        :: (Integral i) => i -> a -> [a]+genericReplicate n x    =  genericTake n (repeat x)++-- | The 'zip4' function takes four lists and returns a list of+-- quadruples, analogous to 'zip'.+zip4                    :: [a] -> [b] -> [c] -> [d] -> [(a,b,c,d)]+zip4                    =  zipWith4 (,,,)++-- | The 'zip5' function takes five lists and returns a list of+-- five-tuples, analogous to 'zip'.+zip5                    :: [a] -> [b] -> [c] -> [d] -> [e] -> [(a,b,c,d,e)]+zip5                    =  zipWith5 (,,,,)++-- | The 'zip6' function takes six lists and returns a list of six-tuples,+-- analogous to 'zip'.+zip6                    :: [a] -> [b] -> [c] -> [d] -> [e] -> [f] ->+                              [(a,b,c,d,e,f)]+zip6                    =  zipWith6 (,,,,,)++-- | The 'zip7' function takes seven lists and returns a list of+-- seven-tuples, analogous to 'zip'.+zip7                    :: [a] -> [b] -> [c] -> [d] -> [e] -> [f] ->+                              [g] -> [(a,b,c,d,e,f,g)]+zip7                    =  zipWith7 (,,,,,,)++-- | The 'zipWith4' function takes a function which combines four+-- elements, as well as four lists and returns a list of their point-wise+-- combination, analogous to 'zipWith'.+zipWith4                :: (a->b->c->d->e) -> [a]->[b]->[c]->[d]->[e]+zipWith4 z (a:as) (b:bs) (c:cs) (d:ds)+                        =  z a b c d : zipWith4 z as bs cs ds+zipWith4 _ _ _ _ _      =  []++-- | The 'zipWith5' function takes a function which combines five+-- elements, as well as five lists and returns a list of their point-wise+-- combination, analogous to 'zipWith'.+zipWith5                :: (a->b->c->d->e->f) ->+                           [a]->[b]->[c]->[d]->[e]->[f]+zipWith5 z (a:as) (b:bs) (c:cs) (d:ds) (e:es)+                        =  z a b c d e : zipWith5 z as bs cs ds es+zipWith5 _ _ _ _ _ _    = []++-- | The 'zipWith6' function takes a function which combines six+-- elements, as well as six lists and returns a list of their point-wise+-- combination, analogous to 'zipWith'.+zipWith6                :: (a->b->c->d->e->f->g) ->+                           [a]->[b]->[c]->[d]->[e]->[f]->[g]+zipWith6 z (a:as) (b:bs) (c:cs) (d:ds) (e:es) (f:fs)+                        =  z a b c d e f : zipWith6 z as bs cs ds es fs+zipWith6 _ _ _ _ _ _ _  = []++-- | The 'zipWith7' function takes a function which combines seven+-- elements, as well as seven lists and returns a list of their point-wise+-- combination, analogous to 'zipWith'.+zipWith7                :: (a->b->c->d->e->f->g->h) ->+                           [a]->[b]->[c]->[d]->[e]->[f]->[g]->[h]+zipWith7 z (a:as) (b:bs) (c:cs) (d:ds) (e:es) (f:fs) (g:gs)+                   =  z a b c d e f g : zipWith7 z as bs cs ds es fs gs+zipWith7 _ _ _ _ _ _ _ _ = []++-- | The 'unzip4' function takes a list of quadruples and returns four+-- lists, analogous to 'unzip'.+unzip4                  :: [(a,b,c,d)] -> ([a],[b],[c],[d])+unzip4                  =  foldr (\(a,b,c,d) ~(as,bs,cs,ds) ->+                                        (a:as,b:bs,c:cs,d:ds))+                                 ([],[],[],[])++-- | The 'unzip5' function takes a list of five-tuples and returns five+-- lists, analogous to 'unzip'.+unzip5                  :: [(a,b,c,d,e)] -> ([a],[b],[c],[d],[e])+unzip5                  =  foldr (\(a,b,c,d,e) ~(as,bs,cs,ds,es) ->+                                        (a:as,b:bs,c:cs,d:ds,e:es))+                                 ([],[],[],[],[])++-- | The 'unzip6' function takes a list of six-tuples and returns six+-- lists, analogous to 'unzip'.+unzip6                  :: [(a,b,c,d,e,f)] -> ([a],[b],[c],[d],[e],[f])+unzip6                  =  foldr (\(a,b,c,d,e,f) ~(as,bs,cs,ds,es,fs) ->+                                        (a:as,b:bs,c:cs,d:ds,e:es,f:fs))+                                 ([],[],[],[],[],[])++-- | The 'unzip7' function takes a list of seven-tuples and returns+-- seven lists, analogous to 'unzip'.+unzip7          :: [(a,b,c,d,e,f,g)] -> ([a],[b],[c],[d],[e],[f],[g])+unzip7          =  foldr (\(a,b,c,d,e,f,g) ~(as,bs,cs,ds,es,fs,gs) ->+                                (a:as,b:bs,c:cs,d:ds,e:es,f:fs,g:gs))+                         ([],[],[],[],[],[],[])+++-- | The 'deleteFirstsBy' function takes a predicate and two lists and+-- returns the first list with the first occurrence of each element of+-- the second list removed.+deleteFirstsBy          :: (a -> a -> Bool) -> [a] -> [a] -> [a]+deleteFirstsBy eq       =  foldl (flip (deleteBy eq))++-- | The 'group' function takes a list and returns a list of lists such+-- that the concatenation of the result is equal to the argument.  Moreover,+-- each sublist in the result contains only equal elements.  For example,+--+-- > group "Mississippi" = ["M","i","ss","i","ss","i","pp","i"]+--+-- It is a special case of 'groupBy', which allows the programmer to supply+-- their own equality test.+group                   :: Eq a => [a] -> [[a]]+group                   =  groupBy (==)++-- | The 'groupBy' function is the non-overloaded version of 'group'.+groupBy                 :: (a -> a -> Bool) -> [a] -> [[a]]+groupBy _  []           =  []+groupBy eq (x:xs)       =  (x:ys) : groupBy eq zs+                           where (ys,zs) = span (eq x) xs++-- | The 'inits' function returns all initial segments of the argument,+-- shortest first.  For example,+--+-- > inits "abc" == ["","a","ab","abc"]+--+-- Note that 'inits' has the following strictness property:+-- @inits (xs ++ _|_) = inits xs ++ _|_@+--+-- In particular,+-- @inits _|_ = [] : _|_@+inits                   :: [a] -> [[a]]+inits                   = map toListSB . scanl' snocSB emptySB+{-# NOINLINE inits #-}++-- We do not allow inits to inline, because it plays havoc with Call Arity+-- if it fuses with a consumer, and it would generally lead to serious+-- loss of sharing if allowed to fuse with a producer.++-- | The 'tails' function returns all final segments of the argument,+-- longest first.  For example,+--+-- > tails "abc" == ["abc", "bc", "c",""]+--+-- Note that 'tails' has the following strictness property:+-- @tails _|_ = _|_ : _|_@+tails                   :: [a] -> [[a]]+{-# INLINABLE tails #-}+tails lst               =  build (\c n ->+  let tailsGo xs = xs `c` case xs of+                             []      -> n+                             _ : xs' -> tailsGo xs'+  in tailsGo lst)++-- | The 'subsequences' function returns the list of all subsequences of the argument.+--+-- > subsequences "abc" == ["","a","b","ab","c","ac","bc","abc"]+subsequences            :: [a] -> [[a]]+subsequences xs         =  [] : nonEmptySubsequences xs++-- | The 'nonEmptySubsequences' function returns the list of all subsequences of the argument,+--   except for the empty list.+--+-- > nonEmptySubsequences "abc" == ["a","b","ab","c","ac","bc","abc"]+nonEmptySubsequences         :: [a] -> [[a]]+nonEmptySubsequences []      =  []+nonEmptySubsequences (x:xs)  =  [x] : foldr f [] (nonEmptySubsequences xs)+  where f ys r = ys : (x : ys) : r+++-- | The 'permutations' function returns the list of all permutations of the argument.+--+-- > permutations "abc" == ["abc","bac","cba","bca","cab","acb"]+permutations            :: [a] -> [[a]]+permutations xs0        =  xs0 : perms xs0 []+  where+    perms []     _  = []+    perms (t:ts) is = foldr interleave (perms ts (t:is)) (permutations is)+      where interleave    xs     r = let (_,zs) = interleave' id xs r in zs+            interleave' _ []     r = (ts, r)+            interleave' f (y:ys) r = let (us,zs) = interleave' (f . (y:)) ys r+                                     in  (y:us, f (t:y:us) : zs)+++------------------------------------------------------------------------------+-- Quick Sort algorithm taken from HBC's QSort library.++-- | The 'sort' function implements a stable sorting algorithm.+-- It is a special case of 'sortBy', which allows the programmer to supply+-- their own comparison function.+sort :: (Ord a) => [a] -> [a]++-- | The 'sortBy' function is the non-overloaded version of 'sort'.+sortBy :: (a -> a -> Ordering) -> [a] -> [a]++#ifdef USE_REPORT_PRELUDE+sort = sortBy compare+sortBy cmp = foldr (insertBy cmp) []+#else++{-+GHC's mergesort replaced by a better implementation, 24/12/2009.+This code originally contributed to the nhc12 compiler by Thomas Nordin+in 2002.  Rumoured to have been based on code by Lennart Augustsson, e.g.+    http://www.mail-archive.com/haskell@haskell.org/msg01822.html+and possibly to bear similarities to a 1982 paper by Richard O'Keefe:+"A smooth applicative merge sort".++Benchmarks show it to be often 2x the speed of the previous implementation.+Fixes ticket http://ghc.haskell.org/trac/ghc/ticket/2143+-}++sort = sortBy compare+sortBy cmp = mergeAll . sequences+  where+    sequences (a:b:xs)+      | a `cmp` b == GT = descending b [a]  xs+      | otherwise       = ascending  b (a:) xs+    sequences xs = [xs]++    descending a as (b:bs)+      | a `cmp` b == GT = descending b (a:as) bs+    descending a as bs  = (a:as): sequences bs++    ascending a as (b:bs)+      | a `cmp` b /= GT = ascending b (\ys -> as (a:ys)) bs+    ascending a as bs   = as [a]: sequences bs++    mergeAll [x] = x+    mergeAll xs  = mergeAll (mergePairs xs)++    mergePairs (a:b:xs) = merge a b: mergePairs xs+    mergePairs xs       = xs++    merge as@(a:as') bs@(b:bs')+      | a `cmp` b == GT = b:merge as  bs'+      | otherwise       = a:merge as' bs+    merge [] bs         = bs+    merge as []         = as++{-+sortBy cmp l = mergesort cmp l+sort l = mergesort compare l++Quicksort replaced by mergesort, 14/5/2002.++From: Ian Lynagh <igloo@earth.li>++I am curious as to why the List.sort implementation in GHC is a+quicksort algorithm rather than an algorithm that guarantees n log n+time in the worst case? I have attached a mergesort implementation along+with a few scripts to time it's performance, the results of which are+shown below (* means it didn't finish successfully - in all cases this+was due to a stack overflow).++If I heap profile the random_list case with only 10000 then I see+random_list peaks at using about 2.5M of memory, whereas in the same+program using List.sort it uses only 100k.++Input style     Input length     Sort data     Sort alg    User time+stdin           10000            random_list   sort        2.82+stdin           10000            random_list   mergesort   2.96+stdin           10000            sorted        sort        31.37+stdin           10000            sorted        mergesort   1.90+stdin           10000            revsorted     sort        31.21+stdin           10000            revsorted     mergesort   1.88+stdin           100000           random_list   sort        *+stdin           100000           random_list   mergesort   *+stdin           100000           sorted        sort        *+stdin           100000           sorted        mergesort   *+stdin           100000           revsorted     sort        *+stdin           100000           revsorted     mergesort   *+func            10000            random_list   sort        0.31+func            10000            random_list   mergesort   0.91+func            10000            sorted        sort        19.09+func            10000            sorted        mergesort   0.15+func            10000            revsorted     sort        19.17+func            10000            revsorted     mergesort   0.16+func            100000           random_list   sort        3.85+func            100000           random_list   mergesort   *+func            100000           sorted        sort        5831.47+func            100000           sorted        mergesort   2.23+func            100000           revsorted     sort        5872.34+func            100000           revsorted     mergesort   2.24++mergesort :: (a -> a -> Ordering) -> [a] -> [a]+mergesort cmp = mergesort' cmp . map wrap++mergesort' :: (a -> a -> Ordering) -> [[a]] -> [a]+mergesort' _   [] = []+mergesort' _   [xs] = xs+mergesort' cmp xss = mergesort' cmp (merge_pairs cmp xss)++merge_pairs :: (a -> a -> Ordering) -> [[a]] -> [[a]]+merge_pairs _   [] = []+merge_pairs _   [xs] = [xs]+merge_pairs cmp (xs:ys:xss) = merge cmp xs ys : merge_pairs cmp xss++merge :: (a -> a -> Ordering) -> [a] -> [a] -> [a]+merge _   [] ys = ys+merge _   xs [] = xs+merge cmp (x:xs) (y:ys)+ = case x `cmp` y of+        GT -> y : merge cmp (x:xs)   ys+        _  -> x : merge cmp    xs (y:ys)++wrap :: a -> [a]+wrap x = [x]++++OLDER: qsort version++-- qsort is stable and does not concatenate.+qsort :: (a -> a -> Ordering) -> [a] -> [a] -> [a]+qsort _   []     r = r+qsort _   [x]    r = x:r+qsort cmp (x:xs) r = qpart cmp x xs [] [] r++-- qpart partitions and sorts the sublists+qpart :: (a -> a -> Ordering) -> a -> [a] -> [a] -> [a] -> [a] -> [a]+qpart cmp x [] rlt rge r =+    -- rlt and rge are in reverse order and must be sorted with an+    -- anti-stable sorting+    rqsort cmp rlt (x:rqsort cmp rge r)+qpart cmp x (y:ys) rlt rge r =+    case cmp x y of+        GT -> qpart cmp x ys (y:rlt) rge r+        _  -> qpart cmp x ys rlt (y:rge) r++-- rqsort is as qsort but anti-stable, i.e. reverses equal elements+rqsort :: (a -> a -> Ordering) -> [a] -> [a] -> [a]+rqsort _   []     r = r+rqsort _   [x]    r = x:r+rqsort cmp (x:xs) r = rqpart cmp x xs [] [] r++rqpart :: (a -> a -> Ordering) -> a -> [a] -> [a] -> [a] -> [a] -> [a]+rqpart cmp x [] rle rgt r =+    qsort cmp rle (x:qsort cmp rgt r)+rqpart cmp x (y:ys) rle rgt r =+    case cmp y x of+        GT -> rqpart cmp x ys rle (y:rgt) r+        _  -> rqpart cmp x ys (y:rle) rgt r+-}++#endif /* USE_REPORT_PRELUDE */++-- | Sort a list by comparing the results of a key function applied to each+-- element.  @sortOn f@ is equivalent to @sortBy . comparing f@, but has the+-- performance advantage of only evaluating @f@ once for each element in the+-- input list.  This is called the decorate-sort-undecorate paradigm, or+-- Schwartzian transform.+--+-- @since 4.8.0.0+sortOn :: Ord b => (a -> b) -> [a] -> [a]+sortOn f =+  map snd . sortBy (comparing fst) . map (\x -> let y = f x in y `seq` (y, x))++-- | The 'unfoldr' function is a \`dual\' to 'foldr': while 'foldr'+-- reduces a list to a summary value, 'unfoldr' builds a list from+-- a seed value.  The function takes the element and returns 'Nothing'+-- if it is done producing the list or returns 'Just' @(a,b)@, in which+-- case, @a@ is a prepended to the list and @b@ is used as the next+-- element in a recursive call.  For example,+--+-- > iterate f == unfoldr (\x -> Just (x, f x))+--+-- In some cases, 'unfoldr' can undo a 'foldr' operation:+--+-- > unfoldr f' (foldr f z xs) == xs+--+-- if the following holds:+--+-- > f' (f x y) = Just (x,y)+-- > f' z       = Nothing+--+-- A simple use of unfoldr:+--+-- > unfoldr (\b -> if b == 0 then Nothing else Just (b, b-1)) 10+-- >  [10,9,8,7,6,5,4,3,2,1]+--++-- Note [INLINE unfoldr]+-- We treat unfoldr a little differently from some other forms for list fusion+-- for two reasons:+--+-- 1. We don't want to use a rule to rewrite a basic form to a fusible+-- form because this would inline before constant floating. As Simon Peyton-+-- Jones and others have pointed out, this could reduce sharing in some cases+-- where sharing is beneficial. Thus we simply INLINE it, which is, for+-- example, how enumFromTo::Int becomes eftInt. Unfortunately, we don't seem+-- to get enough of an inlining discount to get a version of eftInt based on+-- unfoldr to inline as readily as the usual one. We know that all the Maybe+-- nonsense will go away, but the compiler does not.+--+-- 2. The benefit of inlining unfoldr is likely to be huge in many common cases,+-- even apart from list fusion. In particular, inlining unfoldr often+-- allows GHC to erase all the Maybes. This appears to be critical if unfoldr+-- is to be used in high-performance code. A small increase in code size+-- in the relatively rare cases when this does not happen looks like a very+-- small price to pay.+--+-- Doing a back-and-forth dance doesn't seem to accomplish anything if the+-- final form has to be inlined in any case.++unfoldr :: (b -> Maybe (a, b)) -> b -> [a]++{-# INLINE unfoldr #-} -- See Note [INLINE unfoldr]+unfoldr f b0 = build (\c n ->+  let go b = case f b of+               Just (a, new_b) -> a `c` go new_b+               Nothing         -> n+  in go b0)++-- -----------------------------------------------------------------------------+-- Functions on strings++-- | 'lines' breaks a string up into a list of strings at newline+-- characters.  The resulting strings do not contain newlines.+lines                   :: String -> [String]+lines ""                =  []+-- Somehow GHC doesn't detect the selector thunks in the below code,+-- so s' keeps a reference to the first line via the pair and we have+-- a space leak (cf. #4334).+-- So we need to make GHC see the selector thunks with a trick.+lines s                 =  cons (case break (== '\n') s of+                                    (l, s') -> (l, case s' of+                                                    []      -> []+                                                    _:s''   -> lines s''))+  where+    cons ~(h, t)        =  h : t++-- | 'unlines' is an inverse operation to 'lines'.+-- It joins lines, after appending a terminating newline to each.+unlines                 :: [String] -> String+#ifdef USE_REPORT_PRELUDE+unlines                 =  concatMap (++ "\n")+#else+-- HBC version (stolen)+-- here's a more efficient version+unlines [] = []+unlines (l:ls) = l ++ '\n' : unlines ls+#endif++-- | 'words' breaks a string up into a list of words, which were delimited+-- by white space.+words                   :: String -> [String]+{-# NOINLINE [1] words #-}+words s                 =  case dropWhile {-partain:Char.-}isSpace s of+                                "" -> []+                                s' -> w : words s''+                                      where (w, s'') =+                                             break {-partain:Char.-}isSpace s'++{-# RULES+"words" [~1] forall s . words s = build (\c n -> wordsFB c n s)+"wordsList" [1] wordsFB (:) [] = words+ #-}+wordsFB :: ([Char] -> b -> b) -> b -> String -> b+{-# NOINLINE [0] wordsFB #-}+wordsFB c n = go+  where+    go s = case dropWhile isSpace s of+             "" -> n+             s' -> w `c` go s''+                   where (w, s'') = break isSpace s'++-- | 'unwords' is an inverse operation to 'words'.+-- It joins words with separating spaces.+unwords                 :: [String] -> String+#ifdef USE_REPORT_PRELUDE+unwords []              =  ""+unwords ws              =  foldr1 (\w s -> w ++ ' ':s) ws+#else+-- Here's a lazier version that can get the last element of a+-- _|_-terminated list.+{-# NOINLINE [1] unwords #-}+unwords []              =  ""+unwords (w:ws)          = w ++ go ws+  where+    go []     = ""+    go (v:vs) = ' ' : (v ++ go vs)++-- In general, the foldr-based version is probably slightly worse+-- than the HBC version, because it adds an extra space and then takes+-- it back off again. But when it fuses, it reduces allocation. How much+-- depends entirely on the average word length--it's most effective when+-- the words are on the short side.+{-# RULES+"unwords" [~1] forall ws .+   unwords ws = tailUnwords (foldr unwordsFB "" ws)+"unwordsList" [1] forall ws .+   tailUnwords (foldr unwordsFB "" ws) = unwords ws+ #-}++{-# INLINE [0] tailUnwords #-}+tailUnwords           :: String -> String+tailUnwords []        = []+tailUnwords (_:xs)    = xs++{-# INLINE [0] unwordsFB #-}+unwordsFB               :: String -> String -> String+unwordsFB w r           = ' ' : w ++ r+#endif++{- A "SnocBuilder" is a version of Chris Okasaki's banker's queue that supports+toListSB instead of uncons. In single-threaded use, its performance+characteristics are similar to John Hughes's functional difference lists, but+likely somewhat worse. In heavily persistent settings, however, it does much+better, because it takes advantage of sharing. The banker's queue guarantees+(amortized) O(1) snoc and O(1) uncons, meaning that we can think of toListSB as+an O(1) conversion to a list-like structure a constant factor slower than+normal lists--we pay the O(n) cost incrementally as we consume the list. Using+functional difference lists, on the other hand, we would have to pay the whole+cost up front for each output list. -}++{- We store a front list, a rear list, and the length of the queue.  Because we+only snoc onto the queue and never uncons, we know it's time to rotate when the+length of the queue plus 1 is a power of 2. Note that we rely on the value of+the length field only for performance.  In the unlikely event of overflow, the+performance will suffer but the semantics will remain correct.  -}++data SnocBuilder a = SnocBuilder {-# UNPACK #-} !Word [a] [a]++{- Smart constructor that rotates the builder when lp is one minus a power of+2. Does not rotate very small builders because doing so is not worth the+trouble. The lp < 255 test goes first because the power-of-2 test gives awful+branch prediction for very small n (there are 5 powers of 2 between 1 and+16). Putting the well-predicted lp < 255 test first avoids branching on the+power-of-2 test until powers of 2 have become sufficiently rare to be predicted+well. -}++{-# INLINE sb #-}+sb :: Word -> [a] -> [a] -> SnocBuilder a+sb lp f r+  | lp < 255 || (lp .&. (lp + 1)) /= 0 = SnocBuilder lp f r+  | otherwise                          = SnocBuilder lp (f ++ reverse r) []++-- The empty builder++emptySB :: SnocBuilder a+emptySB = SnocBuilder 0 [] []++-- Add an element to the end of a queue.++snocSB :: SnocBuilder a -> a -> SnocBuilder a+snocSB (SnocBuilder lp f r) x = sb (lp + 1) f (x:r)++-- Convert a builder to a list++toListSB :: SnocBuilder a -> [a]+toListSB (SnocBuilder _ f r) = f ++ reverse r
− Data/OldTypeable.hs
@@ -1,179 +0,0 @@-{-# LANGUAGE Trustworthy #-}-{-# LANGUAGE CPP-           , NoImplicitPrelude-           , OverlappingInstances-           , ScopedTypeVariables-           , FlexibleInstances-  #-}-{-# OPTIONS_GHC -funbox-strict-fields -fno-warn-warnings-deprecations #-}---- The -XOverlappingInstances flag allows the user to over-ride--- the instances for Typeable given here.  In particular, we provide an instance---      instance ... => Typeable (s a) --- But a user might want to say---      instance ... => Typeable (MyType a b)---------------------------------------------------------------------------------- |--- Module      :  Data.Typeable--- Copyright   :  (c) The University of Glasgow, CWI 2001--2004--- License     :  BSD-style (see the file libraries/base/LICENSE)--- --- Maintainer  :  libraries@haskell.org--- Stability   :  experimental--- Portability :  portable------ This module defines the old, kind-monomorphic 'Typeable' class. It is now--- deprecated; users are recommended to use the kind-polymorphic--- "Data.Typeable" module instead.------ /Since: 4.7.0.0/--------------------------------------------------------------------------------module Data.OldTypeable {-# DEPRECATED "Use Data.Typeable instead" #-} -- deprecated in 7.8-  (--        -- * 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-        showsTypeRep,--        TyCon,          -- abstract, instance of: Eq, Show, Typeable-        tyConString,    -- :: TyCon   -> String-        tyConPackage,   -- :: TyCon   -> String-        tyConModule,    -- :: TyCon   -> String-        tyConName,      -- :: TyCon   -> String--        -- * Construction of type representations-        mkTyCon,        -- :: String  -> TyCon-        mkTyCon3,       -- :: String  -> String -> 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]-        typeRepKey,     -- :: TypeRep -> IO TypeRepKey-        TypeRepKey,     -- abstract, instance of Eq, Ord--        -- * 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--import Data.OldTypeable.Internal hiding (mkTyCon)--import Unsafe.Coerce-import Data.Maybe--import GHC.Base--import GHC.Fingerprint.Type-import GHC.Fingerprint--#include "OldTypeable.h"--{-# DEPRECATED typeRepKey "TypeRep itself is now an instance of Ord" #-} -- deprecated in 7.2--- | (DEPRECATED) Returns a unique key associated with a 'TypeRep'.--- This function is deprecated because 'TypeRep' itself is now an--- instance of 'Ord', so mappings can be made directly with 'TypeRep'--- as the key.----typeRepKey :: TypeRep -> IO TypeRepKey-typeRepKey (TypeRep f _ _) = return (TypeRepKey f)--        -- -        -- 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.--newtype TypeRepKey = TypeRepKey Fingerprint-  deriving (Eq,Ord)------------------- Construction -----------------------{-# DEPRECATED mkTyCon "either derive Typeable, or use mkTyCon3 instead" #-} -- deprecated in 7.2--- | Backwards-compatible API-mkTyCon :: String       -- ^ unique string-        -> TyCon        -- ^ A unique 'TyCon' object-mkTyCon name = TyCon (fingerprintString name) "" "" name---------------------------------------------------------------------              Type-safe cast--------------------------------------------------------------------- | The type-safe cast operation-cast :: (Typeable a, Typeable b) => a -> Maybe b-cast x = r-       where-         r = if typeOf x == typeOf (fromJust r)-               then Just $ unsafeCoerce x-               else Nothing---- | A flexible variation parameterised in a type constructor-gcast :: (Typeable a, Typeable b) => c a -> Maybe (c b)-gcast x = r- where-  r = if typeOf (getArg x) == typeOf (getArg (fromJust r))-        then Just $ unsafeCoerce x-        else Nothing-  getArg :: c x -> x -  getArg = undefined---- | Cast for * -> *-gcast1 :: (Typeable1 t, Typeable1 t') => c (t a) -> Maybe (c (t' a)) -gcast1 x = r- where-  r = if typeOf1 (getArg x) == typeOf1 (getArg (fromJust r))-       then Just $ unsafeCoerce x-       else Nothing-  getArg :: c x -> x -  getArg = undefined---- | Cast for * -> * -> *-gcast2 :: (Typeable2 t, Typeable2 t') => c (t a b) -> Maybe (c (t' a b)) -gcast2 x = r- where-  r = if typeOf2 (getArg x) == typeOf2 (getArg (fromJust r))-       then Just $ unsafeCoerce x-       else Nothing-  getArg :: c x -> x -  getArg = undefined-
− Data/OldTypeable/Internal.hs
@@ -1,475 +0,0 @@-{-# LANGUAGE Unsafe #-}---------------------------------------------------------------------------------- |--- Module      :  Data.Typeable.Internal--- Copyright   :  (c) The University of Glasgow, CWI 2001--2011--- License     :  BSD-style (see the file libraries/base/LICENSE)--- --- The representations of the types TyCon and TypeRep, and the--- function mkTyCon which is used by derived instances of Typeable to--- construct a TyCon.------ /Since: 4.7.0.0/--------------------------------------------------------------------------------{-# LANGUAGE CPP-           , NoImplicitPrelude-           , OverlappingInstances-           , ScopedTypeVariables-           , FlexibleInstances-           , MagicHash-           , DeriveDataTypeable-           , StandaloneDeriving #-}--module Data.OldTypeable.Internal {-# DEPRECATED "Use Data.Typeable.Internal instead" #-} ( -- deprecated in 7.8-    TypeRep(..),-    TyCon(..),-    mkTyCon,-    mkTyCon3,-    mkTyConApp,-    mkAppTy,-    typeRepTyCon,-    typeOfDefault,-    typeOf1Default,-    typeOf2Default,-    typeOf3Default,-    typeOf4Default,-    typeOf5Default,-    typeOf6Default,-    Typeable(..),-    Typeable1(..),-    Typeable2(..),-    Typeable3(..),-    Typeable4(..),-    Typeable5(..),-    Typeable6(..),-    Typeable7(..),-    mkFunTy,-    splitTyConApp,-    funResultTy,-    typeRepArgs,-    showsTypeRep,-    tyConString,-    listTc, funTc-  ) where--import GHC.Base-import GHC.Word-import GHC.Show-import Data.Maybe-import Data.List-import GHC.Num-import GHC.Real-import GHC.IORef-import GHC.IOArray-import GHC.MVar-import GHC.ST           ( ST )-import GHC.STRef        ( STRef )-import GHC.Ptr          ( Ptr, FunPtr )-import GHC.Stable-import GHC.Arr          ( Array, STArray )-import Data.Int--import GHC.Fingerprint.Type-import GHC.Fingerprint---- | A concrete representation of a (monomorphic) type.  'TypeRep'--- supports reasonably efficient equality.-data TypeRep = TypeRep {-# UNPACK #-} !Fingerprint TyCon [TypeRep]---- Compare keys for equality-instance Eq TypeRep where-  (TypeRep k1 _ _) == (TypeRep k2 _ _) = k1 == k2--instance Ord TypeRep where-  (TypeRep k1 _ _) <= (TypeRep k2 _ _) = k1 <= k2---- | An abstract representation of a type constructor.  'TyCon' objects can--- be built using 'mkTyCon'.-data TyCon = TyCon {-   tyConHash    :: {-# UNPACK #-} !Fingerprint,-   tyConPackage :: String,-   tyConModule  :: String,-   tyConName    :: String- }--instance Eq TyCon where-  (TyCon t1 _ _ _) == (TyCon t2 _ _ _) = t1 == t2--instance Ord TyCon where-  (TyCon k1 _ _ _) <= (TyCon k2 _ _ _) = k1 <= k2------------------- Construction ----------------------#include "MachDeps.h"---- mkTyCon is an internal function to make it easier for GHC to--- generate derived instances.  GHC precomputes the MD5 hash for the--- TyCon and passes it as two separate 64-bit values to mkTyCon.  The--- TyCon for a derived Typeable instance will end up being statically--- allocated.--#if WORD_SIZE_IN_BITS < 64-mkTyCon :: Word64# -> Word64# -> String -> String -> String -> TyCon-#else-mkTyCon :: Word#   -> Word#   -> String -> String -> String -> TyCon-#endif-mkTyCon high# low# pkg modl name-  = TyCon (Fingerprint (W64# high#) (W64# low#)) pkg modl name---- | Applies a type constructor to a sequence of types-mkTyConApp  :: TyCon -> [TypeRep] -> TypeRep-mkTyConApp tc@(TyCon tc_k _ _ _) []-  = TypeRep tc_k tc [] -- optimisation: all derived Typeable instances-                       -- end up here, and it helps generate smaller-                       -- code for derived Typeable.-mkTyConApp tc@(TyCon tc_k _ _ _) args-  = TypeRep (fingerprintFingerprints (tc_k : arg_ks)) tc args-  where-    arg_ks = [k | TypeRep k _ _ <- args]---- | A special case of 'mkTyConApp', which applies the function --- type constructor to a pair of types.-mkFunTy  :: TypeRep -> TypeRep -> TypeRep-mkFunTy f a = mkTyConApp funTc [f,a]---- | Splits a type constructor application-splitTyConApp :: TypeRep -> (TyCon,[TypeRep])-splitTyConApp (TypeRep _ tc trs) = (tc,trs)---- | Applies a type to a function type.  Returns: @'Just' u@ if the--- first argument represents a function of type @t -> u@ and the--- second argument represents a function of type @t@.  Otherwise,--- returns 'Nothing'.-funResultTy :: TypeRep -> TypeRep -> Maybe TypeRep-funResultTy trFun trArg-  = case splitTyConApp trFun of-      (tc, [t1,t2]) | tc == funTc && t1 == trArg -> Just t2-      _ -> Nothing---- | Adds a TypeRep argument to a TypeRep.-mkAppTy :: TypeRep -> TypeRep -> TypeRep-mkAppTy (TypeRep _ tc trs) arg_tr = mkTyConApp tc (trs ++ [arg_tr])-   -- Notice that we call mkTyConApp to construct the fingerprint from tc and-   -- the arg fingerprints.  Simply combining the current fingerprint with-   -- the new one won't give the same answer, but of course we want to -   -- ensure that a TypeRep of the same shape has the same fingerprint!-   -- See Trac #5962---- | Builds a 'TyCon' object representing a type constructor.  An--- implementation of "Data.Typeable" should ensure that the following holds:------ >  A==A' ^ B==B' ^ C==C' ==> mkTyCon A B C == mkTyCon A' B' C'--------mkTyCon3 :: String       -- ^ package name-         -> String       -- ^ module name-         -> String       -- ^ the name of the type constructor-         -> TyCon        -- ^ A unique 'TyCon' object-mkTyCon3 pkg modl name =-  TyCon (fingerprintString (unwords [pkg, modl, name])) pkg modl name------------------- Observation ------------------------- | Observe the type constructor of a type representation-typeRepTyCon :: TypeRep -> TyCon-typeRepTyCon (TypeRep _ tc _) = tc---- | Observe the argument types of a type representation-typeRepArgs :: TypeRep -> [TypeRep]-typeRepArgs (TypeRep _ _ args) = args---- | Observe string encoding of a type representation-{-# DEPRECATED tyConString "renamed to tyConName; tyConModule and tyConPackage are also available." #-} -- deprecated in 7.4-tyConString :: TyCon   -> String-tyConString = tyConName---------------------------------------------------------------------      The Typeable class and friends-------------------------------------------------------------------{- Note [Memoising typeOf]-~~~~~~~~~~~~~~~~~~~~~~~~~~-IMPORTANT: we don't want to recalculate the type-rep once per-call to the dummy argument.  This is what went wrong in Trac #3245-So we help GHC by manually keeping the 'rep' *outside* the value -lambda, thus-    -    typeOfDefault :: forall t a. (Typeable1 t, Typeable a) => t a -> TypeRep-    typeOfDefault = \_ -> rep-      where-        rep = typeOf1 (undefined :: t a) `mkAppTy` -              typeOf  (undefined :: a)--Notice the crucial use of scoped type variables here!--}---- | The class 'Typeable' allows a concrete representation of a type to--- be calculated.-class Typeable a where-  typeOf :: a -> TypeRep-  -- ^ Takes a value of type @a@ and returns a concrete representation-  -- of that type.  The /value/ of the argument should be ignored by-  -- any instance of 'Typeable', so that it is safe to pass 'undefined' as-  -- the argument.---- | Variant for unary type constructors-class Typeable1 t where-  typeOf1 :: t a -> TypeRep---- | For defining a 'Typeable' instance from any 'Typeable1' instance.-typeOfDefault :: forall t a. (Typeable1 t, Typeable a) => t a -> TypeRep-typeOfDefault = \_ -> rep- where-   rep = typeOf1 (undefined :: t a) `mkAppTy` -         typeOf  (undefined :: a)-   -- Note [Memoising typeOf]---- | Variant for binary type constructors-class Typeable2 t where-  typeOf2 :: t a b -> TypeRep---- | For defining a 'Typeable1' instance from any 'Typeable2' instance.-typeOf1Default :: forall t a b. (Typeable2 t, Typeable a) => t a b -> TypeRep-typeOf1Default = \_ -> rep - where-   rep = typeOf2 (undefined :: t a b) `mkAppTy` -         typeOf  (undefined :: a)-   -- Note [Memoising typeOf]---- | Variant for 3-ary type constructors-class Typeable3 t where-  typeOf3 :: t a b c -> TypeRep---- | For defining a 'Typeable2' instance from any 'Typeable3' instance.-typeOf2Default :: forall t a b c. (Typeable3 t, Typeable a) => t a b c -> TypeRep-typeOf2Default = \_ -> rep - where-   rep = typeOf3 (undefined :: t a b c) `mkAppTy` -         typeOf  (undefined :: a)-   -- Note [Memoising typeOf]---- | Variant for 4-ary type constructors-class Typeable4 t where-  typeOf4 :: t a b c d -> TypeRep---- | For defining a 'Typeable3' instance from any 'Typeable4' instance.-typeOf3Default :: forall t a b c d. (Typeable4 t, Typeable a) => t a b c d -> TypeRep-typeOf3Default = \_ -> rep- where-   rep = typeOf4 (undefined :: t a b c d) `mkAppTy` -         typeOf  (undefined :: a)-   -- Note [Memoising typeOf]-   --- | Variant for 5-ary type constructors-class Typeable5 t where-  typeOf5 :: t a b c d e -> TypeRep---- | For defining a 'Typeable4' instance from any 'Typeable5' instance.-typeOf4Default :: forall t a b c d e. (Typeable5 t, Typeable a) => t a b c d e -> TypeRep-typeOf4Default = \_ -> rep - where-   rep = typeOf5 (undefined :: t a b c d e) `mkAppTy` -         typeOf  (undefined :: a)-   -- Note [Memoising typeOf]---- | Variant for 6-ary type constructors-class Typeable6 t where-  typeOf6 :: t a b c d e f -> TypeRep---- | For defining a 'Typeable5' instance from any 'Typeable6' instance.-typeOf5Default :: forall t a b c d e f. (Typeable6 t, Typeable a) => t a b c d e f -> TypeRep-typeOf5Default = \_ -> rep- where-   rep = typeOf6 (undefined :: t a b c d e f) `mkAppTy` -         typeOf  (undefined :: a)-   -- Note [Memoising typeOf]---- | Variant for 7-ary type constructors-class Typeable7 t where-  typeOf7 :: t a b c d e f g -> TypeRep---- | For defining a 'Typeable6' instance from any 'Typeable7' instance.-typeOf6Default :: forall t a b c d e f g. (Typeable7 t, Typeable a) => t a b c d e f g -> TypeRep-typeOf6Default = \_ -> rep- where-   rep = typeOf7 (undefined :: t a b c d e f g) `mkAppTy` -         typeOf  (undefined :: a)-   -- Note [Memoising typeOf]---- Given a @Typeable@/n/ instance for an /n/-ary type constructor,--- define the instances for partial applications.--- Programmers using non-GHC implementations must do this manually--- for each type constructor.--- (The INSTANCE_TYPEABLE/n/ macros in Typeable.h include this.)---- | One Typeable instance for all Typeable1 instances-instance (Typeable1 s, Typeable a)-       => Typeable (s a) where-  typeOf = typeOfDefault---- | One Typeable1 instance for all Typeable2 instances-instance (Typeable2 s, Typeable a)-       => Typeable1 (s a) where-  typeOf1 = typeOf1Default---- | One Typeable2 instance for all Typeable3 instances-instance (Typeable3 s, Typeable a)-       => Typeable2 (s a) where-  typeOf2 = typeOf2Default---- | One Typeable3 instance for all Typeable4 instances-instance (Typeable4 s, Typeable a)-       => Typeable3 (s a) where-  typeOf3 = typeOf3Default---- | One Typeable4 instance for all Typeable5 instances-instance (Typeable5 s, Typeable a)-       => Typeable4 (s a) where-  typeOf4 = typeOf4Default---- | One Typeable5 instance for all Typeable6 instances-instance (Typeable6 s, Typeable a)-       => Typeable5 (s a) where-  typeOf5 = typeOf5Default---- | One Typeable6 instance for all Typeable7 instances-instance (Typeable7 s, Typeable a)-       => Typeable6 (s a) where-  typeOf6 = typeOf6Default------------------- Showing TypeReps ----------------------instance Show TypeRep where-  showsPrec p (TypeRep _ tycon tys) =-    case tys of-      [] -> showsPrec p tycon-      [x]   | tycon == listTc -> showChar '[' . shows x . showChar ']'-      [a,r] | tycon == funTc  -> showParen (p > 8) $-                                 showsPrec 9 a .-                                 showString " -> " .-                                 showsPrec 8 r-      xs | isTupleTyCon tycon -> showTuple xs-         | otherwise         ->-            showParen (p > 9) $-            showsPrec p tycon . -            showChar ' '      . -            showArgs tys--showsTypeRep :: TypeRep -> ShowS-showsTypeRep = shows--instance Show TyCon where-  showsPrec _ t = showString (tyConName t)--isTupleTyCon :: TyCon -> Bool-isTupleTyCon (TyCon _ _ _ ('(':',':_)) = True-isTupleTyCon _                         = False---- Some (Show.TypeRep) helpers:--showArgs :: Show a => [a] -> ShowS-showArgs [] = id-showArgs [a] = showsPrec 10 a-showArgs (a:as) = showsPrec 10 a . showString " " . showArgs as --showTuple :: [TypeRep] -> ShowS-showTuple args = showChar '('-               . (foldr (.) id $ intersperse (showChar ',') -                               $ map (showsPrec 10) args)-               . showChar ')'--listTc :: TyCon-listTc = typeRepTyCon (typeOf [()])--funTc :: TyCon-funTc = mkTyCon3 "ghc-prim" "GHC.Types" "->"---------------------------------------------------------------------      Instances of the Typeable classes for Prelude types-------------------------------------------------------------------#include "OldTypeable.h"--INSTANCE_TYPEABLE0((),unitTc,"()")-INSTANCE_TYPEABLE1([],listTc,"[]")-INSTANCE_TYPEABLE1(Maybe,maybeTc,"Maybe")-INSTANCE_TYPEABLE1(Ratio,ratioTc,"Ratio")--{--TODO: Deriving this instance fails with:-libraries/base/Data/Typeable.hs:589:1:-    Can't make a derived instance of `Typeable2 (->)':-      The last argument of the instance must be a data or newtype application-    In the stand-alone deriving instance for `Typeable2 (->)'--}-instance Typeable2 (->) where { typeOf2 _ = mkTyConApp funTc [] }--INSTANCE_TYPEABLE1(IO,ioTc,"IO")---- Types defined in GHC.MVar-INSTANCE_TYPEABLE1(MVar,mvarTc,"MVar" )--INSTANCE_TYPEABLE2(Array,arrayTc,"Array")-INSTANCE_TYPEABLE2(IOArray,iOArrayTc,"IOArray")--INSTANCE_TYPEABLE2(ST,stTc,"ST")-INSTANCE_TYPEABLE2(STRef,stRefTc,"STRef")-INSTANCE_TYPEABLE3(STArray,sTArrayTc,"STArray")--INSTANCE_TYPEABLE2((,),pairTc,"(,)")-INSTANCE_TYPEABLE3((,,),tup3Tc,"(,,)")-INSTANCE_TYPEABLE4((,,,),tup4Tc,"(,,,)")-INSTANCE_TYPEABLE5((,,,,),tup5Tc,"(,,,,)")-INSTANCE_TYPEABLE6((,,,,,),tup6Tc,"(,,,,,)")-INSTANCE_TYPEABLE7((,,,,,,),tup7Tc,"(,,,,,,)")--INSTANCE_TYPEABLE1(Ptr,ptrTc,"Ptr")-INSTANCE_TYPEABLE1(FunPtr,funPtrTc,"FunPtr")-INSTANCE_TYPEABLE1(StablePtr,stablePtrTc,"StablePtr")-INSTANCE_TYPEABLE1(IORef,iORefTc,"IORef")--------------------------------------------------------------- Generate Typeable instances for standard datatypes-------------------------------------------------------------INSTANCE_TYPEABLE0(Bool,boolTc,"Bool")-INSTANCE_TYPEABLE0(Char,charTc,"Char")-INSTANCE_TYPEABLE0(Float,floatTc,"Float")-INSTANCE_TYPEABLE0(Double,doubleTc,"Double")-INSTANCE_TYPEABLE0(Int,intTc,"Int")-INSTANCE_TYPEABLE0(Word,wordTc,"Word" )-INSTANCE_TYPEABLE0(Integer,integerTc,"Integer")-INSTANCE_TYPEABLE0(Ordering,orderingTc,"Ordering")--INSTANCE_TYPEABLE0(Int8,int8Tc,"Int8")-INSTANCE_TYPEABLE0(Int16,int16Tc,"Int16")-INSTANCE_TYPEABLE0(Int32,int32Tc,"Int32")-INSTANCE_TYPEABLE0(Int64,int64Tc,"Int64")--INSTANCE_TYPEABLE0(Word8,word8Tc,"Word8" )-INSTANCE_TYPEABLE0(Word16,word16Tc,"Word16")-INSTANCE_TYPEABLE0(Word32,word32Tc,"Word32")-INSTANCE_TYPEABLE0(Word64,word64Tc,"Word64")--INSTANCE_TYPEABLE0(TyCon,tyconTc,"TyCon")-INSTANCE_TYPEABLE0(TypeRep,typeRepTc,"TypeRep")--{--TODO: This can't be derived currently:-libraries/base/Data/Typeable.hs:674:1:-    Can't make a derived instance of `Typeable RealWorld':-      The last argument of the instance must be a data or newtype application-    In the stand-alone deriving instance for `Typeable RealWorld'--}-realWorldTc :: TyCon; \-realWorldTc = mkTyCon3 "ghc-prim" "GHC.Types" "RealWorld"; \-instance Typeable RealWorld where { typeOf _ = mkTyConApp realWorldTc [] }
− Data/OldTypeable/Internal.hs-boot
@@ -1,28 +0,0 @@-{-# LANGUAGE Unsafe #-}-{-# LANGUAGE CPP, NoImplicitPrelude, MagicHash #-}--module Data.OldTypeable.Internal (-    Typeable(typeOf),-    TypeRep,-    TyCon,-    mkTyCon,-    mkTyConApp-  ) where--import GHC.Base--data TypeRep-data TyCon--#include "MachDeps.h"--#if WORD_SIZE_IN_BITS < 64-mkTyCon :: Word64# -> Word64# -> String -> String -> String -> TyCon-#else-mkTyCon :: Word#   -> Word#   -> String -> String -> String -> TyCon-#endif--mkTyConApp   :: TyCon -> [TypeRep] -> TypeRep--class Typeable a where-  typeOf :: a -> TypeRep
Data/Ord.hs view
@@ -45,7 +45,7 @@ -- -- Provides 'Show' and 'Read' instances (/since: 4.7.0.0/). ----- /Since: 4.6.0.0/+-- @since 4.6.0.0 newtype Down a = Down a deriving (Eq, Show, Read)  instance Ord a => Ord (Down a) where
Data/Proxy.hs view
@@ -1,4 +1,5 @@-{-# LANGUAGE NoImplicitPrelude, Trustworthy #-}+{-# LANGUAGE Trustworthy #-}+{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE PolyKinds #-}  -----------------------------------------------------------------------------@@ -12,7 +13,7 @@ -- -- Definition of a Proxy type (poly-kinded in GHC) ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 -----------------------------------------------------------------------------  module Data.Proxy@@ -34,6 +35,10 @@ -- There are no instances for this because it is intended at the kind level only data KProxy (t :: *) = KProxy +-- It's common to use (undefined :: Proxy t) and (Proxy :: Proxy t)+-- interchangeably, so all of these instances are hand-written to be+-- lazy in Proxy arguments.+ instance Eq (Proxy s) where   _ == _ = True @@ -69,9 +74,20 @@     minBound = Proxy     maxBound = Proxy +instance Monoid (Proxy s) where+    mempty = Proxy+    mappend _ _ = Proxy+    mconcat _ = Proxy+ instance Functor Proxy where     fmap _ _ = Proxy     {-# INLINE fmap #-}++instance Applicative Proxy where+    pure _ = Proxy+    {-# INLINE pure #-}+    _ <*> _ = Proxy+    {-# INLINE (<*>) #-}  instance Monad Proxy where     return _ = Proxy
Data/Ratio.hs view
@@ -24,8 +24,6 @@    ) where -import Prelude- import GHC.Real         -- The basic defns for Ratio  -- -----------------------------------------------------------------------------
Data/STRef.hs view
@@ -24,8 +24,6 @@         modifySTRef'  ) where -import Prelude- import GHC.ST import GHC.STRef @@ -48,7 +46,7 @@  -- | Strict version of 'modifySTRef' ----- /Since: 4.6.0.0/+-- @since 4.6.0.0 modifySTRef' :: STRef s a -> (a -> a) -> ST s () modifySTRef' ref f = do     x <- readSTRef ref
Data/STRef/Lazy.hs view
@@ -23,9 +23,8 @@         modifySTRef  ) where -import Control.Monad.ST.Lazy.Safe+import Control.Monad.ST.Lazy import qualified Data.STRef as ST-import Prelude  newSTRef    :: a -> ST s (ST.STRef s a) readSTRef   :: ST.STRef s a -> ST s a
Data/Traversable.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE Trustworthy #-}+{-# LANGUAGE NoImplicitPrelude #-}  ----------------------------------------------------------------------------- -- |@@ -30,11 +31,6 @@ --    in /Mathematically-Structured Functional Programming/, 2012, online at --    <http://arxiv.org/pdf/1202.2919>. ----- Note that the functions 'mapM' and 'sequence' generalize "Prelude"--- functions of the same names from lists to any 'Traversable' functor.--- To avoid ambiguity, either import the "Prelude" hiding these names--- or qualify uses of these function names with an alias for this module.--- -----------------------------------------------------------------------------  module Data.Traversable (@@ -50,20 +46,21 @@     foldMapDefault,     ) where -import Prelude hiding (mapM, sequence, foldr)-import qualified Prelude (mapM, foldr)-import Control.Applicative-import Data.Foldable (Foldable())-import Data.Monoid (Monoid)-import Data.Proxy+import Control.Applicative ( Const(..) )+import Data.Either ( Either(..) )+import Data.Foldable ( Foldable )+import Data.Functor+import Data.Proxy ( Proxy(..) )  import GHC.Arr+import GHC.Base ( Applicative(..), Monad(..), Monoid, Maybe(..),+                  ($), (.), id, flip )+import qualified GHC.Base as Monad ( mapM )+import qualified GHC.List as List ( foldr )  -- | Functors representing data structures that can be traversed from -- left to right. ----- Minimal complete definition: 'traverse' or 'sequenceA'.--- -- A definition of 'traverse' must satisfy the following laws: -- -- [/naturality/]@@ -145,26 +142,32 @@ --    ('foldMapDefault'). -- class (Functor t, Foldable t) => Traversable t where-    -- | Map each element of a structure to an action, evaluate+    {-# MINIMAL traverse | sequenceA #-}++    -- | Map each element of a structure to an action, evaluate these     -- these actions from left to right, and collect the results.+    -- actions from left to right, and collect the results. For a+    -- version that ignores the results see 'Data.Foldable.traverse_'.     traverse :: Applicative f => (a -> f b) -> t a -> f (t b)     traverse f = sequenceA . fmap f -    -- | Evaluate each action in the structure from left to right,-    -- and collect the results.+    -- | Evaluate each action in the structure from left to right, and+    -- and collect the results. For a version that ignores the results+    -- see 'Data.Foldable.sequenceA_'.     sequenceA :: Applicative f => t (f a) -> f (t a)     sequenceA = traverse id      -- | Map each element of a structure to a monadic action, evaluate-    -- these actions from left to right, and collect the results.+    -- these actions from left to right, and collect the results. For+    -- a version that ignores the results see 'Data.Foldable.mapM_'.     mapM :: Monad m => (a -> m b) -> t a -> m (t b)-    mapM f = unwrapMonad . traverse (WrapMonad . f)+    mapM = traverse -    -- | Evaluate each monadic action in the structure from left to right,-    -- and collect the results.+    -- | Evaluate each monadic action in the structure from left to+    -- right, and collect the results. For a version that ignores the+    -- results see 'Data.Foldable.sequence_'.     sequence :: Monad m => t (m a) -> m (t a)-    sequence = mapM id-    {-# MINIMAL traverse | sequenceA #-}+    sequence = sequenceA  -- instances for Prelude types @@ -174,10 +177,10 @@  instance Traversable [] where     {-# INLINE traverse #-} -- so that traverse can fuse-    traverse f = Prelude.foldr cons_f (pure [])+    traverse f = List.foldr cons_f (pure [])       where cons_f x ys = (:) <$> f x <*> ys -    mapM = Prelude.mapM+    mapM = Monad.mapM  instance Traversable (Either a) where     traverse _ (Left x) = pure (Left x)@@ -204,12 +207,14 @@  -- general functions --- | 'for' is 'traverse' with its arguments flipped.+-- | 'for' is 'traverse' with its arguments flipped. For a version+-- that ignores the results see 'Data.Foldable.for_'. for :: (Traversable t, Applicative f) => t a -> (a -> f b) -> f (t b) {-# INLINE for #-} for = flip traverse --- | 'forM' is 'mapM' with its arguments flipped.+-- | 'forM' is 'mapM' with its arguments flipped. For a version that+-- ignores the results see 'Data.Foldable.forM_'. forM :: (Traversable t, Monad m) => t a -> (a -> m b) -> m (t b) {-# INLINE forM #-} forM = flip mapM
Data/Tuple.hs view
@@ -1,7 +1,5 @@ {-# LANGUAGE Trustworthy #-} {-# LANGUAGE NoImplicitPrelude #-}-{-# OPTIONS_GHC -fno-warn-unused-imports #-}--- XXX -fno-warn-unused-imports needed for the GHC.Tuple import below. Sigh.  ----------------------------------------------------------------------------- -- |@@ -23,20 +21,9 @@   , curry   , uncurry   , swap-  )-    where--import GHC.Base--- We need to depend on GHC.Base so that--- a) so that we get GHC.Classes, GHC.Types---- b) so that GHC.Base.inline is available, which is used---    when expanding instance declarations+  ) where -import GHC.Tuple--- We must import GHC.Tuple, to ensure sure that the--- data constructors of `(,)' are in scope when we do--- the standalone deriving instance for Eq (a,b) etc+import GHC.Base ()      -- Note [Depend on GHC.Tuple]  default ()              -- Double isn't available yet 
Data/Type/Bool.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE Safe #-} {-# LANGUAGE TypeFamilies, TypeOperators, DataKinds, NoImplicitPrelude,              PolyKinds #-} @@ -12,7 +13,7 @@ -- -- Basic operations on type-level Booleans. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 -----------------------------------------------------------------------------  module Data.Type.Bool (@@ -27,30 +28,28 @@  -- | Type-level "If". @If True a b@ ==> @a@; @If False a b@ ==> @b@ type family If cond tru fls where-  If True  tru fls = tru-  If False tru fls = fls+  If 'True  tru fls = tru+  If 'False tru fls = fls  -- | Type-level "and" type family a && b where-  False && a     = False-  True  && a     = a-  a     && False = False-  a     && True  = a-  a     && a     = a+  'False && a      = 'False+  'True  && a      = a+  a      && 'False = 'False+  a      && 'True  = a+  a      && a      = a infixr 3 &&  -- | Type-level "or" type family a || b where-  False || a     = a-  True  || a     = True-  a     || False = a-  a     || True  = True-  a     || a     = a+  'False || a      = a+  'True  || a      = 'True+  a      || 'False = a+  a      || 'True  = 'True+  a      || a      = a infixr 2 ||  -- | Type-level "not" type family Not a where-  Not False = True-  Not True  = False--  +  Not 'False = 'True+  Not 'True  = 'False
Data/Type/Coercion.hs view
@@ -19,7 +19,7 @@ -- -- Definition of representational equality ('Coercion'). ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 -----------------------------------------------------------------------------  module Data.Type.Coercion@@ -44,7 +44,7 @@ -- To use this equality in practice, pattern-match on the @Coercion a b@ to get out -- the @Coercible a b@ instance, and then use 'coerce' to apply it. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 data Coercion a b where   Coercion :: Coercible a b => Coercion a b 
Data/Type/Equality.hs view
@@ -23,7 +23,7 @@ -- Definition of propositional equality @(:~:)@. Pattern-matching on a variable -- of type @(a :~: b)@ produces a proof that @a ~ b@. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 -----------------------------------------------------------------------------  @@ -56,7 +56,7 @@ -- in practice, pattern-match on the @a :~: b@ to get out the @Refl@ constructor; -- in the body of the pattern-match, the compiler knows that @a ~ b@. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 data a :~: b where   Refl :: a :~: a @@ -127,39 +127,94 @@ type family (a :: k) == (b :: k) :: Bool infix 4 == +{-+This comment explains more about why a poly-kinded instance for (==) is+not provided. To be concrete, here would be the poly-kinded instance:++type family EqPoly (a :: k) (b :: k) where+ EqPoly a a = True+ EqPoly a b = False+type instance (a :: k) == (b :: k) = EqPoly a b++Note that this overlaps with every other instance -- if this were defined,+it would be the only instance for (==).++Now, consider+data Nat = Zero | Succ Nat++Suppose I want+foo :: (Succ n == Succ m) ~ True => ((n == m) :~: True)+foo = Refl++This would not type-check with the poly-kinded instance. `Succ n == Succ m`+quickly becomes `EqPoly (Succ n) (Succ m)` but then is stuck. We don't know+enough about `n` and `m` to reduce further.++On the other hand, consider this:++type family EqNat (a :: Nat) (b :: Nat) where+ EqNat Zero     Zero     = True+ EqNat (Succ n) (Succ m) = EqNat n m+ EqNat n        m        = False+type instance (a :: Nat) == (b :: Nat) = EqNat a b++With this instance, `foo` type-checks fine. `Succ n == Succ m` becomes `EqNat+(Succ n) (Succ m)` which becomes `EqNat n m`. Thus, we can conclude `(n == m)+~ True` as desired.++So, the Nat-specific instance allows strictly more reductions, and is thus+preferable to the poly-kinded instance. But, if we introduce the poly-kinded+instance, we are barred from writing the Nat-specific instance, due to+overlap.++Even better than the current instance for * would be one that does this sort+of recursion for all datatypes, something like this:++type family EqStar (a :: *) (b :: *) where+ EqStar Bool Bool = True+ EqStar (a,b) (c,d) = a == c && b == d+ EqStar (Maybe a) (Maybe b) = a == b+ ...+ EqStar a b = False++The problem is the (...) is extensible -- we would want to add new cases for+all datatypes in scope. This is not currently possible for closed type+families.+-}+ -- all of the following closed type families are local to this module type family EqStar (a :: *) (b :: *) where-  EqStar a a = True-  EqStar a b = False+  EqStar a a = 'True+  EqStar a b = 'False  -- This looks dangerous, but it isn't. This allows == to be defined -- over arbitrary type constructors. type family EqArrow (a :: k1 -> k2) (b :: k1 -> k2) where-  EqArrow a a = True-  EqArrow a b = False+  EqArrow a a = 'True+  EqArrow a b = 'False  type family EqBool a b where-  EqBool True  True  = True-  EqBool False False = True-  EqBool a     b     = False+  EqBool 'True  'True  = 'True+  EqBool 'False 'False = 'True+  EqBool a     b       = 'False  type family EqOrdering a b where-  EqOrdering LT LT = True-  EqOrdering EQ EQ = True-  EqOrdering GT GT = True-  EqOrdering a  b  = False+  EqOrdering 'LT 'LT = 'True+  EqOrdering 'EQ 'EQ = 'True+  EqOrdering 'GT 'GT = 'True+  EqOrdering a  b    = 'False -type EqUnit (a :: ()) (b :: ()) = True+type EqUnit (a :: ()) (b :: ()) = 'True  type family EqList a b where-  EqList '[]        '[]        = True+  EqList '[]        '[]        = 'True   EqList (h1 ': t1) (h2 ': t2) = (h1 == h2) && (t1 == t2)-  EqList a          b          = False+  EqList a          b          = 'False  type family EqMaybe a b where-  EqMaybe Nothing  Nothing  = True-  EqMaybe (Just x) (Just y) = x == y-  EqMaybe a        b        = False+  EqMaybe 'Nothing   'Nothing  = 'True+  EqMaybe ('Just x) ('Just y)  = x == y+  EqMaybe a        b           = 'False  type family Eq2 a b where   Eq2 '(a1, b1) '(a2, b2) = a1 == a2 && b1 == b2
Data/Typeable.hs view
@@ -1,20 +1,9 @@ {-# LANGUAGE Trustworthy #-}-{-# LANGUAGE NoImplicitPrelude-           , OverlappingInstances-           , ScopedTypeVariables-           , FlexibleInstances-           , TypeOperators-           , PolyKinds-           , GADTs-           , MagicHash-  #-}-{-# OPTIONS_GHC -funbox-strict-fields #-}---- The -XOverlappingInstances flag allows the user to over-ride--- the instances for Typeable given here.  In particular, we provide an instance---      instance ... => Typeable (s a) --- But a user might want to say---      instance ... => Typeable (MyType a b)+{-# LANGUAGE GADTs #-}+{-# LANGUAGE NoImplicitPrelude #-}+{-# LANGUAGE PolyKinds #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeOperators #-}  ----------------------------------------------------------------------------- -- |@@ -72,13 +61,17 @@                  -- * Type representations         TypeRep,        -- abstract, instance of: Eq, Show, Typeable+        typeRepFingerprint,+        rnfTypeRep,         showsTypeRep,          TyCon,          -- abstract, instance of: Eq, Show, Typeable+        tyConFingerprint,         tyConString,         tyConPackage,         tyConModule,         tyConName,+        rnfTyCon,          -- * Construction of type representations         -- mkTyCon,        -- :: String  -> TyCon@@ -115,7 +108,7 @@  -- | Extract a witness of equality of two types ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 eqT :: forall a b. (Typeable a, Typeable b) => Maybe (a :~: b) eqT = if typeRep (Proxy :: Proxy a) == typeRep (Proxy :: Proxy b)       then Just $ unsafeCoerce Refl
Data/Typeable/Internal.hs view
@@ -1,32 +1,33 @@-{-# LANGUAGE Unsafe             #-}-{-# LANGUAGE ConstraintKinds    #-}+{-# LANGUAGE Trustworthy #-}+{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE CPP #-}+{-# LANGUAGE ConstraintKinds #-}+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE MagicHash #-}+{-# LANGUAGE NoImplicitPrelude #-}+{-# LANGUAGE PolyKinds #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE StandaloneDeriving #-}+{-# LANGUAGE UndecidableInstances #-}  ----------------------------------------------------------------------------- -- | -- Module      :  Data.Typeable.Internal -- Copyright   :  (c) The University of Glasgow, CWI 2001--2011 -- License     :  BSD-style (see the file libraries/base/LICENSE)--- +-- -- The representations of the types TyCon and TypeRep, and the -- function mkTyCon which is used by derived instances of Typeable to -- construct a TyCon. -- ----------------------------------------------------------------------------- -{-# LANGUAGE CPP-           , NoImplicitPrelude-           , OverlappingInstances-           , ScopedTypeVariables-           , FlexibleInstances-           , MagicHash-           , KindSignatures-           , PolyKinds-           , DeriveDataTypeable-           , StandaloneDeriving #-}- module Data.Typeable.Internal (     Proxy (..),     TypeRep(..),+    KindRep,     Fingerprint(..),     typeOf, typeOf1, typeOf2, typeOf3, typeOf4, typeOf5, typeOf6, typeOf7,     Typeable1, Typeable2, Typeable3, Typeable4, Typeable5, Typeable6, Typeable7,@@ -35,36 +36,29 @@     mkTyCon,     mkTyCon3,     mkTyConApp,+    mkPolyTyConApp,     mkAppTy,     typeRepTyCon,     Typeable(..),     mkFunTy,     splitTyConApp,+    splitPolyTyConApp,     funResultTy,     typeRepArgs,+    typeRepFingerprint,+    rnfTypeRep,     showsTypeRep,     tyConString,-    listTc, funTc+    rnfTyCon,+    listTc, funTc,+    typeRepKinds,+    typeLitTypeRep   ) where  import GHC.Base import GHC.Word import GHC.Show-import Data.Maybe import Data.Proxy-import GHC.Num-import GHC.Real--- import GHC.IORef--- import GHC.IOArray--- import GHC.MVar-import GHC.ST           ( ST )-import GHC.STRef        ( STRef )-import GHC.Ptr          ( Ptr, FunPtr )--- import GHC.Stable-import GHC.Arr          ( Array, STArray )-import Data.Type.Coercion-import Data.Type.Equality--- import Data.Int  import GHC.Fingerprint.Type import {-# SOURCE #-} GHC.Fingerprint@@ -75,22 +69,25 @@  -- | A concrete representation of a (monomorphic) type.  'TypeRep' -- supports reasonably efficient equality.-data TypeRep = TypeRep {-# UNPACK #-} !Fingerprint TyCon [TypeRep]+data TypeRep = TypeRep {-# UNPACK #-} !Fingerprint TyCon [KindRep] [TypeRep] +type KindRep = TypeRep+ -- Compare keys for equality instance Eq TypeRep where-  (TypeRep k1 _ _) == (TypeRep k2 _ _) = k1 == k2+  TypeRep x _ _ _ == TypeRep y _ _ _ = x == y  instance Ord TypeRep where-  (TypeRep k1 _ _) <= (TypeRep k2 _ _) = k1 <= k2+  TypeRep x _ _ _ <= TypeRep y _ _ _ = x <= y + -- | An abstract representation of a type constructor.  'TyCon' objects can -- be built using 'mkTyCon'. data TyCon = TyCon {-   tyConHash    :: {-# UNPACK #-} !Fingerprint,-   tyConPackage :: String, -- ^ /Since: 4.5.0.0/-   tyConModule  :: String, -- ^ /Since: 4.5.0.0/-   tyConName    :: String  -- ^ /Since: 4.5.0.0/+   tyConFingerprint :: {-# UNPACK #-} !Fingerprint, -- ^ @since 4.8.0.0+   tyConPackage :: String, -- ^ @since 4.5.0.0+   tyConModule  :: String, -- ^ @since 4.5.0.0+   tyConName    :: String  -- ^ @since 4.5.0.0  }  instance Eq TyCon where@@ -117,26 +114,34 @@ mkTyCon high# low# pkg modl name   = TyCon (Fingerprint (W64# high#) (W64# low#)) pkg modl name --- | Applies a type constructor to a sequence of types-mkTyConApp  :: TyCon -> [TypeRep] -> TypeRep-mkTyConApp tc@(TyCon tc_k _ _ _) []-  = TypeRep tc_k tc [] -- optimisation: all derived Typeable instances-                       -- end up here, and it helps generate smaller-                       -- code for derived Typeable.-mkTyConApp tc@(TyCon tc_k _ _ _) args-  = TypeRep (fingerprintFingerprints (tc_k : arg_ks)) tc args+-- | Applies a polymorhic type constructor to a sequence of kinds and types+mkPolyTyConApp :: TyCon -> [KindRep] -> [TypeRep] -> TypeRep+mkPolyTyConApp tc@(TyCon tc_k _ _ _) [] [] = TypeRep tc_k tc [] []+mkPolyTyConApp tc@(TyCon tc_k _ _ _) kinds types =+  TypeRep (fingerprintFingerprints (tc_k : arg_ks)) tc kinds types   where-    arg_ks = [k | TypeRep k _ _ <- args]+  arg_ks = [ k | TypeRep k _ _ _ <- kinds ++ types ] --- | A special case of 'mkTyConApp', which applies the function +-- | Applies a monomorphic type constructor to a sequence of types+mkTyConApp  :: TyCon -> [TypeRep] -> TypeRep+mkTyConApp tc = mkPolyTyConApp tc []++-- | A special case of 'mkTyConApp', which applies the function -- type constructor to a pair of types. mkFunTy  :: TypeRep -> TypeRep -> TypeRep mkFunTy f a = mkTyConApp funTc [f,a] --- | Splits a type constructor application+-- | Splits a type constructor application.+-- Note that if the type construcotr is polymorphic, this will+-- not return the kinds that were used.+-- See 'splitPolyTyConApp' if you need all parts. splitTyConApp :: TypeRep -> (TyCon,[TypeRep])-splitTyConApp (TypeRep _ tc trs) = (tc,trs)+splitTyConApp (TypeRep _ tc _ trs) = (tc,trs) +-- | Split a type constructor application+splitPolyTyConApp :: TypeRep -> (TyCon,[KindRep],[TypeRep])+splitPolyTyConApp (TypeRep _ tc ks trs) = (tc,ks,trs)+ -- | Applies a type to a function type.  Returns: @'Just' u@ if the -- first argument represents a function of type @t -> u@ and the -- second argument represents a function of type @t@.  Otherwise,@@ -149,10 +154,10 @@  -- | Adds a TypeRep argument to a TypeRep. mkAppTy :: TypeRep -> TypeRep -> TypeRep-mkAppTy (TypeRep _ tc trs) arg_tr = mkTyConApp tc (trs ++ [arg_tr])+mkAppTy (TypeRep _ tc ks trs) arg_tr = mkPolyTyConApp tc ks (trs ++ [arg_tr])    -- Notice that we call mkTyConApp to construct the fingerprint from tc and    -- the arg fingerprints.  Simply combining the current fingerprint with-   -- the new one won't give the same answer, but of course we want to +   -- the new one won't give the same answer, but of course we want to    -- ensure that a TypeRep of the same shape has the same fingerprint!    -- See Trac #5962 @@ -174,17 +179,27 @@  -- | Observe the type constructor of a type representation typeRepTyCon :: TypeRep -> TyCon-typeRepTyCon (TypeRep _ tc _) = tc+typeRepTyCon (TypeRep _ tc _ _) = tc  -- | Observe the argument types of a type representation typeRepArgs :: TypeRep -> [TypeRep]-typeRepArgs (TypeRep _ _ args) = args+typeRepArgs (TypeRep _ _ _ tys) = tys +-- | Observe the argument kinds of a type representation+typeRepKinds :: TypeRep -> [KindRep]+typeRepKinds (TypeRep _ _ ks _) = ks+ -- | Observe string encoding of a type representation {-# DEPRECATED tyConString "renamed to 'tyConName'; 'tyConModule' and 'tyConPackage' are also available." #-} -- deprecated in 7.4 tyConString :: TyCon   -> String tyConString = tyConName +-- | Observe the 'Fingerprint' of a type representation+--+-- @since 4.8.0.0+typeRepFingerprint :: TypeRep -> Fingerprint+typeRepFingerprint (TypeRep fpr _ _ _) = fpr+ ------------------------------------------------------------- -- --      The Typeable class and friends@@ -199,7 +214,7 @@ -- | Takes a value of type @a@ and returns a concrete representation -- of that type. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 typeRep :: forall proxy a. Typeable a => proxy a -> TypeRep typeRep _ = typeRep# (proxy# :: Proxy# a) {-# INLINE typeRep #-}@@ -250,16 +265,11 @@ {-# DEPRECATED Typeable6 "renamed to 'Typeable'" #-} -- deprecated in 7.8 {-# DEPRECATED Typeable7 "renamed to 'Typeable'" #-} -- deprecated in 7.8 --- | Kind-polymorphic Typeable instance for type application-instance (Typeable s, Typeable a) => Typeable (s a) where-  typeRep# = \_ -> rep-    where rep = typeRep# (proxy# :: Proxy# s)-                   `mkAppTy` typeRep# (proxy# :: Proxy# a)  ----------------- Showing TypeReps --------------------  instance Show TypeRep where-  showsPrec p (TypeRep _ tycon tys) =+  showsPrec p (TypeRep _ tycon kinds tys) =     case tys of       [] -> showsPrec p tycon       [x]   | tycon == listTc -> showChar '[' . shows x . showChar ']'@@ -270,9 +280,9 @@       xs | isTupleTyCon tycon -> showTuple xs          | otherwise         ->             showParen (p > 9) $-            showsPrec p tycon . -            showChar ' '      . -            showArgs (showChar ' ') tys+            showsPrec p tycon .+            showChar ' '      .+            showArgs (showChar ' ') (kinds ++ tys)  showsTypeRep :: TypeRep -> ShowS showsTypeRep = shows@@ -284,12 +294,30 @@ isTupleTyCon (TyCon _ _ _ ('(':',':_)) = True isTupleTyCon _                         = False +-- | Helper to fully evaluate 'TypeRep' for use as @NFData(rnf)@ implementation+--+-- @since 4.8.0.0+rnfTypeRep :: TypeRep -> ()+rnfTypeRep (TypeRep _ tyc krs tyrs) = rnfTyCon tyc `seq` go krs `seq` go tyrs+  where+    go [] = ()+    go (x:xs) = rnfTypeRep x `seq` go xs++-- | Helper to fully evaluate 'TyCon' for use as @NFData(rnf)@ implementation+--+-- @since 4.8.0.0+rnfTyCon :: TyCon -> ()+rnfTyCon (TyCon _ tcp tcm tcn) = go tcp `seq` go tcm `seq` go tcn+  where+    go [] = ()+    go (x:xs) = x `seq` go xs+ -- Some (Show.TypeRep) helpers:  showArgs :: Show a => ShowS -> [a] -> ShowS showArgs _   []     = id showArgs _   [a]    = showsPrec 10 a-showArgs sep (a:as) = showsPrec 10 a . sep . showArgs sep as +showArgs sep (a:as) = showsPrec 10 a . sep . showArgs sep as  showTuple :: [TypeRep] -> ShowS showTuple args = showChar '('@@ -302,59 +330,21 @@ funTc :: TyCon funTc = typeRepTyCon (typeRep (Proxy :: Proxy (->))) --------------------------------------------------------------------      Instances of the Typeable classes for Prelude types----------------------------------------------------------------- -deriving instance Typeable ()-deriving instance Typeable []-deriving instance Typeable Maybe-deriving instance Typeable Ratio-deriving instance Typeable (->)-deriving instance Typeable IO -deriving instance Typeable Array+-- | An internal function, to make representations for type literals.+typeLitTypeRep :: String -> TypeRep+typeLitTypeRep nm = rep+    where+    rep = mkTyConApp tc []+    tc = TyCon+           { tyConFingerprint = fingerprintString (mk pack modu nm)+           , tyConPackage  = pack+           , tyConModule   = modu+           , tyConName     = nm+           }+    pack = "base"+    modu = "GHC.TypeLits"+    mk a b c = a ++ " " ++ b ++ " " ++ c -deriving instance Typeable ST-deriving instance Typeable STRef-deriving instance Typeable STArray -deriving instance Typeable (,)-deriving instance Typeable (,,)-deriving instance Typeable (,,,)-deriving instance Typeable (,,,,)-deriving instance Typeable (,,,,,)-deriving instance Typeable (,,,,,,)--deriving instance Typeable Ptr-deriving instance Typeable FunPtr--------------------------------------------------------------- Generate Typeable instances for standard datatypes-------------------------------------------------------------deriving instance Typeable Bool-deriving instance Typeable Char-deriving instance Typeable Float-deriving instance Typeable Double-deriving instance Typeable Int-deriving instance Typeable Word-deriving instance Typeable Integer-deriving instance Typeable Ordering--deriving instance Typeable Word8-deriving instance Typeable Word16-deriving instance Typeable Word32-deriving instance Typeable Word64--deriving instance Typeable TyCon-deriving instance Typeable TypeRep--deriving instance Typeable RealWorld-deriving instance Typeable Proxy-deriving instance Typeable (:~:)-deriving instance Typeable Coercion
− Data/Typeable/Internal.hs-boot
@@ -1,30 +0,0 @@-{-# LANGUAGE Unsafe #-}-{-# LANGUAGE CPP, NoImplicitPrelude, MagicHash, PolyKinds #-}--module Data.Typeable.Internal (-    Proxy(..),-    Typeable(typeRep),-    TypeRep,-    TyCon,-    mkTyCon,-    mkTyConApp-  ) where--import GHC.Base-import {-# SOURCE #-} Data.Proxy--data TypeRep-data TyCon--#include "MachDeps.h"--#if WORD_SIZE_IN_BITS < 64-mkTyCon :: Word64# -> Word64# -> String -> String -> String -> TyCon-#else-mkTyCon :: Word#   -> Word#   -> String -> String -> String -> TyCon-#endif--mkTyConApp   :: TyCon -> [TypeRep] -> TypeRep--class Typeable a where-  typeRep :: proxy a -> TypeRep
Data/Unique.hs view
@@ -1,5 +1,5 @@ {-# LANGUAGE Trustworthy #-}-{-# LANGUAGE MagicHash, DeriveDataTypeable #-}+{-# LANGUAGE MagicHash, AutoDeriveTypeable #-}  ----------------------------------------------------------------------------- -- |@@ -21,8 +21,6 @@    newUnique,    hashUnique  ) where--import Prelude  import System.IO.Unsafe (unsafePerformIO) 
Data/Version.hs view
@@ -1,24 +1,25 @@-{-# LANGUAGE Trustworthy #-}-{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE Safe #-}+{-# LANGUAGE AutoDeriveTypeable #-}+{-# LANGUAGE NoImplicitPrelude #-}  ----------------------------------------------------------------------------- -- | -- Module      :  Data.Version -- Copyright   :  (c) The University of Glasgow 2004 -- License     :  BSD-style (see the file libraries/base/LICENSE)--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  experimental -- Portability :  non-portable (local universal quantification in ReadP) -- -- A general library for representation and manipulation of versions.--- +-- -- Versioning schemes are many and varied, so the version -- representation provided by this library is intended to be a -- compromise between complete generality, where almost no common -- functionality could reasonably be provided, and fixing a particular -- versioning scheme, which would probably be too restrictive.--- +-- -- So the approach taken here is to provide a representation which -- subsumes many of the versioning schemes commonly in use, and we -- provide implementations of 'Eq', 'Ord' and conversion to\/from 'String'@@ -31,19 +32,26 @@         Version(..),         -- * A concrete representation of @Version@         showVersion, parseVersion,+        -- * Constructor function+        makeVersion   ) where -import Prelude -- necessary to get dependencies right--import Text.ParserCombinators.ReadP--import Data.Typeable    ( Typeable )-import Data.List        ( intersperse, sort )-import Control.Monad    ( liftM )+import Control.Monad    ( Monad(..), liftM )+import Data.Bool        ( (&&) ) import Data.Char        ( isDigit, isAlphaNum )+import Data.Eq+import Data.Int         ( Int )+import Data.List+import Data.Ord+import Data.String      ( String )+import Data.Typeable    ( Typeable )+import GHC.Read+import GHC.Show+import Text.ParserCombinators.ReadP+import Text.Read        ( read )  {- |-A 'Version' represents the version of a software entity.  +A 'Version' represents the version of a software entity.  An instance of 'Eq' is provided, which implements exact equality modulo reordering of the tags in the 'versionTags' field.@@ -65,7 +73,7 @@ 'parseVersion'), but depending on the application a different concrete representation may be more appropriate. -}-data Version = +data Version =   Version { versionBranch :: [Int],                 -- ^ The numeric branch for this version.  This reflects the                 -- fact that most software versions are tree-structured; there@@ -74,7 +82,7 @@                 -- version 3 is 3.1, the second branch off the trunk after                 -- version 3 is 3.2, and so on.  The tree can be branched                 -- arbitrarily, just by adding more digits.-                -- +                --                 -- We represent the branch as a list of 'Int', so                 -- version 3.2.1 becomes [3,2,1].  Lexicographic ordering                 -- (i.e. the default instance of 'Ord' for @[Int]@) gives@@ -86,9 +94,11 @@                 -- on the entity that this version applies to.         }   deriving (Read,Show,Typeable)+{-# DEPRECATED versionTags "See GHC ticket #2496" #-}+-- TODO. Remove all references to versionTags in GHC 7.12 release.  instance Eq Version where-  v1 == v2  =  versionBranch v1 == versionBranch v2 +  v1 == v2  =  versionBranch v1 == versionBranch v2                 && sort (versionTags v1) == sort (versionTags v2)                 -- tags may be in any order @@ -99,17 +109,23 @@ -- A concrete representation of 'Version'  -- | Provides one possible concrete representation for 'Version'.  For--- a version with 'versionBranch' @= [1,2,3]@ and 'versionTags' +-- a version with 'versionBranch' @= [1,2,3]@ and 'versionTags' -- @= [\"tag1\",\"tag2\"]@, the output will be @1.2.3-tag1-tag2@. -- showVersion :: Version -> String showVersion (Version branch tags)-  = concat (intersperse "." (map show branch)) ++ +  = concat (intersperse "." (map show branch)) ++      concatMap ('-':) tags  -- | A parser for versions in the format produced by 'showVersion'. -- parseVersion :: ReadP Version-parseVersion = do branch <- sepBy1 (liftM read $ munch1 isDigit) (char '.')+parseVersion = do branch <- sepBy1 (liftM read (munch1 isDigit)) (char '.')                   tags   <- many (char '-' >> munch1 isAlphaNum)                   return Version{versionBranch=branch, versionTags=tags}++-- | Construct tag-less 'Version'+--+-- @since 4.8.0.0+makeVersion :: [Int] -> Version+makeVersion b = Version b []
+ Data/Void.hs view
@@ -0,0 +1,74 @@+{-# LANGUAGE AutoDeriveTypeable #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE EmptyCase #-}+{-# LANGUAGE Safe #-}+{-# LANGUAGE StandaloneDeriving #-}++-----------------------------------------------------------------------------+-- |+-- Copyright   :  (C) 2008-2014 Edward Kmett+-- License     :  BSD-style (see the file libraries/base/LICENSE)+--+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  provisional+-- Portability :  portable+--+-- A logically uninhabited data type, used to indicate that a given+-- term should not exist.+--+-- @since 4.8.0.0+----------------------------------------------------------------------------+module Data.Void+    ( Void+    , absurd+    , vacuous+    ) where++import Control.Exception+import Data.Data+import Data.Ix+import GHC.Generics++-- | Uninhabited data type+--+-- @since 4.8.0.0+data Void deriving (Generic)++deriving instance Data Void++instance Eq Void where+    _ == _ = True++instance Ord Void where+    compare _ _ = EQ++-- | Reading a 'Void' value is always a parse error, considering+-- 'Void' as a data type with no constructors.+instance Read Void where+    readsPrec _ _ = []++instance Show Void where+    showsPrec _ = absurd++instance Ix Void where+    range _     = []+    index _     = absurd+    inRange _   = absurd+    rangeSize _ = 0++instance Exception Void++-- | Since 'Void' values logically don't exist, this witnesses the+-- logical reasoning tool of \"ex falso quodlibet\".+--+-- @since 4.8.0.0+absurd :: Void -> a+absurd a = case a of {}++-- | If 'Void' is uninhabited then any 'Functor' that holds only+-- values of type 'Void' is holding no values.+--+-- @since 4.8.0.0+vacuous :: Functor f => f Void -> f a+vacuous = fmap absurd
Data/Word.hs view
@@ -43,10 +43,8 @@   common cases so should be fast enough.  Coercing word types to and   from integer types preserves representation, not sign. -* It would be very natural to add a type @Natural@ providing an unbounded -  size unsigned integer, just as 'Prelude.Integer' provides unbounded-  size signed integers.  We do not do that yet since there is no demand-  for it.+* An unbounded size unsigned integer type is available with+  'Numeric.Natural.Natural'.  * The rules that hold for 'Prelude.Enum' instances over a bounded type   such as 'Prelude.Int' (see the section of the Haskell report dealing
Debug/Trace.hs view
@@ -1,12 +1,14 @@ {-# LANGUAGE Unsafe #-}-{-# LANGUAGE MagicHash, UnboxedTuples #-}+{-# LANGUAGE MagicHash #-}+{-# LANGUAGE NoImplicitPrelude #-}+{-# LANGUAGE UnboxedTuples #-}  ----------------------------------------------------------------------------- -- | -- Module      :  Debug.Trace -- Copyright   :  (c) The University of Glasgow 2001 -- License     :  BSD-style (see the file libraries/base/LICENSE)--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  provisional -- Portability :  portable@@ -35,22 +37,21 @@         -- $eventlog_tracing         traceEvent,         traceEventIO,-        +         -- * Execution phase markers         -- $markers         traceMarker,         traceMarkerIO,   ) where -import Prelude import System.IO.Unsafe-import Control.Monad  import Foreign.C.String import GHC.Base import qualified GHC.Foreign import GHC.IO.Encoding import GHC.Ptr+import GHC.Show import GHC.Stack import Data.List @@ -59,7 +60,11 @@ -- The 'trace', 'traceShow' and 'traceIO' functions print messages to an output -- stream. They are intended for \"printf debugging\", that is: tracing the flow -- of execution and printing interesting values.-+--+-- All these functions evaluate the message completely before printing+-- it; so if the message is not fully defined, none of it will be+-- printed.+-- -- The usual output stream is 'System.IO.stderr'. For Windows GUI applications -- (that have no stderr) the output is directed to the Windows debug console. -- Some implementations of these functions may decorate the string that\'s@@ -68,7 +73,7 @@ -- | The 'traceIO' function outputs the trace message from the IO monad. -- This sequences the output with respect to other IO actions. ----- /Since: 4.5.0.0/+-- @since 4.5.0.0 traceIO :: String -> IO () traceIO msg = do     withCString "%s\n" $ \cfmt -> do@@ -114,7 +119,7 @@ {-| Like 'trace' but returns the message instead of a third value. -/Since: 4.7.0.0/+@since 4.7.0.0 -} traceId :: String -> String traceId a = trace a a@@ -138,7 +143,7 @@ {-| Like 'traceShow' but returns the shown value instead of a third value. -/Since: 4.7.0.0/+@since 4.7.0.0 -} traceShowId :: (Show a) => a -> a traceShowId a = trace (show a) a@@ -154,7 +159,7 @@ >   y <- ... >   traceM $ "y: " ++ show y -/Since: 4.7.0.0/+@since 4.7.0.0 -} traceM :: (Monad m) => String -> m () traceM string = trace string $ return ()@@ -168,7 +173,7 @@ >   y <- ... >   traceMShow $ x + y -/Since: 4.7.0.0/+@since 4.7.0.0 -} traceShowM :: (Show a, Monad m) => a -> m () traceShowM = traceM . show@@ -182,7 +187,7 @@ -- stack correspond to @SCC@ annotations, so it is a good idea to use -- @-fprof-auto@ or @-fprof-auto-calls@ to add SCC annotations automatically. ----- /Since: 4.5.0.0/+-- @since 4.5.0.0 traceStack :: String -> a -> a traceStack str expr = unsafePerformIO $ do    traceIO str@@ -215,7 +220,7 @@ -- duplicate events emitted if two CPUs simultaneously evaluate the same thunk -- that uses 'traceEvent'. ----- /Since: 4.5.0.0/+-- @since 4.5.0.0 traceEvent :: String -> a -> a traceEvent msg expr = unsafeDupablePerformIO $ do     traceEventIO msg@@ -227,7 +232,7 @@ -- Compared to 'traceEvent', 'traceEventIO' sequences the event with respect to -- other IO actions. ----- /Since: 4.5.0.0/+-- @since 4.5.0.0 traceEventIO :: String -> IO () traceEventIO msg =   GHC.Foreign.withCString utf8 msg $ \(Ptr p) -> IO $ \s ->@@ -245,7 +250,7 @@ -- -- Markers let us do this: we can annotate the program to emit a marker at -- an appropriate point during execution and then see that in a profile.--- +-- -- Currently this feature is only supported in GHC by the eventlog tracing -- system, but in future it may also be supported by the heap profiling or -- other profiling tools. These function exists for other Haskell@@ -265,7 +270,7 @@ -- duplicate events emitted if two CPUs simultaneously evaluate the same thunk -- that uses 'traceMarker'. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 traceMarker :: String -> a -> a traceMarker msg expr = unsafeDupablePerformIO $ do     traceMarkerIO msg@@ -277,7 +282,7 @@ -- Compared to 'traceMarker', 'traceMarkerIO' sequences the event with respect to -- other IO actions. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 traceMarkerIO :: String -> IO () traceMarkerIO msg =   GHC.Foreign.withCString utf8 msg $ \(Ptr p) -> IO $ \s ->
Foreign.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE Unsafe #-}+{-# LANGUAGE Safe #-} {-# LANGUAGE NoImplicitPrelude #-}  -----------------------------------------------------------------------------
Foreign/C/Error.hs view
@@ -6,7 +6,7 @@ -- Module      :  Foreign.C.Error -- Copyright   :  (c) The FFI task force 2001 -- License     :  BSD-style (see the file libraries/base/LICENSE)--- +-- -- Maintainer  :  ffi@haskell.org -- Stability   :  provisional -- Portability :  portable@@ -26,19 +26,19 @@   -- different values of @errno@.  This module defines the common values,   -- but due to the open definition of 'Errno' users may add definitions   -- which are not predefined.-  eOK, e2BIG, eACCES, eADDRINUSE, eADDRNOTAVAIL, eADV, eAFNOSUPPORT, eAGAIN, -  eALREADY, eBADF, eBADMSG, eBADRPC, eBUSY, eCHILD, eCOMM, eCONNABORTED, -  eCONNREFUSED, eCONNRESET, eDEADLK, eDESTADDRREQ, eDIRTY, eDOM, eDQUOT, -  eEXIST, eFAULT, eFBIG, eFTYPE, eHOSTDOWN, eHOSTUNREACH, eIDRM, eILSEQ, -  eINPROGRESS, eINTR, eINVAL, eIO, eISCONN, eISDIR, eLOOP, eMFILE, eMLINK, -  eMSGSIZE, eMULTIHOP, eNAMETOOLONG, eNETDOWN, eNETRESET, eNETUNREACH, -  eNFILE, eNOBUFS, eNODATA, eNODEV, eNOENT, eNOEXEC, eNOLCK, eNOLINK, -  eNOMEM, eNOMSG, eNONET, eNOPROTOOPT, eNOSPC, eNOSR, eNOSTR, eNOSYS, +  eOK, e2BIG, eACCES, eADDRINUSE, eADDRNOTAVAIL, eADV, eAFNOSUPPORT, eAGAIN,+  eALREADY, eBADF, eBADMSG, eBADRPC, eBUSY, eCHILD, eCOMM, eCONNABORTED,+  eCONNREFUSED, eCONNRESET, eDEADLK, eDESTADDRREQ, eDIRTY, eDOM, eDQUOT,+  eEXIST, eFAULT, eFBIG, eFTYPE, eHOSTDOWN, eHOSTUNREACH, eIDRM, eILSEQ,+  eINPROGRESS, eINTR, eINVAL, eIO, eISCONN, eISDIR, eLOOP, eMFILE, eMLINK,+  eMSGSIZE, eMULTIHOP, eNAMETOOLONG, eNETDOWN, eNETRESET, eNETUNREACH,+  eNFILE, eNOBUFS, eNODATA, eNODEV, eNOENT, eNOEXEC, eNOLCK, eNOLINK,+  eNOMEM, eNOMSG, eNONET, eNOPROTOOPT, eNOSPC, eNOSR, eNOSTR, eNOSYS,   eNOTBLK, eNOTCONN, eNOTDIR, eNOTEMPTY, eNOTSOCK, eNOTSUP, eNOTTY, eNXIO,-  eOPNOTSUPP, ePERM, ePFNOSUPPORT, ePIPE, ePROCLIM, ePROCUNAVAIL, -  ePROGMISMATCH, ePROGUNAVAIL, ePROTO, ePROTONOSUPPORT, ePROTOTYPE, -  eRANGE, eREMCHG, eREMOTE, eROFS, eRPCMISMATCH, eRREMOTE, eSHUTDOWN, -  eSOCKTNOSUPPORT, eSPIPE, eSRCH, eSRMNT, eSTALE, eTIME, eTIMEDOUT, +  eOPNOTSUPP, ePERM, ePFNOSUPPORT, ePIPE, ePROCLIM, ePROCUNAVAIL,+  ePROGMISMATCH, ePROGUNAVAIL, ePROTO, ePROTONOSUPPORT, ePROTOTYPE,+  eRANGE, eREMCHG, eREMOTE, eROFS, eRPCMISMATCH, eRREMOTE, eSHUTDOWN,+  eSOCKTNOSUPPORT, eSPIPE, eSRCH, eSRMNT, eSTALE, eTIME, eTIMEDOUT,   eTOOMANYREFS, eTXTBSY, eUSERS, eWOULDBLOCK, eXDEV,    -- ** 'Errno' functions@@ -66,14 +66,14 @@   throwErrnoIfMinus1,   throwErrnoIfMinus1_,   throwErrnoIfMinus1Retry,-  throwErrnoIfMinus1Retry_,  +  throwErrnoIfMinus1Retry_,   throwErrnoIfNull,   throwErrnoIfNullRetry, -  throwErrnoIfRetryMayBlock, +  throwErrnoIfRetryMayBlock,   throwErrnoIfRetryMayBlock_,   throwErrnoIfMinus1RetryMayBlock,-  throwErrnoIfMinus1RetryMayBlock_,  +  throwErrnoIfMinus1RetryMayBlock_,   throwErrnoIfNullRetryMayBlock,    throwErrnoPath,@@ -93,7 +93,7 @@ import Foreign.Ptr import Foreign.C.Types import Foreign.C.String-import Control.Monad            ( void )+import Data.Functor            ( void ) import Data.Maybe  import GHC.IO@@ -112,29 +112,29 @@ newtype Errno = Errno CInt  instance Eq Errno where-  errno1@(Errno no1) == errno2@(Errno no2) +  errno1@(Errno no1) == errno2@(Errno no2)     | isValidErrno errno1 && isValidErrno errno2 = no1 == no2     | otherwise                                  = False  -- common "errno" symbols ---eOK, e2BIG, eACCES, eADDRINUSE, eADDRNOTAVAIL, eADV, eAFNOSUPPORT, eAGAIN, -  eALREADY, eBADF, eBADMSG, eBADRPC, eBUSY, eCHILD, eCOMM, eCONNABORTED, -  eCONNREFUSED, eCONNRESET, eDEADLK, eDESTADDRREQ, eDIRTY, eDOM, eDQUOT, -  eEXIST, eFAULT, eFBIG, eFTYPE, eHOSTDOWN, eHOSTUNREACH, eIDRM, eILSEQ, -  eINPROGRESS, eINTR, eINVAL, eIO, eISCONN, eISDIR, eLOOP, eMFILE, eMLINK, -  eMSGSIZE, eMULTIHOP, eNAMETOOLONG, eNETDOWN, eNETRESET, eNETUNREACH, -  eNFILE, eNOBUFS, eNODATA, eNODEV, eNOENT, eNOEXEC, eNOLCK, eNOLINK, -  eNOMEM, eNOMSG, eNONET, eNOPROTOOPT, eNOSPC, eNOSR, eNOSTR, eNOSYS, +eOK, e2BIG, eACCES, eADDRINUSE, eADDRNOTAVAIL, eADV, eAFNOSUPPORT, eAGAIN,+  eALREADY, eBADF, eBADMSG, eBADRPC, eBUSY, eCHILD, eCOMM, eCONNABORTED,+  eCONNREFUSED, eCONNRESET, eDEADLK, eDESTADDRREQ, eDIRTY, eDOM, eDQUOT,+  eEXIST, eFAULT, eFBIG, eFTYPE, eHOSTDOWN, eHOSTUNREACH, eIDRM, eILSEQ,+  eINPROGRESS, eINTR, eINVAL, eIO, eISCONN, eISDIR, eLOOP, eMFILE, eMLINK,+  eMSGSIZE, eMULTIHOP, eNAMETOOLONG, eNETDOWN, eNETRESET, eNETUNREACH,+  eNFILE, eNOBUFS, eNODATA, eNODEV, eNOENT, eNOEXEC, eNOLCK, eNOLINK,+  eNOMEM, eNOMSG, eNONET, eNOPROTOOPT, eNOSPC, eNOSR, eNOSTR, eNOSYS,   eNOTBLK, eNOTCONN, eNOTDIR, eNOTEMPTY, eNOTSOCK, eNOTSUP, eNOTTY, eNXIO,-  eOPNOTSUPP, ePERM, ePFNOSUPPORT, ePIPE, ePROCLIM, ePROCUNAVAIL, -  ePROGMISMATCH, ePROGUNAVAIL, ePROTO, ePROTONOSUPPORT, ePROTOTYPE, -  eRANGE, eREMCHG, eREMOTE, eROFS, eRPCMISMATCH, eRREMOTE, eSHUTDOWN, -  eSOCKTNOSUPPORT, eSPIPE, eSRCH, eSRMNT, eSTALE, eTIME, eTIMEDOUT, +  eOPNOTSUPP, ePERM, ePFNOSUPPORT, ePIPE, ePROCLIM, ePROCUNAVAIL,+  ePROGMISMATCH, ePROGUNAVAIL, ePROTO, ePROTONOSUPPORT, ePROTOTYPE,+  eRANGE, eREMCHG, eREMOTE, eROFS, eRPCMISMATCH, eRREMOTE, eSHUTDOWN,+  eSOCKTNOSUPPORT, eSPIPE, eSRCH, eSRMNT, eSTALE, eTIME, eTIMEDOUT,   eTOOMANYREFS, eTXTBSY, eUSERS, eWOULDBLOCK, eXDEV                    :: Errno -- -- the cCONST_XXX identifiers are cpp symbols whose value is computed by--- configure +-- configure -- eOK             = Errno 0 e2BIG           = Errno (CONST_E2BIG)@@ -204,7 +204,7 @@ eNOTEMPTY       = Errno (CONST_ENOTEMPTY) eNOTSOCK        = Errno (CONST_ENOTSOCK) eNOTSUP         = Errno (CONST_ENOTSUP)--- ^ /Since: 4.7.0.0/+-- ^ @since 4.7.0.0 eNOTTY          = Errno (CONST_ENOTTY) eNXIO           = Errno (CONST_ENXIO) eOPNOTSUPP      = Errno (CONST_EOPNOTSUPP)@@ -294,7 +294,7 @@                 -> String       -- ^ textual description of the location                 -> IO a         -- ^ the 'IO' operation to be executed                 -> IO a-throwErrnoIf pred loc f  = +throwErrnoIf pred loc f  =   do     res <- f     if pred res then throwErrno loc else return res@@ -310,7 +310,7 @@ -- interrupted POSIX system calls. -- throwErrnoIfRetry            :: (a -> Bool) -> String -> IO a -> IO a-throwErrnoIfRetry pred loc f  = +throwErrnoIfRetry pred loc f  =   do     res <- f     if pred res@@ -321,7 +321,7 @@           else throwErrno loc       else return res --- | as 'throwErrnoIfRetry', but additionally if the operation +-- | as 'throwErrnoIfRetry', but additionally if the operation -- yields the error code 'eAGAIN' or 'eWOULDBLOCK', an alternative -- action is executed before retrying. --@@ -333,7 +333,7 @@                 -> IO b         -- ^ action to execute before retrying if                                 -- an immediate retry would block                 -> IO a-throwErrnoIfRetryMayBlock pred loc f on_block  = +throwErrnoIfRetryMayBlock pred loc f on_block  =   do     res <- f     if pred res@@ -355,7 +355,7 @@ -- | as 'throwErrnoIfRetryMayBlock', but discards the result. -- throwErrnoIfRetryMayBlock_ :: (a -> Bool) -> String -> IO a -> IO b -> IO ()-throwErrnoIfRetryMayBlock_ pred loc f on_block +throwErrnoIfRetryMayBlock_ pred loc f on_block   = void $ throwErrnoIfRetryMayBlock pred loc f on_block  -- | Throw an 'IOError' corresponding to the current value of 'getErrno'
Foreign/C/String.hs view
@@ -6,7 +6,7 @@ -- Module      :  Foreign.C.String -- Copyright   :  (c) The FFI task force 2001 -- License     :  BSD-style (see the file libraries/base/LICENSE)--- +-- -- Maintainer  :  ffi@haskell.org -- Stability   :  provisional -- Portability :  portable@@ -102,8 +102,6 @@  import Data.Word -import Control.Monad- import GHC.Char import GHC.List import GHC.Real@@ -240,7 +238,7 @@ -- | Marshal a C string with explicit length into a Haskell string. -- peekCAStringLen           :: CStringLen -> IO String-peekCAStringLen (cp, len) +peekCAStringLen (cp, len)   | len <= 0  = return "" -- being (too?) nice.   | otherwise = loop [] (len-1)   where
Foreign/C/Types.hs view
@@ -1,11 +1,7 @@ {-# LANGUAGE Trustworthy #-}-{-# LANGUAGE CPP-           , NoImplicitPrelude-           , MagicHash-           , GeneralizedNewtypeDeriving-  #-}+{-# LANGUAGE CPP, NoImplicitPrelude, MagicHash, GeneralizedNewtypeDeriving,+             AutoDeriveTypeable, StandaloneDeriving #-} {-# OPTIONS_GHC -fno-warn-unused-binds #-}-{-# LANGUAGE DeriveDataTypeable, StandaloneDeriving #-} -- XXX -fno-warn-unused-binds stops us warning about unused constructors, -- but really we should just remove them if we don't want them @@ -188,11 +184,11 @@ ARITHMETIC_TYPE(CTime,HTYPE_TIME_T) -- | Haskell type representing the C @useconds_t@ type. ----- /Since: 4.4.0.0/+-- @since 4.4.0.0 ARITHMETIC_TYPE(CUSeconds,HTYPE_USECONDS_T) -- | Haskell type representing the C @suseconds_t@ type. ----- /Since: 4.4.0.0/+-- @since 4.4.0.0 ARITHMETIC_TYPE(CSUSeconds,HTYPE_SUSECONDS_T)  -- FIXME: Implement and provide instances for Eq and Storable
Foreign/ForeignPtr.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE Unsafe #-}+{-# LANGUAGE Trustworthy #-} {-# LANGUAGE NoImplicitPrelude #-}  -----------------------------------------------------------------------------@@ -43,5 +43,5 @@         , mallocForeignPtrArray0     ) where -import Foreign.ForeignPtr.Safe+import Foreign.ForeignPtr.Imp 
Foreign/ForeignPtr/Safe.hs view
@@ -19,7 +19,7 @@ -- ----------------------------------------------------------------------------- -module Foreign.ForeignPtr.Safe (+module Foreign.ForeignPtr.Safe {-# DEPRECATED "Safe is now the default, please use Foreign.ForeignPtr instead" #-} (         -- * Finalised data pointers           ForeignPtr         , FinalizerPtr
Foreign/Marshal.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE Unsafe #-}+{-# LANGUAGE Safe #-} {-# LANGUAGE NoImplicitPrelude #-}  -----------------------------------------------------------------------------@@ -17,10 +17,18 @@  module Foreign.Marshal         (-         -- | The module "Foreign.Marshal" re-exports the safe content in the-         -- @Foreign.Marshal@ hierarchy:-          module Foreign.Marshal.Safe+         -- | The module "Foreign.Marshal.Safe" re-exports the other modules in the+         -- @Foreign.Marshal@ hierarchy (except for @Foreign.Marshal.Unsafe@):+          module Foreign.Marshal.Alloc+        , module Foreign.Marshal.Array+        , module Foreign.Marshal.Error+        , module Foreign.Marshal.Pool+        , module Foreign.Marshal.Utils         ) where -import Foreign.Marshal.Safe+import Foreign.Marshal.Alloc+import Foreign.Marshal.Array+import Foreign.Marshal.Error+import Foreign.Marshal.Pool+import Foreign.Marshal.Utils 
Foreign/Marshal/Alloc.hs view
@@ -1,8 +1,5 @@ {-# LANGUAGE Trustworthy #-}-{-# LANGUAGE NoImplicitPrelude-           , MagicHash-           , UnboxedTuples-  #-}+{-# LANGUAGE NoImplicitPrelude, MagicHash, UnboxedTuples #-}  ----------------------------------------------------------------------------- -- |@@ -52,6 +49,9 @@   malloc,   mallocBytes, +  calloc,+  callocBytes,+   realloc,   reallocBytes, @@ -85,6 +85,15 @@     doMalloc       :: Storable b => b -> IO (Ptr b)     doMalloc dummy  = mallocBytes (sizeOf dummy) +-- |Like 'malloc' but memory is filled with bytes of value zero.+--+{-# INLINE calloc #-}+calloc :: Storable a => IO (Ptr a)+calloc = doCalloc undefined+  where+    doCalloc       :: Storable b => b -> IO (Ptr b)+    doCalloc dummy = callocBytes (sizeOf dummy)+ -- |Allocate a block of memory of the given number of bytes. -- The block of memory is sufficiently aligned for any of the basic -- foreign types that fits into a memory block of the allocated size.@@ -95,6 +104,11 @@ mallocBytes      :: Int -> IO (Ptr a) mallocBytes size  = failWhenNULL "malloc" (_malloc (fromIntegral size)) +-- |Llike 'mallocBytes' but memory is filled with bytes of value zero.+--+callocBytes :: Int -> IO (Ptr a)+callocBytes size = failWhenNULL "calloc" $ _calloc 1 (fromIntegral size)+ -- |@'alloca' f@ executes the computation @f@, passing as argument -- a pointer to a temporarily allocated block of memory sufficient to -- hold values of type @a@.@@ -201,6 +215,7 @@ -- basic C routines needed for memory allocation -- foreign import ccall unsafe "stdlib.h malloc"  _malloc  ::          CSize -> IO (Ptr a)+foreign import ccall unsafe "stdlib.h calloc"  _calloc  :: CSize -> CSize -> IO (Ptr a) foreign import ccall unsafe "stdlib.h realloc" _realloc :: Ptr a -> CSize -> IO (Ptr b) foreign import ccall unsafe "stdlib.h free"    _free    :: Ptr a -> IO () 
Foreign/Marshal/Array.hs view
@@ -30,6 +30,9 @@   reallocArray,   reallocArray0, +  callocArray,+  callocArray0,+   -- ** Marshalling   --   peekArray,@@ -66,7 +69,7 @@  import Foreign.Ptr      (Ptr, plusPtr) import Foreign.Storable (Storable(alignment,sizeOf,peekElemOff,pokeElemOff))-import Foreign.Marshal.Alloc (mallocBytes, allocaBytesAligned, reallocBytes)+import Foreign.Marshal.Alloc (mallocBytes, callocBytes, allocaBytesAligned, reallocBytes) import Foreign.Marshal.Utils (copyBytes, moveBytes)  import GHC.Num@@ -90,6 +93,20 @@ -- mallocArray0      :: Storable a => Int -> IO (Ptr a) mallocArray0 size  = mallocArray (size + 1)++-- |Like 'mallocArray', but allocated memory is filled with bytes of value zero.+--+callocArray :: Storable a => Int -> IO (Ptr a)+callocArray  = doCalloc undefined+  where+    doCalloc :: Storable a' => a' -> Int -> IO (Ptr a')+    doCalloc dummy size  = callocBytes (size * sizeOf dummy)++-- |Like 'callocArray0', but allocated memory is filled with bytes of value+-- zero.+--+callocArray0 :: Storable a => Int -> IO (Ptr a)+callocArray0 size  = callocArray (size + 1)  -- |Temporarily allocate space for the given number of elements -- (like 'Foreign.Marshal.Alloc.alloca', but for multiple elements).
Foreign/Marshal/Pool.hs view
@@ -6,7 +6,7 @@ -- Module      :  Foreign.Marshal.Pool -- Copyright   :  (c) Sven Panne 2002-2004 -- License     :  BSD-style (see the file libraries/base/LICENSE)--- +-- -- Maintainer  :  sven.panne@aedion.de -- Stability   :  provisional -- Portability :  portable@@ -46,7 +46,7 @@    pooledNewArray0 ) where -import GHC.Base              ( Int, Monad(..), (.), not )+import GHC.Base              ( Int, Monad(..), (.), liftM, not ) import GHC.Err               ( undefined ) import GHC.Exception         ( throw ) import GHC.IO                ( IO, mask, catchAny )@@ -54,8 +54,7 @@ import GHC.List              ( elem, length ) import GHC.Num               ( Num(..) ) -import Control.Monad         ( liftM )-import Data.List             ( delete )+import Data.OldList          ( delete ) import Foreign.Marshal.Alloc ( mallocBytes, reallocBytes, free ) import Foreign.Marshal.Array ( pokeArray, pokeArray0 ) import Foreign.Marshal.Error ( throwIf )
Foreign/Marshal/Safe.hs view
@@ -17,7 +17,7 @@ -- ----------------------------------------------------------------------------- -module Foreign.Marshal.Safe+module Foreign.Marshal.Safe {-# DEPRECATED "Safe is now the default, please use Foreign.Marshal instead" #-}         (          -- | The module "Foreign.Marshal.Safe" re-exports the other modules in the          -- @Foreign.Marshal@ hierarchy:
Foreign/Marshal/Utils.hs view
@@ -43,13 +43,18 @@   --   copyBytes,   moveBytes,++  -- ** Filling up memory area with required values+  --+  fillBytes, ) where  import Data.Maybe import Foreign.Ptr              ( Ptr, nullPtr ) import Foreign.Storable         ( Storable(poke) )-import Foreign.C.Types          ( CSize(..) )+import Foreign.C.Types          ( CSize(..), CInt(..) ) import Foreign.Marshal.Alloc    ( malloc, alloca )+import Data.Word                ( Word8 )  import GHC.Real                 ( fromIntegral ) import GHC.Num@@ -161,7 +166,17 @@ moveBytes dest src size  = do _ <- memmove dest src (fromIntegral size)                               return () +-- Filling up memory area with required values+-- ------------------------------------------- +-- |Fill a given number of bytes in memory area with a byte value.+--+-- @since 4.8.0.0+fillBytes               :: Ptr a -> Word8 -> Int -> IO ()+fillBytes dest char size = do+  _ <- memset dest (fromIntegral char) (fromIntegral size)+  return ()+ -- auxilliary routines -- ------------------- @@ -169,4 +184,4 @@ -- foreign import ccall unsafe "string.h" memcpy  :: Ptr a -> Ptr a -> CSize -> IO (Ptr a) foreign import ccall unsafe "string.h" memmove :: Ptr a -> Ptr a -> CSize -> IO (Ptr a)-+foreign import ccall unsafe "string.h" memset  :: Ptr a -> CInt  -> CSize -> IO (Ptr a)
Foreign/Ptr.hs view
@@ -1,10 +1,6 @@ {-# LANGUAGE Trustworthy #-}-{-# LANGUAGE CPP-           , NoImplicitPrelude-           , MagicHash-           , GeneralizedNewtypeDeriving-  #-}-{-# LANGUAGE DeriveDataTypeable, StandaloneDeriving #-}+{-# LANGUAGE CPP, NoImplicitPrelude, MagicHash, GeneralizedNewtypeDeriving,+             AutoDeriveTypeable, StandaloneDeriving #-}  ----------------------------------------------------------------------------- -- |
Foreign/Safe.hs view
@@ -18,23 +18,23 @@ -- ----------------------------------------------------------------------------- -module Foreign.Safe+module Foreign.Safe {-# DEPRECATED "Safe is now the default, please use Foreign instead" #-}         ( module Data.Bits         , module Data.Int         , module Data.Word         , module Foreign.Ptr-        , module Foreign.ForeignPtr.Safe+        , module Foreign.ForeignPtr         , module Foreign.StablePtr         , module Foreign.Storable-        , module Foreign.Marshal.Safe+        , module Foreign.Marshal         ) where  import Data.Bits import Data.Int import Data.Word import Foreign.Ptr-import Foreign.ForeignPtr.Safe+import Foreign.ForeignPtr import Foreign.StablePtr import Foreign.Storable-import Foreign.Marshal.Safe+import Foreign.Marshal 
Foreign/Storable.hs view
@@ -1,6 +1,5 @@ {-# LANGUAGE Trustworthy #-}-{-# LANGUAGE CPP, NoImplicitPrelude, ScopedTypeVariables #-}-{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE CPP, NoImplicitPrelude, ScopedTypeVariables, BangPatterns #-}  ----------------------------------------------------------------------------- -- |@@ -32,8 +31,6 @@         ) where  -import Control.Monad            ( liftM )- #include "MachDeps.h" #include "HsBaseConfig.h" @@ -73,13 +70,12 @@ 'Int32', 'Int64'), the fixed size @Word@ types ('Word8', 'Word16', 'Word32', 'Word64'), 'StablePtr', all types from "Foreign.C.Types", as well as 'Ptr'.--Minimal complete definition: 'sizeOf', 'alignment', one of 'peek',-'peekElemOff' and 'peekByteOff', and one of 'poke', 'pokeElemOff' and-'pokeByteOff'. -}  class Storable a where+   {-# MINIMAL sizeOf, alignment,+               (peek | peekElemOff | peekByteOff),+               (poke | pokeElemOff | pokeByteOff) #-}     sizeOf      :: a -> Int    -- ^ Computes the storage requirements (in bytes) of the argument.@@ -149,10 +145,6 @@    peek ptr = peekElemOff ptr 0    poke ptr = pokeElemOff ptr 0 -   {-# MINIMAL sizeOf, alignment,-               (peek | peekElemOff | peekByteOff),-               (poke | pokeElemOff | pokeByteOff) #-}- -- System-dependent, but rather obvious instances  instance Storable Bool where@@ -215,6 +207,19 @@  STORABLE(Int64,SIZEOF_INT64,ALIGNMENT_INT64,          readInt64OffPtr,writeInt64OffPtr)++instance (Storable a, Integral a) => Storable (Ratio a) where+    sizeOf _    = 2 * sizeOf (undefined :: a)+    alignment _ = alignment (undefined :: a )+    peek p           = do+                        q <- return $ castPtr p+                        r <- peek q+                        i <- peekElemOff q 1+                        return (r % i)+    poke p (r :% i)  = do+                        q <-return $  (castPtr p)+                        poke q r+                        pokeElemOff q 1 i  -- XXX: here to avoid orphan instance in GHC.Fingerprint instance Storable Fingerprint where
+ GHC/Arr.hs view
@@ -0,0 +1,899 @@+{-# LANGUAGE Unsafe #-}+{-# LANGUAGE NoImplicitPrelude, MagicHash, UnboxedTuples, RoleAnnotations #-}+{-# OPTIONS_HADDOCK hide #-}++-----------------------------------------------------------------------------+-- |+-- Module      :  GHC.Arr+-- Copyright   :  (c) The University of Glasgow, 1994-2000+-- License     :  see libraries/base/LICENSE+--+-- Maintainer  :  cvs-ghc@haskell.org+-- Stability   :  internal+-- Portability :  non-portable (GHC extensions)+--+-- GHC\'s array implementation.+--+-----------------------------------------------------------------------------++module GHC.Arr (+        Ix(..), Array(..), STArray(..),++        indexError, hopelessIndexError,+        arrEleBottom, array, listArray,+        (!), safeRangeSize, negRange, safeIndex, badSafeIndex,+        bounds, numElements, numElementsSTArray, indices, elems,+        assocs, accumArray, adjust, (//), accum,+        amap, ixmap,+        eqArray, cmpArray, cmpIntArray,+        newSTArray, boundsSTArray,+        readSTArray, writeSTArray,+        freezeSTArray, thawSTArray,+        foldlElems, foldlElems', foldl1Elems,+        foldrElems, foldrElems', foldr1Elems,++        -- * Unsafe operations+        fill, done,+        unsafeArray, unsafeArray',+        lessSafeIndex, unsafeAt, unsafeReplace,+        unsafeAccumArray, unsafeAccumArray', unsafeAccum,+        unsafeReadSTArray, unsafeWriteSTArray,+        unsafeFreezeSTArray, unsafeThawSTArray,+    ) where++import GHC.Enum+import GHC.Num+import GHC.ST+import GHC.Base+import GHC.List+import GHC.Real( fromIntegral )+import GHC.Show++infixl 9  !, //++default ()++-- | The 'Ix' class is used to map a contiguous subrange of values in+-- a type onto integers.  It is used primarily for array indexing+-- (see the array package).+--+-- The first argument @(l,u)@ of each of these operations is a pair+-- specifying the lower and upper bounds of a contiguous subrange of values.+--+-- An implementation is entitled to assume the following laws about these+-- operations:+--+-- * @'inRange' (l,u) i == 'elem' i ('range' (l,u))@ @ @+--+-- * @'range' (l,u) '!!' 'index' (l,u) i == i@, when @'inRange' (l,u) i@+--+-- * @'map' ('index' (l,u)) ('range' (l,u))) == [0..'rangeSize' (l,u)-1]@ @ @+--+-- * @'rangeSize' (l,u) == 'length' ('range' (l,u))@ @ @+--+class (Ord a) => Ix a where+    {-# MINIMAL range, (index | unsafeIndex), inRange #-}++    -- | The list of values in the subrange defined by a bounding pair.+    range               :: (a,a) -> [a]+    -- | The position of a subscript in the subrange.+    index               :: (a,a) -> a -> Int+    -- | Like 'index', but without checking that the value is in range.+    unsafeIndex         :: (a,a) -> a -> Int+    -- | Returns 'True' the given subscript lies in the range defined+    -- the bounding pair.+    inRange             :: (a,a) -> a -> Bool+    -- | The size of the subrange defined by a bounding pair.+    rangeSize           :: (a,a) -> Int+    -- | like 'rangeSize', but without checking that the upper bound is+    -- in range.+    unsafeRangeSize     :: (a,a) -> Int++        -- Must specify one of index, unsafeIndex++        -- 'index' is typically over-ridden in instances, with essentially+        -- the same code, but using indexError instead of hopelessIndexError+        -- Reason: we have 'Show' at the instances+    {-# INLINE index #-}  -- See Note [Inlining index]+    index b i | inRange b i = unsafeIndex b i+              | otherwise   = hopelessIndexError++    unsafeIndex b i = index b i++    rangeSize b@(_l,h) | inRange b h = unsafeIndex b h + 1+                       | 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++{-+Note that the following is NOT right+        rangeSize (l,h) | l <= h    = index b h + 1+                        | otherwise = 0++Because it might be the case that l<h, but the range+is nevertheless empty.  Consider+        ((1,2),(2,1))+Here l<h, but the second index ranges from 2..1 and+hence is empty+++Note [Inlining index]+~~~~~~~~~~~~~~~~~~~~~+We inline the 'index' operation,++ * Partly because it generates much faster code+   (although bigger); see Trac #1216++ * Partly because it exposes the bounds checks to the simplifier which+   might help a big.++If you make a per-instance index method, you may consider inlining it.++Note [Double bounds-checking of index values]+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+When you index an array, a!x, there are two possible bounds checks we might make:++  (A) Check that (inRange (bounds a) x) holds.++      (A) is checked in the method for 'index'++  (B) Check that (index (bounds a) x) lies in the range 0..n,+      where n is the size of the underlying array++      (B) is checked in the top-level function (!), in safeIndex.++Of course it *should* be the case that (A) holds iff (B) holds, but that+is a property of the particular instances of index, bounds, and inRange,+so GHC cannot guarantee it.++ * If you do (A) and not (B), then you might get a seg-fault,+   by indexing at some bizarre location.  Trac #1610++ * If you do (B) but not (A), you may get no complaint when you index+   an array out of its semantic bounds.  Trac #2120++At various times we have had (A) and not (B), or (B) and not (A); both+led to complaints.  So now we implement *both* checks (Trac #2669).++For 1-d, 2-d, and 3-d arrays of Int we have specialised instances to avoid this.++Note [Out-of-bounds error messages]+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+The default method for 'index' generates hoplelessIndexError, because+Ix doesn't have Show as a superclass.  For particular base types we+can do better, so we override the default method for index.+-}++-- Abstract these errors from the relevant index functions so that+-- the guts of the function will be small enough to inline.++{-# NOINLINE indexError #-}+indexError :: Show a => (a,a) -> a -> String -> b+indexError rng i tp+  = error (showString "Ix{" . showString tp . showString "}.index: Index " .+           showParen True (showsPrec 0 i) .+           showString " out of range " $+           showParen True (showsPrec 0 rng) "")++hopelessIndexError :: Int -- Try to use 'indexError' instead!+hopelessIndexError = error "Error in array index"++----------------------------------------------------------------------+instance  Ix Char  where+    {-# INLINE range #-}+    range (m,n) = [m..n]++    {-# INLINE unsafeIndex #-}+    unsafeIndex (m,_n) i = fromEnum i - fromEnum m++    {-# INLINE index #-}  -- See Note [Out-of-bounds error messages]+                          -- and Note [Inlining index]+    index b i | inRange b i =  unsafeIndex b i+              | otherwise   =  indexError b i "Char"++    inRange (m,n) i     =  m <= i && i <= n++----------------------------------------------------------------------+instance  Ix Int  where+    {-# INLINE range #-}+        -- The INLINE stops the build in the RHS from getting inlined,+        -- so that callers can fuse with the result of range+    range (m,n) = [m..n]++    {-# INLINE unsafeIndex #-}+    unsafeIndex (m,_n) i = i - m++    {-# INLINE index #-}  -- See Note [Out-of-bounds error messages]+                          -- and Note [Inlining index]+    index b i | inRange b i =  unsafeIndex b i+              | otherwise   =  indexError b i "Int"++    {-# INLINE inRange #-}+    inRange (I# m,I# n) (I# i) =  isTrue# (m <=# i) && isTrue# (i <=# n)++instance Ix Word where+    range (m,n)         = [m..n]+    unsafeIndex (m,_) i = fromIntegral (i - m)+    inRange (m,n) i     = m <= i && i <= n++----------------------------------------------------------------------+instance  Ix Integer  where+    {-# INLINE range #-}+    range (m,n) = [m..n]++    {-# INLINE unsafeIndex #-}+    unsafeIndex (m,_n) i   = fromInteger (i - m)++    {-# INLINE index #-}  -- See Note [Out-of-bounds error messages]+                          -- and Note [Inlining index]+    index b i | inRange b i =  unsafeIndex b i+              | otherwise   =  indexError b i "Integer"++    inRange (m,n) i     =  m <= i && i <= n++----------------------------------------------------------------------+instance Ix Bool where -- as derived+    {-# INLINE range #-}+    range (m,n) = [m..n]++    {-# INLINE unsafeIndex #-}+    unsafeIndex (l,_) i = fromEnum i - fromEnum l++    {-# INLINE index #-}  -- See Note [Out-of-bounds error messages]+                          -- and Note [Inlining index]+    index b i | inRange b i =  unsafeIndex b i+              | otherwise   =  indexError b i "Bool"++    inRange (l,u) i = fromEnum i >= fromEnum l && fromEnum i <= fromEnum u++----------------------------------------------------------------------+instance Ix Ordering where -- as derived+    {-# INLINE range #-}+    range (m,n) = [m..n]++    {-# INLINE unsafeIndex #-}+    unsafeIndex (l,_) i = fromEnum i - fromEnum l++    {-# INLINE index #-}  -- See Note [Out-of-bounds error messages]+                          -- and Note [Inlining index]+    index b i | inRange b i =  unsafeIndex b i+              | otherwise   =  indexError b i "Ordering"++    inRange (l,u) i = fromEnum i >= fromEnum l && fromEnum i <= fromEnum u++----------------------------------------------------------------------+instance Ix () where+    {-# INLINE range #-}+    range   ((), ())    = [()]+    {-# INLINE unsafeIndex #-}+    unsafeIndex   ((), ()) () = 0+    {-# INLINE inRange #-}+    inRange ((), ()) () = True++    {-# INLINE index #-}  -- See Note [Inlining index]+    index b i = unsafeIndex b i++----------------------------------------------------------------------+instance (Ix a, Ix b) => Ix (a, b) where -- as derived+    {-# SPECIALISE instance Ix (Int,Int) #-}++    {-# INLINE range #-}+    range ((l1,l2),(u1,u2)) =+      [ (i1,i2) | i1 <- range (l1,u1), i2 <- range (l2,u2) ]++    {-# INLINE unsafeIndex #-}+    unsafeIndex ((l1,l2),(u1,u2)) (i1,i2) =+      unsafeIndex (l1,u1) i1 * unsafeRangeSize (l2,u2) + unsafeIndex (l2,u2) i2++    {-# INLINE inRange #-}+    inRange ((l1,l2),(u1,u2)) (i1,i2) =+      inRange (l1,u1) i1 && inRange (l2,u2) i2++    -- Default method for index++----------------------------------------------------------------------+instance  (Ix a1, Ix a2, Ix a3) => Ix (a1,a2,a3)  where+    {-# SPECIALISE instance Ix (Int,Int,Int) #-}++    range ((l1,l2,l3),(u1,u2,u3)) =+        [(i1,i2,i3) | i1 <- range (l1,u1),+                      i2 <- range (l2,u2),+                      i3 <- range (l3,u3)]++    unsafeIndex ((l1,l2,l3),(u1,u2,u3)) (i1,i2,i3) =+      unsafeIndex (l3,u3) i3 + unsafeRangeSize (l3,u3) * (+      unsafeIndex (l2,u2) i2 + unsafeRangeSize (l2,u2) * (+      unsafeIndex (l1,u1) i1))++    inRange ((l1,l2,l3),(u1,u2,u3)) (i1,i2,i3) =+      inRange (l1,u1) i1 && inRange (l2,u2) i2 &&+      inRange (l3,u3) i3++    -- Default method for index++----------------------------------------------------------------------+instance  (Ix a1, Ix a2, Ix a3, Ix a4) => Ix (a1,a2,a3,a4)  where+    range ((l1,l2,l3,l4),(u1,u2,u3,u4)) =+      [(i1,i2,i3,i4) | i1 <- range (l1,u1),+                       i2 <- range (l2,u2),+                       i3 <- range (l3,u3),+                       i4 <- range (l4,u4)]++    unsafeIndex ((l1,l2,l3,l4),(u1,u2,u3,u4)) (i1,i2,i3,i4) =+      unsafeIndex (l4,u4) i4 + unsafeRangeSize (l4,u4) * (+      unsafeIndex (l3,u3) i3 + unsafeRangeSize (l3,u3) * (+      unsafeIndex (l2,u2) i2 + unsafeRangeSize (l2,u2) * (+      unsafeIndex (l1,u1) i1)))++    inRange ((l1,l2,l3,l4),(u1,u2,u3,u4)) (i1,i2,i3,i4) =+      inRange (l1,u1) i1 && inRange (l2,u2) i2 &&+      inRange (l3,u3) i3 && inRange (l4,u4) i4++    -- Default method for index++instance  (Ix a1, Ix a2, Ix a3, Ix a4, Ix a5) => Ix (a1,a2,a3,a4,a5)  where+    range ((l1,l2,l3,l4,l5),(u1,u2,u3,u4,u5)) =+      [(i1,i2,i3,i4,i5) | i1 <- range (l1,u1),+                          i2 <- range (l2,u2),+                          i3 <- range (l3,u3),+                          i4 <- range (l4,u4),+                          i5 <- range (l5,u5)]++    unsafeIndex ((l1,l2,l3,l4,l5),(u1,u2,u3,u4,u5)) (i1,i2,i3,i4,i5) =+      unsafeIndex (l5,u5) i5 + unsafeRangeSize (l5,u5) * (+      unsafeIndex (l4,u4) i4 + unsafeRangeSize (l4,u4) * (+      unsafeIndex (l3,u3) i3 + unsafeRangeSize (l3,u3) * (+      unsafeIndex (l2,u2) i2 + unsafeRangeSize (l2,u2) * (+      unsafeIndex (l1,u1) i1))))++    inRange ((l1,l2,l3,l4,l5),(u1,u2,u3,u4,u5)) (i1,i2,i3,i4,i5) =+      inRange (l1,u1) i1 && inRange (l2,u2) i2 &&+      inRange (l3,u3) i3 && inRange (l4,u4) i4 &&+      inRange (l5,u5) i5++    -- Default method for index++-- | The type of immutable non-strict (boxed) arrays+-- with indices in @i@ and elements in @e@.+data Array i e+   = Array            !i         -- the lower bound, l+                      !i         -- the upper bound, u+       {-# UNPACK #-} !Int       -- A cache of (rangeSize (l,u))+                                 -- used to make sure an index is+                                 -- really in range+                      (Array# e) -- The actual elements++-- | Mutable, boxed, non-strict arrays in the 'ST' monad.  The type+-- arguments are as follows:+--+--  * @s@: the state variable argument for the 'ST' type+--+--  * @i@: the index type of the array (should be an instance of 'Ix')+--+--  * @e@: the element type of the array.+--+data STArray s i e+  = STArray           !i               -- the lower bound, l+                      !i               -- the upper bound, u+      {-# UNPACK #-}  !Int             -- A cache of (rangeSize (l,u))+                                       -- used to make sure an index is+                                       -- really in range+                   (MutableArray# s e) -- The actual elements+        -- No Ix context for STArray.  They are stupid,+        -- and force an Ix context on the equality instance.++-- Index types should have nominal role, because of Ix class. See also #9220.+type role Array nominal representational+type role STArray nominal nominal representational++-- Just pointer equality on mutable arrays:+instance Eq (STArray s i e) where+    STArray _ _ _ arr1# == STArray _ _ _ arr2# =+        isTrue# (sameMutableArray# arr1# arr2#)++----------------------------------------------------------------------+-- Operations on immutable arrays++{-# NOINLINE arrEleBottom #-}+arrEleBottom :: a+arrEleBottom = error "(Array.!): undefined array element"++-- | Construct an array with the specified bounds and containing values+-- for given indices within these bounds.+--+-- The array is undefined (i.e. bottom) if any index in the list is+-- out of bounds.  The Haskell 2010 Report further specifies that if any+-- two associations in the list have the same index, the value at that+-- index is undefined (i.e. bottom).  However in GHC's implementation,+-- the value at such an index is the value part of the last association+-- with that index in the list.+--+-- Because the indices must be checked for these errors, 'array' is+-- strict in the bounds argument and in the indices of the association+-- list, but non-strict in the values.  Thus, recurrences such as the+-- following are possible:+--+-- > a = array (1,100) ((1,1) : [(i, i * a!(i-1)) | i <- [2..100]])+--+-- Not every index within the bounds of the array need appear in the+-- association list, but the values associated with indices that do not+-- appear will be undefined (i.e. bottom).+--+-- If, in any dimension, the lower bound is greater than the upper bound,+-- then the array is legal, but empty.  Indexing an empty array always+-- gives an array-bounds error, but 'bounds' still yields the bounds+-- with which the array was constructed.+{-# INLINE array #-}+array :: Ix i+        => (i,i)        -- ^ a pair of /bounds/, each of the index type+                        -- of the array.  These bounds are the lowest and+                        -- highest indices in the array, in that order.+                        -- For example, a one-origin vector of length+                        -- '10' has bounds '(1,10)', and a one-origin '10'+                        -- by '10' matrix has bounds '((1,1),(10,10))'.+        -> [(i, e)]     -- ^ a list of /associations/ of the form+                        -- (/index/, /value/).  Typically, this list will+                        -- be expressed as a comprehension.  An+                        -- association '(i, x)' defines the value of+                        -- the array at index 'i' to be 'x'.+        -> Array i e+array (l,u) ies+    = let n = safeRangeSize (l,u)+      in unsafeArray' (l,u) n+                      [(safeIndex (l,u) n i, e) | (i, e) <- ies]++{-# INLINE unsafeArray #-}+unsafeArray :: Ix i => (i,i) -> [(Int, e)] -> Array i e+unsafeArray b ies = unsafeArray' b (rangeSize b) ies++{-# INLINE unsafeArray' #-}+unsafeArray' :: Ix i => (i,i) -> Int -> [(Int, e)] -> Array i e+unsafeArray' (l,u) n@(I# n#) ies = runST (ST $ \s1# ->+    case newArray# n# arrEleBottom s1# of+        (# s2#, marr# #) ->+            foldr (fill marr#) (done l u n marr#) ies s2#)++{-# INLINE fill #-}+fill :: MutableArray# s e -> (Int, e) -> STRep s a -> STRep s a+-- NB: put the \s after the "=" so that 'fill'+--     inlines when applied to three args+fill marr# (I# i#, e) next+ = \s1# -> case writeArray# marr# i# e s1# of+             s2# -> next s2#++{-# INLINE done #-}+done :: Ix i => i -> i -> Int -> MutableArray# s e -> STRep s (Array i e)+-- See NB on 'fill'+-- Make sure it is strict in 'n'+done l u n@(I# _) marr#+  = \s1# -> case unsafeFreezeArray# marr# s1# of+              (# s2#, arr# #) -> (# s2#, Array l u n arr# #)++-- | Construct an array from a pair of bounds and a list of values in+-- index order.+{-# INLINE listArray #-}+listArray :: Ix i => (i,i) -> [e] -> Array i e+listArray (l,u) es = runST (ST $ \s1# ->+    case safeRangeSize (l,u)            of { n@(I# n#) ->+    case newArray# n# arrEleBottom s1#  of { (# s2#, marr# #) ->+      let+        go y r = \ i# s3# ->+            case writeArray# marr# i# y s3# of+              s4# -> if (isTrue# (i# ==# n# -# 1#))+                     then s4#+                     else r (i# +# 1#) s4#+      in+        done l u n marr# (+          if n == 0+          then s2#+          else foldr go (\_ s# -> s#) es 0# s2#)}})++-- | The value at the given index in an array.+{-# INLINE (!) #-}+(!) :: Ix i => Array i e -> i -> e+arr@(Array l u n _) ! i = unsafeAt arr $ safeIndex (l,u) n i++{-# INLINE safeRangeSize #-}+safeRangeSize :: Ix i => (i, i) -> Int+safeRangeSize (l,u) = let r = rangeSize (l, u)+                      in if r < 0 then negRange+                                  else r++-- Don't inline this error message everywhere!!+negRange :: Int   -- Uninformative, but Ix does not provide Show+negRange = error "Negative range size"++{-# INLINE[1] safeIndex #-}+-- See Note [Double bounds-checking of index values]+-- Inline *after* (!) so the rules can fire+-- Make sure it is strict in n+safeIndex :: Ix i => (i, i) -> Int -> i -> Int+safeIndex (l,u) n@(I# _) i+  | (0 <= i') && (i' < n) = i'+  | otherwise             = badSafeIndex i' n+  where+    i' = index (l,u) i++-- See Note [Double bounds-checking of index values]+{-# RULES+"safeIndex/I"       safeIndex = lessSafeIndex :: (Int,Int) -> Int -> Int -> Int+"safeIndex/(I,I)"   safeIndex = lessSafeIndex :: ((Int,Int),(Int,Int)) -> Int -> (Int,Int) -> Int+"safeIndex/(I,I,I)" safeIndex = lessSafeIndex :: ((Int,Int,Int),(Int,Int,Int)) -> Int -> (Int,Int,Int) -> Int+  #-}++lessSafeIndex :: Ix i => (i, i) -> Int -> i -> Int+-- See Note [Double bounds-checking of index values]+-- Do only (A), the semantic check+lessSafeIndex (l,u) _ i = index (l,u) i++-- Don't inline this long error message everywhere!!+badSafeIndex :: Int -> Int -> Int+badSafeIndex i' n = error ("Error in array index; " ++ show i' +++                        " not in range [0.." ++ show n ++ ")")++{-# INLINE unsafeAt #-}+unsafeAt :: Ix i => Array i e -> Int -> e+unsafeAt (Array _ _ _ arr#) (I# i#) =+    case indexArray# arr# i# of (# e #) -> e++-- | The bounds with which an array was constructed.+{-# INLINE bounds #-}+bounds :: Ix i => Array i e -> (i,i)+bounds (Array l u _ _) = (l,u)++-- | The number of elements in the array.+{-# INLINE numElements #-}+numElements :: Ix i => Array i e -> Int+numElements (Array _ _ n _) = n++-- | The list of indices of an array in ascending order.+{-# INLINE indices #-}+indices :: Ix i => Array i e -> [i]+indices (Array l u _ _) = range (l,u)++-- | The list of elements of an array in index order.+{-# INLINE elems #-}+elems :: Ix i => Array i e -> [e]+elems arr@(Array _ _ n _) =+    [unsafeAt arr i | i <- [0 .. n - 1]]++-- | A right fold over the elements+{-# INLINABLE foldrElems #-}+foldrElems :: Ix i => (a -> b -> b) -> b -> Array i a -> b+foldrElems f b0 = \ arr@(Array _ _ n _) ->+  let+    go i | i == n    = b0+         | otherwise = f (unsafeAt arr i) (go (i+1))+  in go 0++-- | A left fold over the elements+{-# INLINABLE foldlElems #-}+foldlElems :: Ix i => (b -> a -> b) -> b -> Array i a -> b+foldlElems f b0 = \ arr@(Array _ _ n _) ->+  let+    go i | i == (-1) = b0+         | otherwise = f (go (i-1)) (unsafeAt arr i)+  in go (n-1)++-- | A strict right fold over the elements+{-# INLINABLE foldrElems' #-}+foldrElems' :: Ix i => (a -> b -> b) -> b -> Array i a -> b+foldrElems' f b0 = \ arr@(Array _ _ n _) ->+  let+    go i a | i == (-1) = a+           | otherwise = go (i-1) (f (unsafeAt arr i) $! a)+  in go (n-1) b0++-- | A strict left fold over the elements+{-# INLINABLE foldlElems' #-}+foldlElems' :: Ix i => (b -> a -> b) -> b -> Array i a -> b+foldlElems' f b0 = \ arr@(Array _ _ n _) ->+  let+    go i a | i == n    = a+           | otherwise = go (i+1) (a `seq` f a (unsafeAt arr i))+  in go 0 b0++-- | A left fold over the elements with no starting value+{-# INLINABLE foldl1Elems #-}+foldl1Elems :: Ix i => (a -> a -> a) -> Array i a -> a+foldl1Elems f = \ arr@(Array _ _ n _) ->+  let+    go i | i == 0    = unsafeAt arr 0+         | otherwise = f (go (i-1)) (unsafeAt arr i)+  in+    if n == 0 then error "foldl1: empty Array" else go (n-1)++-- | A right fold over the elements with no starting value+{-# INLINABLE foldr1Elems #-}+foldr1Elems :: Ix i => (a -> a -> a) -> Array i a -> a+foldr1Elems f = \ arr@(Array _ _ n _) ->+  let+    go i | i == n-1  = unsafeAt arr i+         | otherwise = f (unsafeAt arr i) (go (i + 1))+  in+    if n == 0 then error "foldr1: empty Array" else go 0++-- | The list of associations of an array in index order.+{-# INLINE assocs #-}+assocs :: Ix i => Array i e -> [(i, e)]+assocs arr@(Array l u _ _) =+    [(i, arr ! i) | i <- range (l,u)]++-- | The 'accumArray' function deals with repeated indices in the association+-- list using an /accumulating function/ which combines the values of+-- associations with the same index.+-- For example, given a list of values of some index type, @hist@+-- produces a histogram of the number of occurrences of each index within+-- a specified range:+--+-- > hist :: (Ix a, Num b) => (a,a) -> [a] -> Array a b+-- > hist bnds is = accumArray (+) 0 bnds [(i, 1) | i<-is, inRange bnds i]+--+-- If the accumulating function is strict, then 'accumArray' is strict in+-- the values, as well as the indices, in the association list.  Thus,+-- unlike ordinary arrays built with 'array', accumulated arrays should+-- not in general be recursive.+{-# INLINE accumArray #-}+accumArray :: Ix i+        => (e -> a -> e)        -- ^ accumulating function+        -> e                    -- ^ initial value+        -> (i,i)                -- ^ bounds of the array+        -> [(i, a)]             -- ^ association list+        -> Array i e+accumArray f initial (l,u) ies =+    let n = safeRangeSize (l,u)+    in unsafeAccumArray' f initial (l,u) n+                         [(safeIndex (l,u) n i, e) | (i, e) <- ies]++{-# INLINE unsafeAccumArray #-}+unsafeAccumArray :: Ix i => (e -> a -> e) -> e -> (i,i) -> [(Int, a)] -> Array i e+unsafeAccumArray f initial b ies = unsafeAccumArray' f initial b (rangeSize b) ies++{-# INLINE unsafeAccumArray' #-}+unsafeAccumArray' :: Ix i => (e -> a -> e) -> e -> (i,i) -> Int -> [(Int, a)] -> Array i e+unsafeAccumArray' f initial (l,u) n@(I# n#) ies = runST (ST $ \s1# ->+    case newArray# n# initial s1#          of { (# s2#, marr# #) ->+    foldr (adjust f marr#) (done l u n marr#) ies s2# })++{-# INLINE adjust #-}+adjust :: (e -> a -> e) -> MutableArray# s e -> (Int, a) -> STRep s b -> STRep s b+-- See NB on 'fill'+adjust f marr# (I# i#, new) next+  = \s1# -> case readArray# marr# i# s1# of+                (# s2#, old #) ->+                    case writeArray# marr# i# (f old new) s2# of+                        s3# -> next s3#++-- | Constructs an array identical to the first argument except that it has+-- been updated by the associations in the right argument.+-- For example, if @m@ is a 1-origin, @n@ by @n@ matrix, then+--+-- > m//[((i,i), 0) | i <- [1..n]]+--+-- is the same matrix, except with the diagonal zeroed.+--+-- Repeated indices in the association list are handled as for 'array':+-- Haskell 2010 specifies that the resulting array is undefined (i.e. bottom),+-- but GHC's implementation uses the last association for each index.+{-# INLINE (//) #-}+(//) :: Ix i => Array i e -> [(i, e)] -> Array i e+arr@(Array l u n _) // ies =+    unsafeReplace arr [(safeIndex (l,u) n i, e) | (i, e) <- ies]++{-# INLINE unsafeReplace #-}+unsafeReplace :: Ix i => Array i e -> [(Int, e)] -> Array i e+unsafeReplace arr ies = runST (do+    STArray l u n marr# <- thawSTArray arr+    ST (foldr (fill marr#) (done l u n marr#) ies))++-- | @'accum' f@ takes an array and an association list and accumulates+-- pairs from the list into the array with the accumulating function @f@.+-- Thus 'accumArray' can be defined using 'accum':+--+-- > accumArray f z b = accum f (array b [(i, z) | i <- range b])+--+{-# INLINE accum #-}+accum :: Ix i => (e -> a -> e) -> Array i e -> [(i, a)] -> Array i e+accum f arr@(Array l u n _) ies =+    unsafeAccum f arr [(safeIndex (l,u) n i, e) | (i, e) <- ies]++{-# INLINE unsafeAccum #-}+unsafeAccum :: Ix i => (e -> a -> e) -> Array i e -> [(Int, a)] -> Array i e+unsafeAccum f arr ies = runST (do+    STArray l u n marr# <- thawSTArray arr+    ST (foldr (adjust f marr#) (done l u n marr#) ies))++{-# INLINE [1] amap #-}+amap :: Ix i => (a -> b) -> Array i a -> Array i b+amap f arr@(Array l u n@(I# n#) _) = runST (ST $ \s1# ->+    case newArray# n# arrEleBottom s1# of+        (# s2#, marr# #) ->+          let go i s#+                | i == n    = done l u n marr# s#+                | otherwise = fill marr# (i, f (unsafeAt arr i)) (go (i+1)) s#+          in go 0 s2# )++{-+amap was originally defined like this:++ amap f arr@(Array l u n _) =+     unsafeArray' (l,u) n [(i, f (unsafeAt arr i)) | i <- [0 .. n - 1]]++There are two problems:++1. The enumFromTo implementation produces (spurious) code for the impossible+case of n<0 that ends up duplicating the array freezing code.++2. This implementation relies on list fusion for efficiency. In order to+implement the amap/coerce rule, we need to delay inlining amap until simplifier+phase 1, which is when the eftIntList rule kicks in and makes that impossible.+-}+++-- See Breitner, Eisenberg, Peyton Jones, and Weirich, "Safe Zero-cost+-- Coercions for Haskell", section 6.5:+--   http://research.microsoft.com/en-us/um/people/simonpj/papers/ext-f/coercible.pdf+{-# RULES+"amap/coerce" amap coerce = coerce+ #-}++-- Second functor law:+{-# RULES+"amap/amap" forall f g a . amap f (amap g a) = amap (f . g) a+ #-}++-- | 'ixmap' allows for transformations on array indices.+-- It may be thought of as providing function composition on the right+-- with the mapping that the original array embodies.+--+-- A similar transformation of array values may be achieved using 'fmap'+-- from the 'Array' instance of the 'Functor' class.+{-# INLINE ixmap #-}+ixmap :: (Ix i, Ix j) => (i,i) -> (i -> j) -> Array j e -> Array i e+ixmap (l,u) f arr =+    array (l,u) [(i, arr ! f i) | i <- range (l,u)]++{-# INLINE eqArray #-}+eqArray :: (Ix i, Eq e) => Array i e -> Array i e -> Bool+eqArray arr1@(Array l1 u1 n1 _) arr2@(Array l2 u2 n2 _) =+    if n1 == 0 then n2 == 0 else+    l1 == l2 && u1 == u2 &&+    and [unsafeAt arr1 i == unsafeAt arr2 i | i <- [0 .. n1 - 1]]++{-# INLINE [1] cmpArray #-}+cmpArray :: (Ix i, Ord e) => Array i e -> Array i e -> Ordering+cmpArray arr1 arr2 = compare (assocs arr1) (assocs arr2)++{-# INLINE cmpIntArray #-}+cmpIntArray :: Ord e => Array Int e -> Array Int e -> Ordering+cmpIntArray arr1@(Array l1 u1 n1 _) arr2@(Array l2 u2 n2 _) =+    if n1 == 0 then+        if n2 == 0 then EQ else LT+    else if n2 == 0 then GT+    else case compare l1 l2 of+             EQ    -> foldr cmp (compare u1 u2) [0 .. (n1 `min` n2) - 1]+             other -> other+  where+    cmp i rest = case compare (unsafeAt arr1 i) (unsafeAt arr2 i) of+        EQ    -> rest+        other -> other++{-# RULES "cmpArray/Int" cmpArray = cmpIntArray #-}++----------------------------------------------------------------------+-- Array instances++instance Ix i => Functor (Array i) where+    fmap = amap++instance (Ix i, Eq e) => Eq (Array i e) where+    (==) = eqArray++instance (Ix i, Ord e) => Ord (Array i e) where+    compare = cmpArray++instance (Ix a, Show a, Show b) => Show (Array a b) where+    showsPrec p a =+        showParen (p > appPrec) $+        showString "array " .+        showsPrec appPrec1 (bounds a) .+        showChar ' ' .+        showsPrec appPrec1 (assocs a)+        -- Precedence of 'array' is the precedence of application++-- The Read instance is in GHC.Read++----------------------------------------------------------------------+-- Operations on mutable arrays++{-+Idle ADR question: What's the tradeoff here between flattening these+datatypes into @STArray ix ix (MutableArray# s elt)@ and using+it as is?  As I see it, the former uses slightly less heap and+provides faster access to the individual parts of the bounds while the+code used has the benefit of providing a ready-made @(lo, hi)@ pair as+required by many array-related functions.  Which wins? Is the+difference significant (probably not).++Idle AJG answer: When I looked at the outputted code (though it was 2+years ago) it seems like you often needed the tuple, and we build+it frequently. Now we've got the overloading specialiser things+might be different, though.+-}++{-# INLINE newSTArray #-}+newSTArray :: Ix i => (i,i) -> e -> ST s (STArray s i e)+newSTArray (l,u) initial = ST $ \s1# ->+    case safeRangeSize (l,u)            of { n@(I# n#) ->+    case newArray# n# initial s1#       of { (# s2#, marr# #) ->+    (# s2#, STArray l u n marr# #) }}++{-# INLINE boundsSTArray #-}+boundsSTArray :: STArray s i e -> (i,i)+boundsSTArray (STArray l u _ _) = (l,u)++{-# INLINE numElementsSTArray #-}+numElementsSTArray :: STArray s i e -> Int+numElementsSTArray (STArray _ _ n _) = n++{-# INLINE readSTArray #-}+readSTArray :: Ix i => STArray s i e -> i -> ST s e+readSTArray marr@(STArray l u n _) i =+    unsafeReadSTArray marr (safeIndex (l,u) n i)++{-# INLINE unsafeReadSTArray #-}+unsafeReadSTArray :: Ix i => STArray s i e -> Int -> ST s e+unsafeReadSTArray (STArray _ _ _ marr#) (I# i#)+    = ST $ \s1# -> readArray# marr# i# s1#++{-# INLINE writeSTArray #-}+writeSTArray :: Ix i => STArray s i e -> i -> e -> ST s ()+writeSTArray marr@(STArray l u n _) i e =+    unsafeWriteSTArray marr (safeIndex (l,u) n i) e++{-# INLINE unsafeWriteSTArray #-}+unsafeWriteSTArray :: Ix i => STArray s i e -> Int -> e -> ST s ()+unsafeWriteSTArray (STArray _ _ _ marr#) (I# i#) e = ST $ \s1# ->+    case writeArray# marr# i# e s1# of+        s2# -> (# s2#, () #)++----------------------------------------------------------------------+-- Moving between mutable and immutable++freezeSTArray :: Ix i => STArray s i e -> ST s (Array i e)+freezeSTArray (STArray l u n@(I# n#) marr#) = ST $ \s1# ->+    case newArray# n# arrEleBottom s1#  of { (# s2#, marr'# #) ->+    let copy i# s3# | isTrue# (i# ==# n#) = s3#+                    | otherwise =+            case readArray# marr# i# s3# of { (# s4#, e #) ->+            case writeArray# marr'# i# e s4# of { s5# ->+            copy (i# +# 1#) s5# }} in+    case copy 0# s2#                    of { s3# ->+    case unsafeFreezeArray# marr'# s3#  of { (# s4#, arr# #) ->+    (# s4#, Array l u n arr# #) }}}++{-# INLINE unsafeFreezeSTArray #-}+unsafeFreezeSTArray :: Ix i => STArray s i e -> ST s (Array i e)+unsafeFreezeSTArray (STArray l u n marr#) = ST $ \s1# ->+    case unsafeFreezeArray# marr# s1#   of { (# s2#, arr# #) ->+    (# s2#, Array l u n arr# #) }++thawSTArray :: Ix i => Array i e -> ST s (STArray s i e)+thawSTArray (Array l u n@(I# n#) arr#) = ST $ \s1# ->+    case newArray# n# arrEleBottom s1#  of { (# s2#, marr# #) ->+    let copy i# s3# | isTrue# (i# ==# n#) = s3#+                    | otherwise =+            case indexArray# arr# i#    of { (# e #) ->+            case writeArray# marr# i# e s3# of { s4# ->+            copy (i# +# 1#) s4# }} in+    case copy 0# s2#                    of { s3# ->+    (# s3#, STArray l u n marr# #) }}++{-# INLINE unsafeThawSTArray #-}+unsafeThawSTArray :: Ix i => Array i e -> ST s (STArray s i e)+unsafeThawSTArray (Array l u n arr#) = ST $ \s1# ->+    case unsafeThawArray# arr# s1#      of { (# s2#, marr# #) ->+    (# s2#, STArray l u n marr# #) }
− GHC/Arr.lhs
@@ -1,849 +0,0 @@-\begin{code}-{-# LANGUAGE Unsafe #-}-{-# LANGUAGE NoImplicitPrelude, MagicHash, UnboxedTuples #-}-{-# OPTIONS_GHC -funbox-strict-fields #-}-{-# OPTIONS_HADDOCK hide #-}---------------------------------------------------------------------------------- |--- Module      :  GHC.Arr--- Copyright   :  (c) The University of Glasgow, 1994-2000--- License     :  see libraries/base/LICENSE------ Maintainer  :  cvs-ghc@haskell.org--- Stability   :  internal--- Portability :  non-portable (GHC extensions)------ GHC\'s array implementation.-----------------------------------------------------------------------------------module GHC.Arr (-        Ix(..), Array(..), STArray(..),--        indexError, hopelessIndexError,-        arrEleBottom, array, listArray,-        (!), safeRangeSize, negRange, safeIndex, badSafeIndex,-        bounds, numElements, numElementsSTArray, indices, elems,-        assocs, accumArray, adjust, (//), accum,-        amap, ixmap,-        eqArray, cmpArray, cmpIntArray,-        newSTArray, boundsSTArray,-        readSTArray, writeSTArray,-        freezeSTArray, thawSTArray,--        -- * Unsafe operations-        fill, done,-        unsafeArray, unsafeArray',-        lessSafeIndex, unsafeAt, unsafeReplace,-        unsafeAccumArray, unsafeAccumArray', unsafeAccum,-        unsafeReadSTArray, unsafeWriteSTArray,-        unsafeFreezeSTArray, unsafeThawSTArray,-    ) where--import GHC.Enum-import GHC.Num-import GHC.ST-import GHC.Base-import GHC.List-import GHC.Real( fromIntegral )-import GHC.Show--infixl 9  !, //--default ()-\end{code}---%*********************************************************-%*                                                      *-\subsection{The @Ix@ class}-%*                                                      *-%*********************************************************--\begin{code}--- | The 'Ix' class is used to map a contiguous subrange of values in--- a type onto integers.  It is used primarily for array indexing--- (see the array package).------ The first argument @(l,u)@ of each of these operations is a pair--- specifying the lower and upper bounds of a contiguous subrange of values.------ An implementation is entitled to assume the following laws about these--- operations:------ * @'inRange' (l,u) i == 'elem' i ('range' (l,u))@ @ @------ * @'range' (l,u) '!!' 'index' (l,u) i == i@, when @'inRange' (l,u) i@------ * @'map' ('index' (l,u)) ('range' (l,u))) == [0..'rangeSize' (l,u)-1]@ @ @------ * @'rangeSize' (l,u) == 'length' ('range' (l,u))@ @ @------ Minimal complete instance: 'range', 'index' and 'inRange'.----class (Ord a) => Ix a where-    -- | The list of values in the subrange defined by a bounding pair.-    range               :: (a,a) -> [a]-    -- | The position of a subscript in the subrange.-    index               :: (a,a) -> a -> Int-    -- | Like 'index', but without checking that the value is in range.-    unsafeIndex         :: (a,a) -> a -> Int-    -- | Returns 'True' the given subscript lies in the range defined-    -- the bounding pair.-    inRange             :: (a,a) -> a -> Bool-    -- | The size of the subrange defined by a bounding pair.-    rangeSize           :: (a,a) -> Int-    -- | like 'rangeSize', but without checking that the upper bound is-    -- in range.-    unsafeRangeSize     :: (a,a) -> Int--        -- Must specify one of index, unsafeIndex--	-- 'index' is typically over-ridden in instances, with essentially-	-- the same code, but using indexError instead of hopelessIndexError-	-- Reason: we have 'Show' at the instances-    {-# INLINE index #-}  -- See Note [Inlining index]-    index b i | inRange b i = unsafeIndex b i-              | otherwise   = hopelessIndexError--    unsafeIndex b i = index b i--    rangeSize b@(_l,h) | inRange b h = unsafeIndex b h + 1-                       | 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-        rangeSize (l,h) | l <= h    = index b h + 1-                        | otherwise = 0--Because it might be the case that l<h, but the range-is nevertheless empty.  Consider-        ((1,2),(2,1))-Here l<h, but the second index ranges from 2..1 and-hence is empty--%*********************************************************-%*                                                      *-\subsection{Instances of @Ix@}-%*                                                      *-%*********************************************************--Note [Inlining index]-~~~~~~~~~~~~~~~~~~~~~-We inline the 'index' operation,-- * Partly because it generates much faster code-   (although bigger); see Trac #1216-- * Partly because it exposes the bounds checks to the simplifier which-   might help a big.--If you make a per-instance index method, you may consider inlining it.--Note [Double bounds-checking of index values]-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-When you index an array, a!x, there are two possible bounds checks we might make:--  (A) Check that (inRange (bounds a) x) holds.--      (A) is checked in the method for 'index'--  (B) Check that (index (bounds a) x) lies in the range 0..n,-      where n is the size of the underlying array--      (B) is checked in the top-level function (!), in safeIndex.--Of course it *should* be the case that (A) holds iff (B) holds, but that-is a property of the particular instances of index, bounds, and inRange,-so GHC cannot guarantee it.-- * If you do (A) and not (B), then you might get a seg-fault,-   by indexing at some bizarre location.  Trac #1610-- * If you do (B) but not (A), you may get no complaint when you index-   an array out of its semantic bounds.  Trac #2120--At various times we have had (A) and not (B), or (B) and not (A); both-led to complaints.  So now we implement *both* checks (Trac #2669).--For 1-d, 2-d, and 3-d arrays of Int we have specialised instances to avoid this.--Note [Out-of-bounds error messages]-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-The default method for 'index' generates hoplelessIndexError, because-Ix doesn't have Show as a superclass.  For particular base types we-can do better, so we override the default method for index.--\begin{code}--- Abstract these errors from the relevant index functions so that--- the guts of the function will be small enough to inline.--{-# NOINLINE indexError #-}-indexError :: Show a => (a,a) -> a -> String -> b-indexError rng i tp-  = error (showString "Ix{" . showString tp . showString "}.index: Index " .-           showParen True (showsPrec 0 i) .-           showString " out of range " $-           showParen True (showsPrec 0 rng) "")--hopelessIndexError :: Int -- Try to use 'indexError' instead!-hopelessIndexError = error "Error in array index"-------------------------------------------------------------------------instance  Ix Char  where-    {-# INLINE range #-}-    range (m,n) = [m..n]--    {-# INLINE unsafeIndex #-}-    unsafeIndex (m,_n) i = fromEnum i - fromEnum m--    {-# INLINE index #-}  -- See Note [Out-of-bounds error messages]-                          -- and Note [Inlining index]-    index b i | inRange b i =  unsafeIndex b i-              | otherwise   =  indexError b i "Char"--    inRange (m,n) i     =  m <= i && i <= n-------------------------------------------------------------------------instance  Ix Int  where-    {-# INLINE range #-}-        -- The INLINE stops the build in the RHS from getting inlined,-        -- so that callers can fuse with the result of range-    range (m,n) = [m..n]--    {-# INLINE unsafeIndex #-}-    unsafeIndex (m,_n) i = i - m--    {-# INLINE index #-}  -- See Note [Out-of-bounds error messages]-                          -- and Note [Inlining index]-    index b i | inRange b i =  unsafeIndex b i-              | otherwise   =  indexError b i "Int"--    {-# INLINE inRange #-}-    inRange (I# m,I# n) (I# i) =  isTrue# (m <=# i) && isTrue# (i <=# n)--instance Ix Word where-    range (m,n)         = [m..n]-    unsafeIndex (m,_) i = fromIntegral (i - m)-    inRange (m,n) i     = m <= i && i <= n-------------------------------------------------------------------------instance  Ix Integer  where-    {-# INLINE range #-}-    range (m,n) = [m..n]--    {-# INLINE unsafeIndex #-}-    unsafeIndex (m,_n) i   = fromInteger (i - m)--    {-# INLINE index #-}  -- See Note [Out-of-bounds error messages]-                          -- and Note [Inlining index]-    index b i | inRange b i =  unsafeIndex b i-              | otherwise   =  indexError b i "Integer"--    inRange (m,n) i     =  m <= i && i <= n-------------------------------------------------------------------------instance Ix Bool where -- as derived-    {-# INLINE range #-}-    range (m,n) = [m..n]--    {-# INLINE unsafeIndex #-}-    unsafeIndex (l,_) i = fromEnum i - fromEnum l--    {-# INLINE index #-}  -- See Note [Out-of-bounds error messages]-                          -- and Note [Inlining index]-    index b i | inRange b i =  unsafeIndex b i-              | otherwise   =  indexError b i "Bool"--    inRange (l,u) i = fromEnum i >= fromEnum l && fromEnum i <= fromEnum u-------------------------------------------------------------------------instance Ix Ordering where -- as derived-    {-# INLINE range #-}-    range (m,n) = [m..n]--    {-# INLINE unsafeIndex #-}-    unsafeIndex (l,_) i = fromEnum i - fromEnum l--    {-# INLINE index #-}  -- See Note [Out-of-bounds error messages]-                          -- and Note [Inlining index]-    index b i | inRange b i =  unsafeIndex b i-              | otherwise   =  indexError b i "Ordering"--    inRange (l,u) i = fromEnum i >= fromEnum l && fromEnum i <= fromEnum u-------------------------------------------------------------------------instance Ix () where-    {-# INLINE range #-}-    range   ((), ())    = [()]-    {-# INLINE unsafeIndex #-}-    unsafeIndex   ((), ()) () = 0-    {-# INLINE inRange #-}-    inRange ((), ()) () = True--    {-# INLINE index #-}  -- See Note [Inlining index]-    index b i = unsafeIndex b i-------------------------------------------------------------------------instance (Ix a, Ix b) => Ix (a, b) where -- as derived-    {-# SPECIALISE instance Ix (Int,Int) #-}--    {-# INLINE range #-}-    range ((l1,l2),(u1,u2)) =-      [ (i1,i2) | i1 <- range (l1,u1), i2 <- range (l2,u2) ]--    {-# INLINE unsafeIndex #-}-    unsafeIndex ((l1,l2),(u1,u2)) (i1,i2) =-      unsafeIndex (l1,u1) i1 * unsafeRangeSize (l2,u2) + unsafeIndex (l2,u2) i2--    {-# INLINE inRange #-}-    inRange ((l1,l2),(u1,u2)) (i1,i2) =-      inRange (l1,u1) i1 && inRange (l2,u2) i2--    -- Default method for index-------------------------------------------------------------------------instance  (Ix a1, Ix a2, Ix a3) => Ix (a1,a2,a3)  where-    {-# SPECIALISE instance Ix (Int,Int,Int) #-}--    range ((l1,l2,l3),(u1,u2,u3)) =-        [(i1,i2,i3) | i1 <- range (l1,u1),-                      i2 <- range (l2,u2),-                      i3 <- range (l3,u3)]--    unsafeIndex ((l1,l2,l3),(u1,u2,u3)) (i1,i2,i3) =-      unsafeIndex (l3,u3) i3 + unsafeRangeSize (l3,u3) * (-      unsafeIndex (l2,u2) i2 + unsafeRangeSize (l2,u2) * (-      unsafeIndex (l1,u1) i1))--    inRange ((l1,l2,l3),(u1,u2,u3)) (i1,i2,i3) =-      inRange (l1,u1) i1 && inRange (l2,u2) i2 &&-      inRange (l3,u3) i3--    -- Default method for index-------------------------------------------------------------------------instance  (Ix a1, Ix a2, Ix a3, Ix a4) => Ix (a1,a2,a3,a4)  where-    range ((l1,l2,l3,l4),(u1,u2,u3,u4)) =-      [(i1,i2,i3,i4) | i1 <- range (l1,u1),-                       i2 <- range (l2,u2),-                       i3 <- range (l3,u3),-                       i4 <- range (l4,u4)]--    unsafeIndex ((l1,l2,l3,l4),(u1,u2,u3,u4)) (i1,i2,i3,i4) =-      unsafeIndex (l4,u4) i4 + unsafeRangeSize (l4,u4) * (-      unsafeIndex (l3,u3) i3 + unsafeRangeSize (l3,u3) * (-      unsafeIndex (l2,u2) i2 + unsafeRangeSize (l2,u2) * (-      unsafeIndex (l1,u1) i1)))--    inRange ((l1,l2,l3,l4),(u1,u2,u3,u4)) (i1,i2,i3,i4) =-      inRange (l1,u1) i1 && inRange (l2,u2) i2 &&-      inRange (l3,u3) i3 && inRange (l4,u4) i4--    -- Default method for index--instance  (Ix a1, Ix a2, Ix a3, Ix a4, Ix a5) => Ix (a1,a2,a3,a4,a5)  where-    range ((l1,l2,l3,l4,l5),(u1,u2,u3,u4,u5)) =-      [(i1,i2,i3,i4,i5) | i1 <- range (l1,u1),-                          i2 <- range (l2,u2),-                          i3 <- range (l3,u3),-                          i4 <- range (l4,u4),-                          i5 <- range (l5,u5)]--    unsafeIndex ((l1,l2,l3,l4,l5),(u1,u2,u3,u4,u5)) (i1,i2,i3,i4,i5) =-      unsafeIndex (l5,u5) i5 + unsafeRangeSize (l5,u5) * (-      unsafeIndex (l4,u4) i4 + unsafeRangeSize (l4,u4) * (-      unsafeIndex (l3,u3) i3 + unsafeRangeSize (l3,u3) * (-      unsafeIndex (l2,u2) i2 + unsafeRangeSize (l2,u2) * (-      unsafeIndex (l1,u1) i1))))--    inRange ((l1,l2,l3,l4,l5),(u1,u2,u3,u4,u5)) (i1,i2,i3,i4,i5) =-      inRange (l1,u1) i1 && inRange (l2,u2) i2 &&-      inRange (l3,u3) i3 && inRange (l4,u4) i4 &&-      inRange (l5,u5) i5--    -- Default method for index-\end{code}--%*********************************************************-%*                                                      *-\subsection{The @Array@ types}-%*                                                      *-%*********************************************************--\begin{code}--- | The type of immutable non-strict (boxed) arrays--- with indices in @i@ and elements in @e@.-data Array i e-         = Array !i         -- the lower bound, l-                 !i         -- the upper bound, u-                 !Int       -- a cache of (rangeSize (l,u))-                            -- used to make sure an index is-                            -- really in range-                 (Array# e) -- The actual elements---- | Mutable, boxed, non-strict arrays in the 'ST' monad.  The type--- arguments are as follows:------  * @s@: the state variable argument for the 'ST' type------  * @i@: the index type of the array (should be an instance of 'Ix')------  * @e@: the element type of the array.----data STArray s i e-         = STArray !i                  -- the lower bound, l-                   !i                  -- the upper bound, u-                   !Int                -- a cache of (rangeSize (l,u))-                                       -- used to make sure an index is-                                       -- really in range-                   (MutableArray# s e) -- The actual elements-        -- No Ix context for STArray.  They are stupid,-        -- and force an Ix context on the equality instance.---- Just pointer equality on mutable arrays:-instance Eq (STArray s i e) where-    STArray _ _ _ arr1# == STArray _ _ _ arr2# =-        isTrue# (sameMutableArray# arr1# arr2#)-\end{code}---%*********************************************************-%*                                                      *-\subsection{Operations on immutable arrays}-%*                                                      *-%*********************************************************--\begin{code}-{-# NOINLINE arrEleBottom #-}-arrEleBottom :: a-arrEleBottom = error "(Array.!): undefined array element"---- | Construct an array with the specified bounds and containing values--- for given indices within these bounds.------ The array is undefined (i.e. bottom) if any index in the list is--- out of bounds.  The Haskell 2010 Report further specifies that if any--- two associations in the list have the same index, the value at that--- index is undefined (i.e. bottom).  However in GHC's implementation,--- the value at such an index is the value part of the last association--- with that index in the list.------ Because the indices must be checked for these errors, 'array' is--- strict in the bounds argument and in the indices of the association--- list, but non-strict in the values.  Thus, recurrences such as the--- following are possible:------ > a = array (1,100) ((1,1) : [(i, i * a!(i-1)) | i <- [2..100]])------ Not every index within the bounds of the array need appear in the--- association list, but the values associated with indices that do not--- appear will be undefined (i.e. bottom).------ If, in any dimension, the lower bound is greater than the upper bound,--- then the array is legal, but empty.  Indexing an empty array always--- gives an array-bounds error, but 'bounds' still yields the bounds--- with which the array was constructed.-{-# INLINE array #-}-array :: Ix i-        => (i,i)        -- ^ a pair of /bounds/, each of the index type-                        -- of the array.  These bounds are the lowest and-                        -- highest indices in the array, in that order.-                        -- For example, a one-origin vector of length-                        -- '10' has bounds '(1,10)', and a one-origin '10'-                        -- by '10' matrix has bounds '((1,1),(10,10))'.-        -> [(i, e)]     -- ^ a list of /associations/ of the form-                        -- (/index/, /value/).  Typically, this list will-                        -- be expressed as a comprehension.  An-                        -- association '(i, x)' defines the value of-                        -- the array at index 'i' to be 'x'.-        -> Array i e-array (l,u) ies-    = let n = safeRangeSize (l,u)-      in unsafeArray' (l,u) n-                      [(safeIndex (l,u) n i, e) | (i, e) <- ies]--{-# INLINE unsafeArray #-}-unsafeArray :: Ix i => (i,i) -> [(Int, e)] -> Array i e-unsafeArray b ies = unsafeArray' b (rangeSize b) ies--{-# INLINE unsafeArray' #-}-unsafeArray' :: Ix i => (i,i) -> Int -> [(Int, e)] -> Array i e-unsafeArray' (l,u) n@(I# n#) ies = runST (ST $ \s1# ->-    case newArray# n# arrEleBottom s1# of-        (# s2#, marr# #) ->-            foldr (fill marr#) (done l u n marr#) ies s2#)--{-# INLINE fill #-}-fill :: MutableArray# s e -> (Int, e) -> STRep s a -> STRep s a--- NB: put the \s after the "=" so that 'fill'---     inlines when applied to three args-fill marr# (I# i#, e) next- = \s1# -> case writeArray# marr# i# e s1# of-             s2# -> next s2#--{-# INLINE done #-}-done :: Ix i => i -> i -> Int -> MutableArray# s e -> STRep s (Array i e)--- See NB on 'fill'-done l u n marr#-  = \s1# -> case unsafeFreezeArray# marr# s1# of-              (# s2#, arr# #) -> (# s2#, Array l u n arr# #)---- This is inefficient and I'm not sure why:--- listArray (l,u) es = unsafeArray (l,u) (zip [0 .. rangeSize (l,u) - 1] es)--- The code below is better. It still doesn't enable foldr/build--- transformation on the list of elements; I guess it's impossible--- using mechanisms currently available.---- | Construct an array from a pair of bounds and a list of values in--- index order.-{-# INLINE listArray #-}-listArray :: Ix i => (i,i) -> [e] -> Array i e-listArray (l,u) es = runST (ST $ \s1# ->-    case safeRangeSize (l,u)            of { n@(I# n#) ->-    case newArray# n# arrEleBottom s1#  of { (# s2#, marr# #) ->-    let fillFromList i# xs s3# | isTrue# (i# ==# n#) = s3#-                               | otherwise = case xs of-            []   -> s3#-            y:ys -> case writeArray# marr# i# y s3# of { s4# ->-                    fillFromList (i# +# 1#) ys s4# } in-    case fillFromList 0# es s2#         of { s3# ->-    done l u n marr# s3# }}})---- | The value at the given index in an array.-{-# INLINE (!) #-}-(!) :: Ix i => Array i e -> i -> e-arr@(Array l u n _) ! i = unsafeAt arr $ safeIndex (l,u) n i--{-# INLINE safeRangeSize #-}-safeRangeSize :: Ix i => (i, i) -> Int-safeRangeSize (l,u) = let r = rangeSize (l, u)-                      in if r < 0 then negRange-                                  else r---- Don't inline this error message everywhere!!-negRange :: Int	  -- Uninformative, but Ix does not provide Show-negRange = error "Negative range size"--{-# INLINE[1] safeIndex #-}--- See Note [Double bounds-checking of index values]--- Inline *after* (!) so the rules can fire-safeIndex :: Ix i => (i, i) -> Int -> i -> Int-safeIndex (l,u) n i = let i' = index (l,u) i-                      in if (0 <= i') && (i' < n)-                         then i'-                         else badSafeIndex i' n---- See Note [Double bounds-checking of index values]-{-# RULES-"safeIndex/I"       safeIndex = lessSafeIndex :: (Int,Int) -> Int -> Int -> Int-"safeIndex/(I,I)"   safeIndex = lessSafeIndex :: ((Int,Int),(Int,Int)) -> Int -> (Int,Int) -> Int-"safeIndex/(I,I,I)" safeIndex = lessSafeIndex :: ((Int,Int,Int),(Int,Int,Int)) -> Int -> (Int,Int,Int) -> Int-  #-}--lessSafeIndex :: Ix i => (i, i) -> Int -> i -> Int--- See Note [Double bounds-checking of index values]--- Do only (A), the semantic check-lessSafeIndex (l,u) _ i = index (l,u) i---- Don't inline this long error message everywhere!!-badSafeIndex :: Int -> Int -> Int-badSafeIndex i' n = error ("Error in array index; " ++ show i' ++-                        " not in range [0.." ++ show n ++ ")")--{-# INLINE unsafeAt #-}-unsafeAt :: Ix i => Array i e -> Int -> e-unsafeAt (Array _ _ _ arr#) (I# i#) =-    case indexArray# arr# i# of (# e #) -> e---- | The bounds with which an array was constructed.-{-# INLINE bounds #-}-bounds :: Ix i => Array i e -> (i,i)-bounds (Array l u _ _) = (l,u)---- | The number of elements in the array.-{-# INLINE numElements #-}-numElements :: Ix i => Array i e -> Int-numElements (Array _ _ n _) = n---- | The list of indices of an array in ascending order.-{-# INLINE indices #-}-indices :: Ix i => Array i e -> [i]-indices (Array l u _ _) = range (l,u)---- | The list of elements of an array in index order.-{-# INLINE elems #-}-elems :: Ix i => Array i e -> [e]-elems arr@(Array _ _ n _) =-    [unsafeAt arr i | i <- [0 .. n - 1]]---- | The list of associations of an array in index order.-{-# INLINE assocs #-}-assocs :: Ix i => Array i e -> [(i, e)]-assocs arr@(Array l u _ _) =-    [(i, arr ! i) | i <- range (l,u)]---- | The 'accumArray' function deals with repeated indices in the association--- list using an /accumulating function/ which combines the values of--- associations with the same index.--- For example, given a list of values of some index type, @hist@--- produces a histogram of the number of occurrences of each index within--- a specified range:------ > hist :: (Ix a, Num b) => (a,a) -> [a] -> Array a b--- > hist bnds is = accumArray (+) 0 bnds [(i, 1) | i<-is, inRange bnds i]------ If the accumulating function is strict, then 'accumArray' is strict in--- the values, as well as the indices, in the association list.  Thus,--- unlike ordinary arrays built with 'array', accumulated arrays should--- not in general be recursive.-{-# INLINE accumArray #-}-accumArray :: Ix i-        => (e -> a -> e)        -- ^ accumulating function-        -> e                    -- ^ initial value-        -> (i,i)                -- ^ bounds of the array-        -> [(i, a)]             -- ^ association list-        -> Array i e-accumArray f initial (l,u) ies =-    let n = safeRangeSize (l,u)-    in unsafeAccumArray' f initial (l,u) n-                         [(safeIndex (l,u) n i, e) | (i, e) <- ies]--{-# INLINE unsafeAccumArray #-}-unsafeAccumArray :: Ix i => (e -> a -> e) -> e -> (i,i) -> [(Int, a)] -> Array i e-unsafeAccumArray f initial b ies = unsafeAccumArray' f initial b (rangeSize b) ies--{-# INLINE unsafeAccumArray' #-}-unsafeAccumArray' :: Ix i => (e -> a -> e) -> e -> (i,i) -> Int -> [(Int, a)] -> Array i e-unsafeAccumArray' f initial (l,u) n@(I# n#) ies = runST (ST $ \s1# ->-    case newArray# n# initial s1#          of { (# s2#, marr# #) ->-    foldr (adjust f marr#) (done l u n marr#) ies s2# })--{-# INLINE adjust #-}-adjust :: (e -> a -> e) -> MutableArray# s e -> (Int, a) -> STRep s b -> STRep s b--- See NB on 'fill'-adjust f marr# (I# i#, new) next-  = \s1# -> case readArray# marr# i# s1# of-        	(# s2#, old #) ->-        	    case writeArray# marr# i# (f old new) s2# of-        	        s3# -> next s3#---- | Constructs an array identical to the first argument except that it has--- been updated by the associations in the right argument.--- For example, if @m@ is a 1-origin, @n@ by @n@ matrix, then------ > m//[((i,i), 0) | i <- [1..n]]------ is the same matrix, except with the diagonal zeroed.------ Repeated indices in the association list are handled as for 'array':--- Haskell 2010 specifies that the resulting array is undefined (i.e. bottom),--- but GHC's implementation uses the last association for each index.-{-# INLINE (//) #-}-(//) :: Ix i => Array i e -> [(i, e)] -> Array i e-arr@(Array l u n _) // ies =-    unsafeReplace arr [(safeIndex (l,u) n i, e) | (i, e) <- ies]--{-# INLINE unsafeReplace #-}-unsafeReplace :: Ix i => Array i e -> [(Int, e)] -> Array i e-unsafeReplace arr ies = runST (do-    STArray l u n marr# <- thawSTArray arr-    ST (foldr (fill marr#) (done l u n marr#) ies))---- | @'accum' f@ takes an array and an association list and accumulates--- pairs from the list into the array with the accumulating function @f@.--- Thus 'accumArray' can be defined using 'accum':------ > accumArray f z b = accum f (array b [(i, z) | i <- range b])----{-# INLINE accum #-}-accum :: Ix i => (e -> a -> e) -> Array i e -> [(i, a)] -> Array i e-accum f arr@(Array l u n _) ies =-    unsafeAccum f arr [(safeIndex (l,u) n i, e) | (i, e) <- ies]--{-# INLINE unsafeAccum #-}-unsafeAccum :: Ix i => (e -> a -> e) -> Array i e -> [(Int, a)] -> Array i e-unsafeAccum f arr ies = runST (do-    STArray l u n marr# <- thawSTArray arr-    ST (foldr (adjust f marr#) (done l u n marr#) ies))--{-# INLINE amap #-}-amap :: Ix i => (a -> b) -> Array i a -> Array i b-amap f arr@(Array l u n _) =-    unsafeArray' (l,u) n [(i, f (unsafeAt arr i)) | i <- [0 .. n - 1]]---- | 'ixmap' allows for transformations on array indices.--- It may be thought of as providing function composition on the right--- with the mapping that the original array embodies.------ A similar transformation of array values may be achieved using 'fmap'--- from the 'Array' instance of the 'Functor' class.-{-# INLINE ixmap #-}-ixmap :: (Ix i, Ix j) => (i,i) -> (i -> j) -> Array j e -> Array i e-ixmap (l,u) f arr =-    array (l,u) [(i, arr ! f i) | i <- range (l,u)]--{-# INLINE eqArray #-}-eqArray :: (Ix i, Eq e) => Array i e -> Array i e -> Bool-eqArray arr1@(Array l1 u1 n1 _) arr2@(Array l2 u2 n2 _) =-    if n1 == 0 then n2 == 0 else-    l1 == l2 && u1 == u2 &&-    and [unsafeAt arr1 i == unsafeAt arr2 i | i <- [0 .. n1 - 1]]--{-# INLINE [1] cmpArray #-}-cmpArray :: (Ix i, Ord e) => Array i e -> Array i e -> Ordering-cmpArray arr1 arr2 = compare (assocs arr1) (assocs arr2)--{-# INLINE cmpIntArray #-}-cmpIntArray :: Ord e => Array Int e -> Array Int e -> Ordering-cmpIntArray arr1@(Array l1 u1 n1 _) arr2@(Array l2 u2 n2 _) =-    if n1 == 0 then-        if n2 == 0 then EQ else LT-    else if n2 == 0 then GT-    else case compare l1 l2 of-             EQ    -> foldr cmp (compare u1 u2) [0 .. (n1 `min` n2) - 1]-             other -> other-  where-    cmp i rest = case compare (unsafeAt arr1 i) (unsafeAt arr2 i) of-        EQ    -> rest-        other -> other--{-# RULES "cmpArray/Int" cmpArray = cmpIntArray #-}-\end{code}---%*********************************************************-%*                                                      *-\subsection{Array instances}-%*                                                      *-%*********************************************************--\begin{code}-instance Ix i => Functor (Array i) where-    fmap = amap--instance (Ix i, Eq e) => Eq (Array i e) where-    (==) = eqArray--instance (Ix i, Ord e) => Ord (Array i e) where-    compare = cmpArray--instance (Ix a, Show a, Show b) => Show (Array a b) where-    showsPrec p a =-        showParen (p > appPrec) $-        showString "array " .-        showsPrec appPrec1 (bounds a) .-        showChar ' ' .-        showsPrec appPrec1 (assocs a)-        -- Precedence of 'array' is the precedence of application---- The Read instance is in GHC.Read-\end{code}---%*********************************************************-%*                                                      *-\subsection{Operations on mutable arrays}-%*                                                      *-%*********************************************************--Idle ADR question: What's the tradeoff here between flattening these-datatypes into @STArray ix ix (MutableArray# s elt)@ and using-it as is?  As I see it, the former uses slightly less heap and-provides faster access to the individual parts of the bounds while the-code used has the benefit of providing a ready-made @(lo, hi)@ pair as-required by many array-related functions.  Which wins? Is the-difference significant (probably not).--Idle AJG answer: When I looked at the outputted code (though it was 2-years ago) it seems like you often needed the tuple, and we build-it frequently. Now we've got the overloading specialiser things-might be different, though.--\begin{code}-{-# INLINE newSTArray #-}-newSTArray :: Ix i => (i,i) -> e -> ST s (STArray s i e)-newSTArray (l,u) initial = ST $ \s1# ->-    case safeRangeSize (l,u)            of { n@(I# n#) ->-    case newArray# n# initial s1#       of { (# s2#, marr# #) ->-    (# s2#, STArray l u n marr# #) }}--{-# INLINE boundsSTArray #-}-boundsSTArray :: STArray s i e -> (i,i)-boundsSTArray (STArray l u _ _) = (l,u)--{-# INLINE numElementsSTArray #-}-numElementsSTArray :: STArray s i e -> Int-numElementsSTArray (STArray _ _ n _) = n--{-# INLINE readSTArray #-}-readSTArray :: Ix i => STArray s i e -> i -> ST s e-readSTArray marr@(STArray l u n _) i =-    unsafeReadSTArray marr (safeIndex (l,u) n i)--{-# INLINE unsafeReadSTArray #-}-unsafeReadSTArray :: Ix i => STArray s i e -> Int -> ST s e-unsafeReadSTArray (STArray _ _ _ marr#) (I# i#)-    = ST $ \s1# -> readArray# marr# i# s1#--{-# INLINE writeSTArray #-}-writeSTArray :: Ix i => STArray s i e -> i -> e -> ST s ()-writeSTArray marr@(STArray l u n _) i e =-    unsafeWriteSTArray marr (safeIndex (l,u) n i) e--{-# INLINE unsafeWriteSTArray #-}-unsafeWriteSTArray :: Ix i => STArray s i e -> Int -> e -> ST s ()-unsafeWriteSTArray (STArray _ _ _ marr#) (I# i#) e = ST $ \s1# ->-    case writeArray# marr# i# e s1# of-        s2# -> (# s2#, () #)-\end{code}---%*********************************************************-%*                                                      *-\subsection{Moving between mutable and immutable}-%*                                                      *-%*********************************************************--\begin{code}-freezeSTArray :: Ix i => STArray s i e -> ST s (Array i e)-freezeSTArray (STArray l u n@(I# n#) marr#) = ST $ \s1# ->-    case newArray# n# arrEleBottom s1#  of { (# s2#, marr'# #) ->-    let copy i# s3# | isTrue# (i# ==# n#) = s3#-                    | otherwise =-            case readArray# marr# i# s3# of { (# s4#, e #) ->-            case writeArray# marr'# i# e s4# of { s5# ->-            copy (i# +# 1#) s5# }} in-    case copy 0# s2#                    of { s3# ->-    case unsafeFreezeArray# marr'# s3#  of { (# s4#, arr# #) ->-    (# s4#, Array l u n arr# #) }}}--{-# INLINE unsafeFreezeSTArray #-}-unsafeFreezeSTArray :: Ix i => STArray s i e -> ST s (Array i e)-unsafeFreezeSTArray (STArray l u n marr#) = ST $ \s1# ->-    case unsafeFreezeArray# marr# s1#   of { (# s2#, arr# #) ->-    (# s2#, Array l u n arr# #) }--thawSTArray :: Ix i => Array i e -> ST s (STArray s i e)-thawSTArray (Array l u n@(I# n#) arr#) = ST $ \s1# ->-    case newArray# n# arrEleBottom s1#  of { (# s2#, marr# #) ->-    let copy i# s3# | isTrue# (i# ==# n#) = s3#-                    | otherwise =-            case indexArray# arr# i#    of { (# e #) ->-            case writeArray# marr# i# e s3# of { s4# ->-            copy (i# +# 1#) s4# }} in-    case copy 0# s2#                    of { s3# ->-    (# s3#, STArray l u n marr# #) }}--{-# INLINE unsafeThawSTArray #-}-unsafeThawSTArray :: Ix i => Array i e -> ST s (STArray s i e)-unsafeThawSTArray (Array l u n arr#) = ST $ \s1# ->-    case unsafeThawArray# arr# s1#      of { (# s2#, marr# #) ->-    (# s2#, STArray l u n marr# #) }-\end{code}
+ GHC/Base.hs view
@@ -0,0 +1,1199 @@+{-+The overall structure of the GHC Prelude is a bit tricky.++  a) We want to avoid "orphan modules", i.e. ones with instance+        decls that don't belong either to a tycon or a class+        defined in the same module++  b) We want to avoid giant modules++So the rough structure is as follows, in (linearised) dependency order+++GHC.Prim        Has no implementation.  It defines built-in things, and+                by importing it you bring them into scope.+                The source file is GHC.Prim.hi-boot, which is just+                copied to make GHC.Prim.hi++GHC.Base        Classes: Eq, Ord, Functor, Monad+                Types:   list, (), Int, Bool, Ordering, Char, String++Data.Tuple      Types: tuples, plus instances for GHC.Base classes++GHC.Show        Class: Show, plus instances for GHC.Base/GHC.Tup types++GHC.Enum        Class: Enum,  plus instances for GHC.Base/GHC.Tup types++Data.Maybe      Type: Maybe, plus instances for GHC.Base classes++GHC.List        List functions++GHC.Num         Class: Num, plus instances for Int+                Type:  Integer, plus instances for all classes so far (Eq, Ord, Num, Show)++                Integer is needed here because it is mentioned in the signature+                of 'fromInteger' in class Num++GHC.Real        Classes: Real, Integral, Fractional, RealFrac+                         plus instances for Int, Integer+                Types:  Ratio, Rational+                        plus intances for classes so far++                Rational is needed here because it is mentioned in the signature+                of 'toRational' in class Real++GHC.ST  The ST monad, instances and a few helper functions++Ix              Classes: Ix, plus instances for Int, Bool, Char, Integer, Ordering, tuples++GHC.Arr         Types: Array, MutableArray, MutableVar++                Arrays are used by a function in GHC.Float++GHC.Float       Classes: Floating, RealFloat+                Types:   Float, Double, plus instances of all classes so far++                This module contains everything to do with floating point.+                It is a big module (900 lines)+                With a bit of luck, many modules can be compiled without ever reading GHC.Float.hi+++Other Prelude modules are much easier with fewer complex dependencies.+-}++{-# LANGUAGE Unsafe #-}+{-# LANGUAGE CPP+           , NoImplicitPrelude+           , BangPatterns+           , ExplicitForAll+           , MagicHash+           , UnboxedTuples+           , ExistentialQuantification+           , RankNTypes+  #-}+-- -fno-warn-orphans is needed for things like:+-- Orphan rule: "x# -# x#" ALWAYS forall x# :: Int# -# x# x# = 0+{-# OPTIONS_GHC -fno-warn-orphans #-}+{-# OPTIONS_HADDOCK hide #-}++-----------------------------------------------------------------------------+-- |+-- Module      :  GHC.Base+-- Copyright   :  (c) The University of Glasgow, 1992-2002+-- License     :  see libraries/base/LICENSE+--+-- Maintainer  :  cvs-ghc@haskell.org+-- Stability   :  internal+-- Portability :  non-portable (GHC extensions)+--+-- Basic data types and classes.+--+-----------------------------------------------------------------------------++#include "MachDeps.h"++module GHC.Base+        (+        module GHC.Base,+        module GHC.Classes,+        module GHC.CString,+        module GHC.Magic,+        module GHC.Types,+        module GHC.Prim,        -- Re-export GHC.Prim and [boot] GHC.Err,+                                -- to avoid lots of people having to+        module GHC.Err          -- import it explicitly+  )+        where++import GHC.Types+import GHC.Classes+import GHC.CString+import GHC.Magic+import GHC.Prim+import GHC.Err+import {-# SOURCE #-} GHC.IO (failIO)++import GHC.Tuple ()     -- Note [Depend on GHC.Tuple]+import GHC.Integer ()   -- Note [Depend on GHC.Integer]++infixr 9  .+infixr 5  +++infixl 4  <$+infixl 1  >>, >>=+infixr 1  =<<+infixr 0  $, $!++infixl 4 <*>, <*, *>, <**>++default ()              -- Double isn't available yet++{-+Note [Depend on GHC.Integer]+~~~~~~~~~~~~~~~~~~~~~~~~~~~~+The Integer type is special because TidyPgm uses+GHC.Integer.Type.mkInteger to construct Integer literal values+Currently it reads the interface file whether or not the current+module *has* any Integer literals, so it's important that+GHC.Integer.Type (in patckage integer-gmp or integer-simple) is+compiled before any other module.  (There's a hack in GHC to disable+this for packages ghc-prim, integer-gmp, integer-simple, which aren't+allowed to contain any Integer literals.)++Likewise we implicitly need Integer when deriving things like Eq+instances.++The danger is that if the build system doesn't know about the dependency+on Integer, it'll compile some base module before GHC.Integer.Type,+resulting in:+  Failed to load interface for ‘GHC.Integer.Type’+    There are files missing in the ‘integer-gmp’ package,++Bottom line: we make GHC.Base depend on GHC.Integer; and everything+else either depends on GHC.Base, or does not have NoImplicitPrelude+(and hence depends on Prelude).++Note [Depend on GHC.Tuple]+~~~~~~~~~~~~~~~~~~~~~~~~~~+Similarly, tuple syntax (or ()) creates an implicit dependency on+GHC.Tuple, so we use the same rule as for Integer --- see Note [Depend on+GHC.Integer] --- to explain this to the build system.  We make GHC.Base+depend on GHC.Tuple, and everything else depends on GHC.Base or Prelude.+-}++#if 0+-- for use when compiling GHC.Base itself doesn't work+data  Bool  =  False | True+data Ordering = LT | EQ | GT+data Char = C# Char#+type  String = [Char]+data Int = I# Int#+data  ()  =  ()+data [] a = MkNil++not True = False+(&&) True True = True+otherwise = True++build = error "urk"+foldr = error "urk"+#endif++-- | The 'Maybe' type encapsulates an optional value.  A value of type+-- @'Maybe' a@ either contains a value of type @a@ (represented as @'Just' a@),+-- or it is empty (represented as 'Nothing').  Using 'Maybe' is a good way to+-- deal with errors or exceptional cases without resorting to drastic+-- measures such as 'error'.+--+-- The 'Maybe' type is also a monad.  It is a simple kind of error+-- monad, where all errors are represented by 'Nothing'.  A richer+-- error monad can be built using the 'Data.Either.Either' type.+--+data  Maybe a  =  Nothing | Just a+  deriving (Eq, Ord)++-- | The class of monoids (types with an associative binary operation that+-- has an identity).  Instances should satisfy the following laws:+--+--  * @mappend mempty x = x@+--+--  * @mappend x mempty = x@+--+--  * @mappend x (mappend y z) = mappend (mappend x y) z@+--+--  * @mconcat = 'foldr' mappend mempty@+--+-- The method names refer to the monoid of lists under concatenation,+-- but there are many other instances.+--+-- Some types can be viewed as a monoid in more than one way,+-- e.g. both addition and multiplication on numbers.+-- In such cases we often define @newtype@s and make those instances+-- of 'Monoid', e.g. 'Sum' and 'Product'.++class Monoid a where+        mempty  :: a+        -- ^ Identity of 'mappend'+        mappend :: a -> a -> a+        -- ^ An associative operation+        mconcat :: [a] -> a++        -- ^ Fold a list using the monoid.+        -- For most types, the default definition for 'mconcat' will be+        -- used, but the function is included in the class definition so+        -- that an optimized version can be provided for specific types.++        mconcat = foldr mappend mempty++instance Monoid [a] where+        {-# INLINE mempty #-}+        mempty  = []+        {-# INLINE mappend #-}+        mappend = (++)+        {-# INLINE mconcat #-}+        mconcat xss = [x | xs <- xss, x <- xs]+-- See Note: [List comprehensions and inlining]++{-+Note: [List comprehensions and inlining]+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+The list monad operations are traditionally described in terms of concatMap:++xs >>= f = concatMap f xs++Similarly, mconcat for lists is just concat. Here in Base, however, we don't+have concatMap, and we'll refrain from adding it here so it won't have to be+hidden in imports. Instead, we use GHC's list comprehension desugaring+mechanism to define mconcat and the Applicative and Monad instances for lists.+We mark them INLINE because the inliner is not generally too keen to inline+build forms such as the ones these desugar to without our insistence.  Defining+these using list comprehensions instead of foldr has an additional potential+benefit, as described in compiler/deSugar/DsListComp.lhs: if optimizations+needed to make foldr/build forms efficient are turned off, we'll get reasonably+efficient translations anyway.+-}++instance Monoid b => Monoid (a -> b) where+        mempty _ = mempty+        mappend f g x = f x `mappend` g x++instance Monoid () where+        -- Should it be strict?+        mempty        = ()+        _ `mappend` _ = ()+        mconcat _     = ()++instance (Monoid a, Monoid b) => Monoid (a,b) where+        mempty = (mempty, mempty)+        (a1,b1) `mappend` (a2,b2) =+                (a1 `mappend` a2, b1 `mappend` b2)++instance (Monoid a, Monoid b, Monoid c) => Monoid (a,b,c) where+        mempty = (mempty, mempty, mempty)+        (a1,b1,c1) `mappend` (a2,b2,c2) =+                (a1 `mappend` a2, b1 `mappend` b2, c1 `mappend` c2)++instance (Monoid a, Monoid b, Monoid c, Monoid d) => Monoid (a,b,c,d) where+        mempty = (mempty, mempty, mempty, mempty)+        (a1,b1,c1,d1) `mappend` (a2,b2,c2,d2) =+                (a1 `mappend` a2, b1 `mappend` b2,+                 c1 `mappend` c2, d1 `mappend` d2)++instance (Monoid a, Monoid b, Monoid c, Monoid d, Monoid e) =>+                Monoid (a,b,c,d,e) where+        mempty = (mempty, mempty, mempty, mempty, mempty)+        (a1,b1,c1,d1,e1) `mappend` (a2,b2,c2,d2,e2) =+                (a1 `mappend` a2, b1 `mappend` b2, c1 `mappend` c2,+                 d1 `mappend` d2, e1 `mappend` e2)++-- lexicographical ordering+instance Monoid Ordering where+        mempty         = EQ+        LT `mappend` _ = LT+        EQ `mappend` y = y+        GT `mappend` _ = GT++-- | Lift a semigroup into 'Maybe' forming a 'Monoid' according to+-- <http://en.wikipedia.org/wiki/Monoid>: \"Any semigroup @S@ may be+-- turned into a monoid simply by adjoining an element @e@ not in @S@+-- and defining @e*e = e@ and @e*s = s = s*e@ for all @s ∈ S@.\" Since+-- there is no \"Semigroup\" typeclass providing just 'mappend', we+-- use 'Monoid' instead.+instance Monoid a => Monoid (Maybe a) where+  mempty = Nothing+  Nothing `mappend` m = m+  m `mappend` Nothing = m+  Just m1 `mappend` Just m2 = Just (m1 `mappend` m2)++instance Monoid a => Applicative ((,) a) where+    pure x = (mempty, x)+    (u, f) <*> (v, x) = (u `mappend` v, f x)+++{- | The 'Functor' class is used for types that can be mapped over.+Instances of 'Functor' should satisfy the following laws:++> fmap id  ==  id+> fmap (f . g)  ==  fmap f . fmap g++The instances of 'Functor' for lists, 'Data.Maybe.Maybe' and 'System.IO.IO'+satisfy these laws.+-}++class  Functor f  where+    fmap        :: (a -> b) -> f a -> f b++    -- | Replace all locations in the input with the same value.+    -- The default definition is @'fmap' . 'const'@, but this may be+    -- overridden with a more efficient version.+    (<$)        :: a -> f b -> f a+    (<$)        =  fmap . const++-- | A functor with application, providing operations to+--+-- * embed pure expressions ('pure'), and+--+-- * sequence computations and combine their results ('<*>').+--+-- A minimal complete definition must include implementations of these+-- functions satisfying the following laws:+--+-- [/identity/]+--+--      @'pure' 'id' '<*>' v = v@+--+-- [/composition/]+--+--      @'pure' (.) '<*>' u '<*>' v '<*>' w = u '<*>' (v '<*>' w)@+--+-- [/homomorphism/]+--+--      @'pure' f '<*>' 'pure' x = 'pure' (f x)@+--+-- [/interchange/]+--+--      @u '<*>' 'pure' y = 'pure' ('$' y) '<*>' u@+--+-- The other methods have the following default definitions, which may+-- be overridden with equivalent specialized implementations:+--+--   * @u '*>' v = 'pure' ('const' 'id') '<*>' u '<*>' v@+--+--   * @u '<*' v = 'pure' 'const' '<*>' u '<*>' v@+--+-- As a consequence of these laws, the 'Functor' instance for @f@ will satisfy+--+--   * @'fmap' f x = 'pure' f '<*>' x@+--+-- If @f@ is also a 'Monad', it should satisfy+--+--   * @'pure' = 'return'@+--+--   * @('<*>') = 'ap'@+--+-- (which implies that 'pure' and '<*>' satisfy the applicative functor laws).++class Functor f => Applicative f where+    -- | Lift a value.+    pure :: a -> f a++    -- | Sequential application.+    (<*>) :: f (a -> b) -> f a -> f b++    -- | Sequence actions, discarding the value of the first argument.+    (*>) :: f a -> f b -> f b+    a1 *> a2 = (id <$ a1) <*> a2+    -- This is essentially the same as liftA2 (const id), but if the+    -- Functor instance has an optimized (<$), we want to use that instead.++    -- | Sequence actions, discarding the value of the second argument.+    (<*) :: f a -> f b -> f a+    (<*) = liftA2 const++-- | A variant of '<*>' with the arguments reversed.+(<**>) :: Applicative f => f a -> f (a -> b) -> f b+(<**>) = liftA2 (flip ($))++-- | Lift a function to actions.+-- This function may be used as a value for `fmap` in a `Functor` instance.+liftA :: Applicative f => (a -> b) -> f a -> f b+liftA f a = pure f <*> a+-- Caution: since this may be used for `fmap`, we can't use the obvious+-- definition of liftA = fmap.++-- | Lift a binary function to actions.+liftA2 :: Applicative f => (a -> b -> c) -> f a -> f b -> f c+liftA2 f a b = fmap f a <*> b++-- | Lift a ternary function to actions.+liftA3 :: Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d+liftA3 f a b c = fmap f a <*> b <*> c+++{-# INLINEABLE liftA #-}+{-# SPECIALISE liftA :: (a1->r) -> IO a1 -> IO r #-}+{-# SPECIALISE liftA :: (a1->r) -> Maybe a1 -> Maybe r #-}+{-# INLINEABLE liftA2 #-}+{-# SPECIALISE liftA2 :: (a1->a2->r) -> IO a1 -> IO a2 -> IO r #-}+{-# SPECIALISE liftA2 :: (a1->a2->r) -> Maybe a1 -> Maybe a2 -> Maybe r #-}+{-# INLINEABLE liftA3 #-}+{-# SPECIALISE liftA3 :: (a1->a2->a3->r) -> IO a1 -> IO a2 -> IO a3 -> IO r #-}+{-# SPECIALISE liftA3 :: (a1->a2->a3->r) ->+                                Maybe a1 -> Maybe a2 -> Maybe a3 -> Maybe r #-}++-- | The 'join' function is the conventional monad join operator. It+-- is used to remove one level of monadic structure, projecting its+-- bound argument into the outer level.+join              :: (Monad m) => m (m a) -> m a+join x            =  x >>= id++{- | The 'Monad' class defines the basic operations over a /monad/,+a concept from a branch of mathematics known as /category theory/.+From the perspective of a Haskell programmer, however, it is best to+think of a monad as an /abstract datatype/ of actions.+Haskell's @do@ expressions provide a convenient syntax for writing+monadic expressions.++Instances of 'Monad' should satisfy the following laws:++* @'return' a '>>=' k  =  k a@+* @m '>>=' 'return'  =  m@+* @m '>>=' (\x -> k x '>>=' h)  =  (m '>>=' k) '>>=' h@++Furthermore, the 'Monad' and 'Applicative' operations should relate as follows:++* @'pure' = 'return'@+* @('<*>') = 'ap'@++The above laws imply:++* @'fmap' f xs  =  xs '>>=' 'return' . f@+* @('>>') = ('*>')@++and that 'pure' and ('<*>') satisfy the applicative functor laws.++The instances of 'Monad' for lists, 'Data.Maybe.Maybe' and 'System.IO.IO'+defined in the "Prelude" satisfy these laws.+-}+class Applicative m => Monad m where+    -- | Sequentially compose two actions, passing any value produced+    -- by the first as an argument to the second.+    (>>=)       :: forall a b. m a -> (a -> m b) -> m b++    -- | Sequentially compose two actions, discarding any value produced+    -- by the first, like sequencing operators (such as the semicolon)+    -- in imperative languages.+    (>>)        :: forall a b. m a -> m b -> m b+    m >> k = m >>= \_ -> k -- See Note [Recursive bindings for Applicative/Monad]+    {-# INLINE (>>) #-}++    -- | Inject a value into the monadic type.+    return      :: a -> m a+    return      = pure++    -- | Fail with a message.  This operation is not part of the+    -- mathematical definition of a monad, but is invoked on pattern-match+    -- failure in a @do@ expression.+    fail        :: String -> m a+    fail s      = error s++{- Note [Recursive bindings for Applicative/Monad]+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~++The original Applicative/Monad proposal stated that after+implementation, the designated implementation of (>>) would become++  (>>) :: forall a b. m a -> m b -> m b+  (>>) = (*>)++by default. You might be inclined to change this to reflect the stated+proposal, but you really shouldn't! Why? Because people tend to define+such instances the /other/ way around: in particular, it is perfectly+legitimate to define an instance of Applicative (*>) in terms of (>>),+which would lead to an infinite loop for the default implementation of+Monad! And people do this in the wild.++This turned into a nasty bug that was tricky to track down, and rather+than eliminate it everywhere upstream, it's easier to just retain the+original default.++-}++-- | Same as '>>=', but with the arguments interchanged.+{-# SPECIALISE (=<<) :: (a -> [b]) -> [a] -> [b] #-}+(=<<)           :: Monad m => (a -> m b) -> m a -> m b+f =<< x         = x >>= f++-- | Conditional execution of 'Applicative' expressions. For example,+--+-- > when debug (putStrLn "Debugging")+--+-- will output the string @Debugging@ if the Boolean value @debug@+-- is 'True', and otherwise do nothing.+when      :: (Applicative f) => Bool -> f () -> f ()+{-# INLINEABLE when #-}+{-# SPECIALISE when :: Bool -> IO () -> IO () #-}+{-# SPECIALISE when :: Bool -> Maybe () -> Maybe () #-}+when p s  = if p then s else pure ()++-- | Evaluate each action in the sequence from left to right,+-- and collect the results.+sequence :: Monad m => [m a] -> m [a]+{-# INLINE sequence #-}+sequence = mapM id+-- Note: [sequence and mapM]++-- | @'mapM' f@ is equivalent to @'sequence' . 'map' f@.+mapM :: Monad m => (a -> m b) -> [a] -> m [b]+{-# INLINE mapM #-}+mapM f as = foldr k (return []) as+            where+              k a r = do { x <- f a; xs <- r; return (x:xs) }++{-+Note: [sequence and mapM]+~~~~~~~~~~~~~~~~~~~~~~~~~+Originally, we defined++mapM f = sequence . map f++This relied on list fusion to produce efficient code for mapM, and led to+excessive allocation in cryptarithm2. Defining++sequence = mapM id++relies only on inlining a tiny function (id) and beta reduction, which tends to+be a more reliable aspect of simplification. Indeed, this does not lead to+similar problems in nofib.+-}++-- | Promote a function to a monad.+liftM   :: (Monad m) => (a1 -> r) -> m a1 -> m r+liftM f m1              = do { x1 <- m1; return (f x1) }++-- | Promote a function to a monad, scanning the monadic arguments from+-- left to right.  For example,+--+-- >    liftM2 (+) [0,1] [0,2] = [0,2,1,3]+-- >    liftM2 (+) (Just 1) Nothing = Nothing+--+liftM2  :: (Monad m) => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r+liftM2 f m1 m2          = do { x1 <- m1; x2 <- m2; return (f x1 x2) }++-- | Promote a function to a monad, scanning the monadic arguments from+-- left to right (cf. 'liftM2').+liftM3  :: (Monad m) => (a1 -> a2 -> a3 -> r) -> m a1 -> m a2 -> m a3 -> m r+liftM3 f m1 m2 m3       = do { x1 <- m1; x2 <- m2; x3 <- m3; return (f x1 x2 x3) }++-- | Promote a function to a monad, scanning the monadic arguments from+-- left to right (cf. 'liftM2').+liftM4  :: (Monad m) => (a1 -> a2 -> a3 -> a4 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m r+liftM4 f m1 m2 m3 m4    = do { x1 <- m1; x2 <- m2; x3 <- m3; x4 <- m4; return (f x1 x2 x3 x4) }++-- | Promote a function to a monad, scanning the monadic arguments from+-- left to right (cf. 'liftM2').+liftM5  :: (Monad m) => (a1 -> a2 -> a3 -> a4 -> a5 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m a5 -> m r+liftM5 f m1 m2 m3 m4 m5 = do { x1 <- m1; x2 <- m2; x3 <- m3; x4 <- m4; x5 <- m5; return (f x1 x2 x3 x4 x5) }++{-# INLINEABLE liftM #-}+{-# SPECIALISE liftM :: (a1->r) -> IO a1 -> IO r #-}+{-# SPECIALISE liftM :: (a1->r) -> Maybe a1 -> Maybe r #-}+{-# INLINEABLE liftM2 #-}+{-# SPECIALISE liftM2 :: (a1->a2->r) -> IO a1 -> IO a2 -> IO r #-}+{-# SPECIALISE liftM2 :: (a1->a2->r) -> Maybe a1 -> Maybe a2 -> Maybe r #-}+{-# INLINEABLE liftM3 #-}+{-# SPECIALISE liftM3 :: (a1->a2->a3->r) -> IO a1 -> IO a2 -> IO a3 -> IO r #-}+{-# SPECIALISE liftM3 :: (a1->a2->a3->r) -> Maybe a1 -> Maybe a2 -> Maybe a3 -> Maybe r #-}+{-# INLINEABLE liftM4 #-}+{-# SPECIALISE liftM4 :: (a1->a2->a3->a4->r) -> IO a1 -> IO a2 -> IO a3 -> IO a4 -> IO r #-}+{-# SPECIALISE liftM4 :: (a1->a2->a3->a4->r) -> Maybe a1 -> Maybe a2 -> Maybe a3 -> Maybe a4 -> Maybe r #-}+{-# INLINEABLE liftM5 #-}+{-# SPECIALISE liftM5 :: (a1->a2->a3->a4->a5->r) -> IO a1 -> IO a2 -> IO a3 -> IO a4 -> IO a5 -> IO r #-}+{-# SPECIALISE liftM5 :: (a1->a2->a3->a4->a5->r) -> Maybe a1 -> Maybe a2 -> Maybe a3 -> Maybe a4 -> Maybe a5 -> Maybe r #-}++{- | In many situations, the 'liftM' operations can be replaced by uses of+'ap', which promotes function application.++>       return f `ap` x1 `ap` ... `ap` xn++is equivalent to++>       liftMn f x1 x2 ... xn++-}++ap                :: (Monad m) => m (a -> b) -> m a -> m b+ap m1 m2          = do { x1 <- m1; x2 <- m2; return (x1 x2) }+-- Since many Applicative instances define (<*>) = ap, we+-- cannot define ap = (<*>)+{-# INLINEABLE ap #-}+{-# SPECIALISE ap :: IO (a -> b) -> IO a -> IO b #-}+{-# SPECIALISE ap :: Maybe (a -> b) -> Maybe a -> Maybe b #-}++-- instances for Prelude types++instance Functor ((->) r) where+    fmap = (.)++instance Applicative ((->) a) where+    pure = const+    (<*>) f g x = f x (g x)++instance Monad ((->) r) where+    return = const+    f >>= k = \ r -> k (f r) r++instance Functor ((,) a) where+    fmap f (x,y) = (x, f y)+++instance  Functor Maybe  where+    fmap _ Nothing       = Nothing+    fmap f (Just a)      = Just (f a)++instance Applicative Maybe where+    pure = Just++    Just f  <*> m       = fmap f m+    Nothing <*> _m      = Nothing++    Just _m1 *> m2      = m2+    Nothing  *> _m2     = Nothing++instance  Monad Maybe  where+    (Just x) >>= k      = k x+    Nothing  >>= _      = Nothing++    (>>) = (*>)++    return              = Just+    fail _              = Nothing++-- -----------------------------------------------------------------------------+-- The Alternative class definition++infixl 3 <|>++-- | A monoid on applicative functors.+--+-- If defined, 'some' and 'many' should be the least solutions+-- of the equations:+--+-- * @some v = (:) '<$>' v '<*>' many v@+--+-- * @many v = some v '<|>' 'pure' []@+class Applicative f => Alternative f where+    -- | The identity of '<|>'+    empty :: f a+    -- | An associative binary operation+    (<|>) :: f a -> f a -> f a++    -- | One or more.+    some :: f a -> f [a]+    some v = some_v+      where+        many_v = some_v <|> pure []+        some_v = (fmap (:) v) <*> many_v++    -- | Zero or more.+    many :: f a -> f [a]+    many v = many_v+      where+        many_v = some_v <|> pure []+        some_v = (fmap (:) v) <*> many_v+++instance Alternative Maybe where+    empty = Nothing+    Nothing <|> r = r+    l       <|> _ = l++-- -----------------------------------------------------------------------------+-- The MonadPlus class definition++-- | Monads that also support choice and failure.+class (Alternative m, Monad m) => MonadPlus m where+   -- | the identity of 'mplus'.  It should also satisfy the equations+   --+   -- > mzero >>= f  =  mzero+   -- > v >> mzero   =  mzero+   --+   mzero :: m a+   mzero = empty++   -- | an associative operation+   mplus :: m a -> m a -> m a+   mplus = (<|>)++instance MonadPlus Maybe++----------------------------------------------+-- The list type++instance Functor [] where+    {-# INLINE fmap #-}+    fmap = map++-- See Note: [List comprehensions and inlining]+instance Applicative [] where+    {-# INLINE pure #-}+    pure x    = [x]+    {-# INLINE (<*>) #-}+    fs <*> xs = [f x | f <- fs, x <- xs]+    {-# INLINE (*>) #-}+    xs *> ys  = [y | _ <- xs, y <- ys]++-- See Note: [List comprehensions and inlining]+instance Monad []  where+    {-# INLINE (>>=) #-}+    xs >>= f             = [y | x <- xs, y <- f x]+    {-# INLINE (>>) #-}+    (>>) = (*>)+    {-# INLINE return #-}+    return x            = [x]+    {-# INLINE fail #-}+    fail _              = []++instance Alternative [] where+    empty = []+    (<|>) = (++)++instance MonadPlus []++{-+A few list functions that appear here because they are used here.+The rest of the prelude list functions are in GHC.List.+-}++----------------------------------------------+--      foldr/build/augment+----------------------------------------------++-- | 'foldr', applied to a binary operator, a starting value (typically+-- the right-identity of the operator), and a list, reduces the list+-- using the binary operator, from right to left:+--+-- > foldr f z [x1, x2, ..., xn] == x1 `f` (x2 `f` ... (xn `f` z)...)++foldr            :: (a -> b -> b) -> b -> [a] -> b+-- foldr _ z []     =  z+-- foldr f z (x:xs) =  f x (foldr f z xs)+{-# INLINE [0] foldr #-}+-- Inline only in the final stage, after the foldr/cons rule has had a chance+-- Also note that we inline it when it has *two* parameters, which are the+-- ones we are keen about specialising!+foldr k z = go+          where+            go []     = z+            go (y:ys) = y `k` go ys++-- | A list producer that can be fused with 'foldr'.+-- This function is merely+--+-- >    build g = g (:) []+--+-- but GHC's simplifier will transform an expression of the form+-- @'foldr' k z ('build' g)@, which may arise after inlining, to @g k z@,+-- which avoids producing an intermediate list.++build   :: forall a. (forall b. (a -> b -> b) -> b -> b) -> [a]+{-# INLINE [1] build #-}+        -- The INLINE is important, even though build is tiny,+        -- because it prevents [] getting inlined in the version that+        -- appears in the interface file.  If [] *is* inlined, it+        -- won't match with [] appearing in rules in an importing module.+        --+        -- The "1" says to inline in phase 1++build g = g (:) []++-- | A list producer that can be fused with 'foldr'.+-- This function is merely+--+-- >    augment g xs = g (:) xs+--+-- but GHC's simplifier will transform an expression of the form+-- @'foldr' k z ('augment' g xs)@, which may arise after inlining, to+-- @g k ('foldr' k z xs)@, which avoids producing an intermediate list.++augment :: forall a. (forall b. (a->b->b) -> b -> b) -> [a] -> [a]+{-# INLINE [1] augment #-}+augment g xs = g (:) xs++{-# RULES+"fold/build"    forall k z (g::forall b. (a->b->b) -> b -> b) .+                foldr k z (build g) = g k z++"foldr/augment" forall k z xs (g::forall b. (a->b->b) -> b -> b) .+                foldr k z (augment g xs) = g k (foldr k z xs)++"foldr/id"                        foldr (:) [] = \x  -> x+"foldr/app"     [1] forall ys. foldr (:) ys = \xs -> xs ++ ys+        -- Only activate this from phase 1, because that's+        -- when we disable the rule that expands (++) into foldr++-- The foldr/cons rule looks nice, but it can give disastrously+-- bloated code when commpiling+--      array (a,b) [(1,2), (2,2), (3,2), ...very long list... ]+-- i.e. when there are very very long literal lists+-- So I've disabled it for now. We could have special cases+-- for short lists, I suppose.+-- "foldr/cons" forall k z x xs. foldr k z (x:xs) = k x (foldr k z xs)++"foldr/single"  forall k z x. foldr k z [x] = k x z+"foldr/nil"     forall k z.   foldr k z []  = z++"foldr/cons/build" forall k z x (g::forall b. (a->b->b) -> b -> b) .+                           foldr k z (x:build g) = k x (g k z)++"augment/build" forall (g::forall b. (a->b->b) -> b -> b)+                       (h::forall b. (a->b->b) -> b -> b) .+                       augment g (build h) = build (\c n -> g c (h c n))+"augment/nil"   forall (g::forall b. (a->b->b) -> b -> b) .+                        augment g [] = build g+ #-}++-- This rule is true, but not (I think) useful:+--      augment g (augment h t) = augment (\cn -> g c (h c n)) t++----------------------------------------------+--              map+----------------------------------------------++-- | 'map' @f xs@ is the list obtained by applying @f@ to each element+-- of @xs@, i.e.,+--+-- > map f [x1, x2, ..., xn] == [f x1, f x2, ..., f xn]+-- > map f [x1, x2, ...] == [f x1, f x2, ...]++map :: (a -> b) -> [a] -> [b]+{-# NOINLINE [1] map #-}    -- We want the RULE to fire first.+                            -- It's recursive, so won't inline anyway,+                            -- but saying so is more explicit+map _ []     = []+map f (x:xs) = f x : map f xs++-- Note eta expanded+mapFB ::  (elt -> lst -> lst) -> (a -> elt) -> a -> lst -> lst+{-# INLINE [0] mapFB #-}+mapFB c f = \x ys -> c (f x) ys++-- The rules for map work like this.+--+-- Up to (but not including) phase 1, we use the "map" rule to+-- rewrite all saturated applications of map with its build/fold+-- form, hoping for fusion to happen.+-- In phase 1 and 0, we switch off that rule, inline build, and+-- switch on the "mapList" rule, which rewrites the foldr/mapFB+-- thing back into plain map.+--+-- It's important that these two rules aren't both active at once+-- (along with build's unfolding) else we'd get an infinite loop+-- in the rules.  Hence the activation control below.+--+-- The "mapFB" rule optimises compositions of map.+--+-- This same pattern is followed by many other functions:+-- e.g. append, filter, iterate, repeat, etc.++{-# RULES+"map"       [~1] forall f xs.   map f xs                = build (\c n -> foldr (mapFB c f) n xs)+"mapList"   [1]  forall f.      foldr (mapFB (:) f) []  = map f+"mapFB"     forall c f g.       mapFB (mapFB c f) g     = mapFB c (f.g)+  #-}++-- See Breitner, Eisenberg, Peyton Jones, and Weirich, "Safe Zero-cost+-- Coercions for Haskell", section 6.5:+--   http://research.microsoft.com/en-us/um/people/simonpj/papers/ext-f/coercible.pdf++{-# RULES "map/coerce" [1] map coerce = coerce #-}+++----------------------------------------------+--              append+----------------------------------------------++-- | Append two lists, i.e.,+--+-- > [x1, ..., xm] ++ [y1, ..., yn] == [x1, ..., xm, y1, ..., yn]+-- > [x1, ..., xm] ++ [y1, ...] == [x1, ..., xm, y1, ...]+--+-- If the first list is not finite, the result is the first list.++(++) :: [a] -> [a] -> [a]+{-# NOINLINE [1] (++) #-}    -- We want the RULE to fire first.+                             -- It's recursive, so won't inline anyway,+                             -- but saying so is more explicit+(++) []     ys = ys+(++) (x:xs) ys = x : xs ++ ys++{-# RULES+"++"    [~1] forall xs ys. xs ++ ys = augment (\c n -> foldr c n xs) ys+  #-}+++-- |'otherwise' is defined as the value 'True'.  It helps to make+-- guards more readable.  eg.+--+-- >  f x | x < 0     = ...+-- >      | otherwise = ...+otherwise               :: Bool+otherwise               =  True++----------------------------------------------+-- Type Char and String+----------------------------------------------++-- | A 'String' is a list of characters.  String constants in Haskell are values+-- of type 'String'.+--+type String = [Char]++unsafeChr :: Int -> Char+unsafeChr (I# i#) = C# (chr# i#)++-- | The 'Prelude.fromEnum' method restricted to the type 'Data.Char.Char'.+ord :: Char -> Int+ord (C# c#) = I# (ord# c#)++-- | This 'String' equality predicate is used when desugaring+-- pattern-matches against strings.+eqString :: String -> String -> Bool+eqString []       []       = True+eqString (c1:cs1) (c2:cs2) = c1 == c2 && cs1 `eqString` cs2+eqString _        _        = False++{-# RULES "eqString" (==) = eqString #-}+-- eqString also has a BuiltInRule in PrelRules.lhs:+--      eqString (unpackCString# (Lit s1)) (unpackCString# (Lit s2) = s1==s2+++----------------------------------------------+-- 'Int' related definitions+----------------------------------------------++maxInt, minInt :: Int++{- Seems clumsy. Should perhaps put minInt and MaxInt directly into MachDeps.h -}+#if WORD_SIZE_IN_BITS == 31+minInt  = I# (-0x40000000#)+maxInt  = I# 0x3FFFFFFF#+#elif WORD_SIZE_IN_BITS == 32+minInt  = I# (-0x80000000#)+maxInt  = I# 0x7FFFFFFF#+#else+minInt  = I# (-0x8000000000000000#)+maxInt  = I# 0x7FFFFFFFFFFFFFFF#+#endif++----------------------------------------------+-- The function type+----------------------------------------------++-- | Identity function.+id                      :: a -> a+id x                    =  x++-- Assertion function.  This simply ignores its boolean argument.+-- The compiler may rewrite it to @('assertError' line)@.++-- | If the first argument evaluates to 'True', then the result is the+-- second argument.  Otherwise an 'AssertionFailed' exception is raised,+-- containing a 'String' with the source file and line number of the+-- call to 'assert'.+--+-- Assertions can normally be turned on or off with a compiler flag+-- (for GHC, assertions are normally on unless optimisation is turned on+-- with @-O@ or the @-fignore-asserts@+-- option is given).  When assertions are turned off, the first+-- argument to 'assert' is ignored, and the second argument is+-- returned as the result.++--      SLPJ: in 5.04 etc 'assert' is in GHC.Prim,+--      but from Template Haskell onwards it's simply+--      defined here in Base.lhs+assert :: Bool -> a -> a+assert _pred r = r++breakpoint :: a -> a+breakpoint r = r++breakpointCond :: Bool -> a -> a+breakpointCond _ r = r++data Opaque = forall a. O a++-- | Constant function.+const                   :: a -> b -> a+const x _               =  x++-- | Function composition.+{-# INLINE (.) #-}+-- Make sure it has TWO args only on the left, so that it inlines+-- when applied to two functions, even if there is no final argument+(.)    :: (b -> c) -> (a -> b) -> a -> c+(.) f g = \x -> f (g x)++-- | @'flip' f@ takes its (first) two arguments in the reverse order of @f@.+flip                    :: (a -> b -> c) -> b -> a -> c+flip f x y              =  f y x++-- | Application operator.  This operator is redundant, since ordinary+-- application @(f x)@ means the same as @(f '$' x)@. However, '$' has+-- low, right-associative binding precedence, so it sometimes allows+-- parentheses to be omitted; for example:+--+-- >     f $ g $ h x  =  f (g (h x))+--+-- It is also useful in higher-order situations, such as @'map' ('$' 0) xs@,+-- or @'Data.List.zipWith' ('$') fs xs@.+{-# INLINE ($) #-}+($)                     :: (a -> b) -> a -> b+f $ x                   =  f x++-- | Strict (call-by-value) application operator. It takes a function and an+-- argument, evaluates the argument to weak head normal form (WHNF), then calls+-- the function with that value.++($!)                    :: (a -> b) -> a -> b+f $! x                  = let !vx = x in f vx  -- see #2273++-- | @'until' p f@ yields the result of applying @f@ until @p@ holds.+until                   :: (a -> Bool) -> (a -> a) -> a -> a+until p f = go+  where+    go x | p x          = x+         | otherwise    = go (f x)++-- | 'asTypeOf' is a type-restricted version of 'const'.  It is usually+-- used as an infix operator, and its typing forces its first argument+-- (which is usually overloaded) to have the same type as the second.+asTypeOf                :: a -> a -> a+asTypeOf                =  const++----------------------------------------------+-- Functor/Applicative/Monad instances for IO+----------------------------------------------++instance  Functor IO where+   fmap f x = x >>= (return . f)++instance Applicative IO where+    pure = return+    (<*>) = ap++instance  Monad IO  where+    {-# INLINE return #-}+    {-# INLINE (>>)   #-}+    {-# INLINE (>>=)  #-}+    m >> k    = m >>= \ _ -> k+    return    = returnIO+    (>>=)     = bindIO+    fail s    = failIO s++returnIO :: a -> IO a+returnIO x = IO $ \ s -> (# s, x #)++bindIO :: IO a -> (a -> IO b) -> IO b+bindIO (IO m) k = IO $ \ s -> case m s of (# new_s, a #) -> unIO (k a) new_s++thenIO :: IO a -> IO b -> IO b+thenIO (IO m) k = IO $ \ s -> case m s of (# new_s, _ #) -> unIO k new_s++unIO :: IO a -> (State# RealWorld -> (# State# RealWorld, a #))+unIO (IO a) = a++{- |+Returns the 'tag' of a constructor application; this function is used+by the deriving code for Eq, Ord and Enum.++The primitive dataToTag# requires an evaluated constructor application+as its argument, so we provide getTag as a wrapper that performs the+evaluation before calling dataToTag#.  We could have dataToTag#+evaluate its argument, but we prefer to do it this way because (a)+dataToTag# can be an inline primop if it doesn't need to do any+evaluation, and (b) we want to expose the evaluation to the+simplifier, because it might be possible to eliminate the evaluation+in the case when the argument is already known to be evaluated.+-}+{-# INLINE getTag #-}+getTag :: a -> Int#+getTag !x = dataToTag# x++----------------------------------------------+-- Numeric primops+----------------------------------------------++-- Definitions of the boxed PrimOps; these will be+-- used in the case of partial applications, etc.++{-# INLINE quotInt #-}+{-# INLINE remInt #-}++quotInt, remInt, divInt, modInt :: Int -> Int -> Int+(I# x) `quotInt`  (I# y) = I# (x `quotInt#` y)+(I# x) `remInt`   (I# y) = I# (x `remInt#`  y)+(I# x) `divInt`   (I# y) = I# (x `divInt#`  y)+(I# x) `modInt`   (I# y) = I# (x `modInt#`  y)++quotRemInt :: Int -> Int -> (Int, Int)+(I# x) `quotRemInt` (I# y) = case x `quotRemInt#` y of+                             (# q, r #) ->+                                 (I# q, I# r)++divModInt :: Int -> Int -> (Int, Int)+(I# x) `divModInt` (I# y) = case x `divModInt#` y of+                            (# q, r #) -> (I# q, I# r)++divModInt# :: Int# -> Int# -> (# Int#, Int# #)+x# `divModInt#` y#+ | isTrue# (x# ># 0#) && isTrue# (y# <# 0#) =+                                    case (x# -# 1#) `quotRemInt#` y# of+                                      (# q, r #) -> (# q -# 1#, r +# y# +# 1# #)+ | isTrue# (x# <# 0#) && isTrue# (y# ># 0#) =+                                    case (x# +# 1#) `quotRemInt#` y# of+                                      (# q, r #) -> (# q -# 1#, r +# y# -# 1# #)+ | otherwise                                =+                                    x# `quotRemInt#` y#++-- Wrappers for the shift operations.  The uncheckedShift# family are+-- undefined when the amount being shifted by is greater than the size+-- in bits of Int#, so these wrappers perform a check and return+-- either zero or -1 appropriately.+--+-- Note that these wrappers still produce undefined results when the+-- second argument (the shift amount) is negative.++-- | Shift the argument left by the specified number of bits+-- (which must be non-negative).+shiftL# :: Word# -> Int# -> Word#+a `shiftL#` b   | isTrue# (b >=# WORD_SIZE_IN_BITS#) = 0##+                | otherwise                          = a `uncheckedShiftL#` b++-- | Shift the argument right by the specified number of bits+-- (which must be non-negative).+-- The "RL" means "right, logical" (as opposed to RA for arithmetic)+-- (although an arithmetic right shift wouldn't make sense for Word#)+shiftRL# :: Word# -> Int# -> Word#+a `shiftRL#` b  | isTrue# (b >=# WORD_SIZE_IN_BITS#) = 0##+                | otherwise                          = a `uncheckedShiftRL#` b++-- | Shift the argument left by the specified number of bits+-- (which must be non-negative).+iShiftL# :: Int# -> Int# -> Int#+a `iShiftL#` b  | isTrue# (b >=# WORD_SIZE_IN_BITS#) = 0#+                | otherwise                          = a `uncheckedIShiftL#` b++-- | Shift the argument right (signed) by the specified number of bits+-- (which must be non-negative).+-- The "RA" means "right, arithmetic" (as opposed to RL for logical)+iShiftRA# :: Int# -> Int# -> Int#+a `iShiftRA#` b | isTrue# (b >=# WORD_SIZE_IN_BITS#) = if isTrue# (a <# 0#)+                                                          then (-1#)+                                                          else 0#+                | otherwise                          = a `uncheckedIShiftRA#` b++-- | Shift the argument right (unsigned) by the specified number of bits+-- (which must be non-negative).+-- The "RL" means "right, logical" (as opposed to RA for arithmetic)+iShiftRL# :: Int# -> Int# -> Int#+a `iShiftRL#` b | isTrue# (b >=# WORD_SIZE_IN_BITS#) = 0#+                | otherwise                          = a `uncheckedIShiftRL#` b++-- Rules for C strings (the functions themselves are now in GHC.CString)+{-# RULES+"unpack"       [~1] forall a   . unpackCString# a             = build (unpackFoldrCString# a)+"unpack-list"  [1]  forall a   . unpackFoldrCString# a (:) [] = unpackCString# a+"unpack-append"     forall a n . unpackFoldrCString# a (:) n  = unpackAppendCString# a n++-- There's a built-in rule (in PrelRules.lhs) for+--      unpackFoldr "foo" c (unpackFoldr "baz" c n)  =  unpackFoldr "foobaz" c n++  #-}+++#ifdef __HADDOCK__+-- | A special argument for the 'Control.Monad.ST.ST' type constructor,+-- indexing a state embedded in the 'Prelude.IO' monad by+-- 'Control.Monad.ST.stToIO'.+data RealWorld+#endif
− GHC/Base.lhs
@@ -1,741 +0,0 @@-\section[GHC.Base]{Module @GHC.Base@}--The overall structure of the GHC Prelude is a bit tricky.--  a) We want to avoid "orphan modules", i.e. ones with instance-        decls that don't belong either to a tycon or a class-        defined in the same module--  b) We want to avoid giant modules--So the rough structure is as follows, in (linearised) dependency order---GHC.Prim        Has no implementation.  It defines built-in things, and-                by importing it you bring them into scope.-                The source file is GHC.Prim.hi-boot, which is just-                copied to make GHC.Prim.hi--GHC.Base        Classes: Eq, Ord, Functor, Monad-                Types:   list, (), Int, Bool, Ordering, Char, String--Data.Tuple      Types: tuples, plus instances for GHC.Base classes--GHC.Show        Class: Show, plus instances for GHC.Base/GHC.Tup types--GHC.Enum        Class: Enum,  plus instances for GHC.Base/GHC.Tup types--Data.Maybe      Type: Maybe, plus instances for GHC.Base classes--GHC.List        List functions--GHC.Num         Class: Num, plus instances for Int-                Type:  Integer, plus instances for all classes so far (Eq, Ord, Num, Show)--                Integer is needed here because it is mentioned in the signature-                of 'fromInteger' in class Num--GHC.Real        Classes: Real, Integral, Fractional, RealFrac-                         plus instances for Int, Integer-                Types:  Ratio, Rational-                        plus intances for classes so far--                Rational is needed here because it is mentioned in the signature-                of 'toRational' in class Real--GHC.ST  The ST monad, instances and a few helper functions--Ix              Classes: Ix, plus instances for Int, Bool, Char, Integer, Ordering, tuples--GHC.Arr         Types: Array, MutableArray, MutableVar--                Arrays are used by a function in GHC.Float--GHC.Float       Classes: Floating, RealFloat-                Types:   Float, Double, plus instances of all classes so far--                This module contains everything to do with floating point.-                It is a big module (900 lines)-                With a bit of luck, many modules can be compiled without ever reading GHC.Float.hi---Other Prelude modules are much easier with fewer complex dependencies.--\begin{code}-{-# LANGUAGE Unsafe #-}-{-# LANGUAGE CPP-           , NoImplicitPrelude-           , BangPatterns-           , ExplicitForAll-           , MagicHash-           , UnboxedTuples-           , ExistentialQuantification-           , RankNTypes-  #-}--- -fno-warn-orphans is needed for things like:--- Orphan rule: "x# -# x#" ALWAYS forall x# :: Int# -# x# x# = 0-{-# OPTIONS_GHC -fno-warn-orphans #-}-{-# OPTIONS_HADDOCK hide #-}---------------------------------------------------------------------------------- |--- Module      :  GHC.Base--- Copyright   :  (c) The University of Glasgow, 1992-2002--- License     :  see libraries/base/LICENSE------ Maintainer  :  cvs-ghc@haskell.org--- Stability   :  internal--- Portability :  non-portable (GHC extensions)------ Basic data types and classes.-----------------------------------------------------------------------------------#include "MachDeps.h"--module GHC.Base-        (-        module GHC.Base,-        module GHC.Classes,-        module GHC.CString,-        module GHC.Magic,-        module GHC.Types,-        module GHC.Prim,        -- Re-export GHC.Prim and [boot] GHC.Err,-                                -- to avoid lots of people having to-        module GHC.Err          -- import it explicitly-  )-        where--import GHC.Types-import GHC.Classes-import GHC.CString-import GHC.Magic-import GHC.Prim-import GHC.Err-import {-# SOURCE #-} GHC.IO (failIO)---- This is not strictly speaking required by this module, but is an--- implicit dependency whenever () or tuples are mentioned, so adding it--- as an import here helps to get the dependencies right in the new--- build system.-import GHC.Tuple ()--- Likewise we need Integer when deriving things like Eq instances, and--- this is a convenient place to force it to be built-import GHC.Integer ()--infixr 9  .-infixr 5  ++-infixl 4  <$-infixl 1  >>, >>=-infixr 0  $--default ()              -- Double isn't available yet-\end{code}---%*********************************************************-%*                                                      *-\subsection{DEBUGGING STUFF}-%*  (for use when compiling GHC.Base itself doesn't work)-%*                                                      *-%*********************************************************--\begin{code}-{--data  Bool  =  False | True-data Ordering = LT | EQ | GT-data Char = C# Char#-type  String = [Char]-data Int = I# Int#-data  ()  =  ()-data [] a = MkNil--not True = False-(&&) True True = True-otherwise = True--build = error "urk"-foldr = error "urk"--}-\end{code}---%*********************************************************-%*                                                      *-\subsection{Monadic classes @Functor@, @Monad@ }-%*                                                      *-%*********************************************************--\begin{code}-{- | The 'Functor' class is used for types that can be mapped over.-Instances of 'Functor' should satisfy the following laws:--> fmap id  ==  id-> fmap (f . g)  ==  fmap f . fmap g--The instances of 'Functor' for lists, 'Data.Maybe.Maybe' and 'System.IO.IO'-satisfy these laws.--}--class  Functor f  where-    fmap        :: (a -> b) -> f a -> f b--    -- | Replace all locations in the input with the same value.-    -- The default definition is @'fmap' . 'const'@, but this may be-    -- overridden with a more efficient version.-    (<$)        :: a -> f b -> f a-    (<$)        =  fmap . const--{- | The 'Monad' class defines the basic operations over a /monad/,-a concept from a branch of mathematics known as /category theory/.-From the perspective of a Haskell programmer, however, it is best to-think of a monad as an /abstract datatype/ of actions.-Haskell's @do@ expressions provide a convenient syntax for writing-monadic expressions.--Minimal complete definition: '>>=' and 'return'.--Instances of 'Monad' should satisfy the following laws:--> return a >>= k  ==  k a-> m >>= return  ==  m-> m >>= (\x -> k x >>= h)  ==  (m >>= k) >>= h--Instances of both 'Monad' and 'Functor' should additionally satisfy the law:--> fmap f xs  ==  xs >>= return . f--The instances of 'Monad' for lists, 'Data.Maybe.Maybe' and 'System.IO.IO'-defined in the "Prelude" satisfy these laws.--}--class  Monad m  where-    -- | Sequentially compose two actions, passing any value produced-    -- by the first as an argument to the second.-    (>>=)       :: forall a b. m a -> (a -> m b) -> m b-    -- | Sequentially compose two actions, discarding any value produced-    -- by the first, like sequencing operators (such as the semicolon)-    -- in imperative languages.-    (>>)        :: forall a b. m a -> m b -> m b-        -- Explicit for-alls so that we know what order to-        -- give type arguments when desugaring--    -- | Inject a value into the monadic type.-    return      :: a -> m a-    -- | Fail with a message.  This operation is not part of the-    -- mathematical definition of a monad, but is invoked on pattern-match-    -- failure in a @do@ expression.-    fail        :: String -> m a--    {-# INLINE (>>) #-}-    m >> k      = m >>= \_ -> k-    fail s      = error s--instance Functor ((->) r) where-    fmap = (.)--instance Monad ((->) r) where-    return = const-    f >>= k = \ r -> k (f r) r--instance Functor ((,) a) where-    fmap f (x,y) = (x, f y)-\end{code}---%*********************************************************-%*                                                      *-\subsection{The list type}-%*                                                      *-%*********************************************************--\begin{code}-instance Functor [] where-    fmap = map--instance  Monad []  where-    m >>= k             = foldr ((++) . k) [] m-    m >> k              = foldr ((++) . (\ _ -> k)) [] m-    return x            = [x]-    fail _              = []-\end{code}--A few list functions that appear here because they are used here.-The rest of the prelude list functions are in GHC.List.---------------------------------------------------      foldr/build/augment-------------------------------------------------\begin{code}--- | 'foldr', applied to a binary operator, a starting value (typically--- the right-identity of the operator), and a list, reduces the list--- using the binary operator, from right to left:------ > foldr f z [x1, x2, ..., xn] == x1 `f` (x2 `f` ... (xn `f` z)...)--foldr            :: (a -> b -> b) -> b -> [a] -> b--- foldr _ z []     =  z--- foldr f z (x:xs) =  f x (foldr f z xs)-{-# INLINE [0] foldr #-}--- Inline only in the final stage, after the foldr/cons rule has had a chance--- Also note that we inline it when it has *two* parameters, which are the--- ones we are keen about specialising!-foldr k z = go-          where-            go []     = z-            go (y:ys) = y `k` go ys---- | A list producer that can be fused with 'foldr'.--- This function is merely------ >    build g = g (:) []------ but GHC's simplifier will transform an expression of the form--- @'foldr' k z ('build' g)@, which may arise after inlining, to @g k z@,--- which avoids producing an intermediate list.--build   :: forall a. (forall b. (a -> b -> b) -> b -> b) -> [a]-{-# INLINE [1] build #-}-        -- The INLINE is important, even though build is tiny,-        -- because it prevents [] getting inlined in the version that-        -- appears in the interface file.  If [] *is* inlined, it-        -- won't match with [] appearing in rules in an importing module.-        ---        -- The "1" says to inline in phase 1--build g = g (:) []---- | A list producer that can be fused with 'foldr'.--- This function is merely------ >    augment g xs = g (:) xs------ but GHC's simplifier will transform an expression of the form--- @'foldr' k z ('augment' g xs)@, which may arise after inlining, to--- @g k ('foldr' k z xs)@, which avoids producing an intermediate list.--augment :: forall a. (forall b. (a->b->b) -> b -> b) -> [a] -> [a]-{-# INLINE [1] augment #-}-augment g xs = g (:) xs--{-# RULES-"fold/build"    forall k z (g::forall b. (a->b->b) -> b -> b) .-                foldr k z (build g) = g k z--"foldr/augment" forall k z xs (g::forall b. (a->b->b) -> b -> b) .-                foldr k z (augment g xs) = g k (foldr k z xs)--"foldr/id"                        foldr (:) [] = \x  -> x-"foldr/app"     [1] forall ys. foldr (:) ys = \xs -> xs ++ ys-        -- Only activate this from phase 1, because that's-        -- when we disable the rule that expands (++) into foldr---- The foldr/cons rule looks nice, but it can give disastrously--- bloated code when commpiling---      array (a,b) [(1,2), (2,2), (3,2), ...very long list... ]--- i.e. when there are very very long literal lists--- So I've disabled it for now. We could have special cases--- for short lists, I suppose.--- "foldr/cons" forall k z x xs. foldr k z (x:xs) = k x (foldr k z xs)--"foldr/single"  forall k z x. foldr k z [x] = k x z-"foldr/nil"     forall k z.   foldr k z []  = z--"augment/build" forall (g::forall b. (a->b->b) -> b -> b)-                       (h::forall b. (a->b->b) -> b -> b) .-                       augment g (build h) = build (\c n -> g c (h c n))-"augment/nil"   forall (g::forall b. (a->b->b) -> b -> b) .-                        augment g [] = build g- #-}---- This rule is true, but not (I think) useful:---      augment g (augment h t) = augment (\cn -> g c (h c n)) t-\end{code}----------------------------------------------------              map-------------------------------------------------\begin{code}--- | 'map' @f xs@ is the list obtained by applying @f@ to each element--- of @xs@, i.e.,------ > map f [x1, x2, ..., xn] == [f x1, f x2, ..., f xn]--- > map f [x1, x2, ...] == [f x1, f x2, ...]--map :: (a -> b) -> [a] -> [b]-{-# NOINLINE [1] map #-}    -- We want the RULE to fire first.-                            -- It's recursive, so won't inline anyway,-                            -- but saying so is more explicit-map _ []     = []-map f (x:xs) = f x : map f xs---- Note eta expanded-mapFB ::  (elt -> lst -> lst) -> (a -> elt) -> a -> lst -> lst-{-# INLINE [0] mapFB #-}-mapFB c f = \x ys -> c (f x) ys---- The rules for map work like this.------ Up to (but not including) phase 1, we use the "map" rule to--- rewrite all saturated applications of map with its build/fold--- form, hoping for fusion to happen.--- In phase 1 and 0, we switch off that rule, inline build, and--- switch on the "mapList" rule, which rewrites the foldr/mapFB--- thing back into plain map.------ It's important that these two rules aren't both active at once--- (along with build's unfolding) else we'd get an infinite loop--- in the rules.  Hence the activation control below.------ The "mapFB" rule optimises compositions of map.------ This same pattern is followed by many other functions:--- e.g. append, filter, iterate, repeat, etc.--{-# RULES-"map"       [~1] forall f xs.   map f xs                = build (\c n -> foldr (mapFB c f) n xs)-"mapList"   [1]  forall f.      foldr (mapFB (:) f) []  = map f-"mapFB"     forall c f g.       mapFB (mapFB c f) g     = mapFB c (f.g)-  #-}-\end{code}----------------------------------------------------              append------------------------------------------------\begin{code}--- | Append two lists, i.e.,------ > [x1, ..., xm] ++ [y1, ..., yn] == [x1, ..., xm, y1, ..., yn]--- > [x1, ..., xm] ++ [y1, ...] == [x1, ..., xm, y1, ...]------ If the first list is not finite, the result is the first list.--(++) :: [a] -> [a] -> [a]-{-# NOINLINE [1] (++) #-}    -- We want the RULE to fire first.-                             -- It's recursive, so won't inline anyway,-                             -- but saying so is more explicit-(++) []     ys = ys-(++) (x:xs) ys = x : xs ++ ys--{-# RULES-"++"    [~1] forall xs ys. xs ++ ys = augment (\c n -> foldr c n xs) ys-  #-}--\end{code}---%*********************************************************-%*                                                      *-\subsection{Type @Bool@}-%*                                                      *-%*********************************************************--\begin{code}--- |'otherwise' is defined as the value 'True'.  It helps to make--- guards more readable.  eg.------ >  f x | x < 0     = ...--- >      | otherwise = ...-otherwise               :: Bool-otherwise               =  True-\end{code}--%*********************************************************-%*                                                      *-\subsection{Type @Char@ and @String@}-%*                                                      *-%*********************************************************--\begin{code}--- | A 'String' is a list of characters.  String constants in Haskell are values--- of type 'String'.----type String = [Char]--unsafeChr :: Int -> Char-unsafeChr (I# i#) = C# (chr# i#)---- | The 'Prelude.fromEnum' method restricted to the type 'Data.Char.Char'.-ord :: Char -> Int-ord (C# c#) = I# (ord# c#)-\end{code}--String equality is used when desugaring pattern-matches against strings.--\begin{code}-eqString :: String -> String -> Bool-eqString []       []       = True-eqString (c1:cs1) (c2:cs2) = c1 == c2 && cs1 `eqString` cs2-eqString _        _        = False--{-# RULES "eqString" (==) = eqString #-}--- eqString also has a BuiltInRule in PrelRules.lhs:---      eqString (unpackCString# (Lit s1)) (unpackCString# (Lit s2) = s1==s2-\end{code}---%*********************************************************-%*                                                      *-\subsection{Type @Int@}-%*                                                      *-%*********************************************************--\begin{code}-maxInt, minInt :: Int--{- Seems clumsy. Should perhaps put minInt and MaxInt directly into MachDeps.h -}-#if WORD_SIZE_IN_BITS == 31-minInt  = I# (-0x40000000#)-maxInt  = I# 0x3FFFFFFF#-#elif WORD_SIZE_IN_BITS == 32-minInt  = I# (-0x80000000#)-maxInt  = I# 0x7FFFFFFF#-#else-minInt  = I# (-0x8000000000000000#)-maxInt  = I# 0x7FFFFFFFFFFFFFFF#-#endif-\end{code}---%*********************************************************-%*                                                      *-\subsection{The function type}-%*                                                      *-%*********************************************************--\begin{code}--- | Identity function.-id                      :: a -> a-id x                    =  x---- Assertion function.  This simply ignores its boolean argument.--- The compiler may rewrite it to @('assertError' line)@.---- | If the first argument evaluates to 'True', then the result is the--- second argument.  Otherwise an 'AssertionFailed' exception is raised,--- containing a 'String' with the source file and line number of the--- call to 'assert'.------ Assertions can normally be turned on or off with a compiler flag--- (for GHC, assertions are normally on unless optimisation is turned on--- with @-O@ or the @-fignore-asserts@--- option is given).  When assertions are turned off, the first--- argument to 'assert' is ignored, and the second argument is--- returned as the result.----      SLPJ: in 5.04 etc 'assert' is in GHC.Prim,---      but from Template Haskell onwards it's simply---      defined here in Base.lhs-assert :: Bool -> a -> a-assert _pred r = r--breakpoint :: a -> a-breakpoint r = r--breakpointCond :: Bool -> a -> a-breakpointCond _ r = r--data Opaque = forall a. O a---- | Constant function.-const                   :: a -> b -> a-const x _               =  x---- | Function composition.-{-# INLINE (.) #-}--- Make sure it has TWO args only on the left, so that it inlines--- when applied to two functions, even if there is no final argument-(.)    :: (b -> c) -> (a -> b) -> a -> c-(.) f g = \x -> f (g x)---- | @'flip' f@ takes its (first) two arguments in the reverse order of @f@.-flip                    :: (a -> b -> c) -> b -> a -> c-flip f x y              =  f y x---- | Application operator.  This operator is redundant, since ordinary--- application @(f x)@ means the same as @(f '$' x)@. However, '$' has--- low, right-associative binding precedence, so it sometimes allows--- parentheses to be omitted; for example:------ >     f $ g $ h x  =  f (g (h x))------ It is also useful in higher-order situations, such as @'map' ('$' 0) xs@,--- or @'Data.List.zipWith' ('$') fs xs@.-{-# INLINE ($) #-}-($)                     :: (a -> b) -> a -> b-f $ x                   =  f x---- | @'until' p f@ yields the result of applying @f@ until @p@ holds.-until                   :: (a -> Bool) -> (a -> a) -> a -> a-until p f = go-  where-    go x | p x          = x-         | otherwise    = go (f x)---- | 'asTypeOf' is a type-restricted version of 'const'.  It is usually--- used as an infix operator, and its typing forces its first argument--- (which is usually overloaded) to have the same type as the second.-asTypeOf                :: a -> a -> a-asTypeOf                =  const-\end{code}--%*********************************************************-%*                                                      *-\subsection{@Functor@ and @Monad@ instances for @IO@}-%*                                                      *-%*********************************************************--\begin{code}-instance  Functor IO where-   fmap f x = x >>= (return . f)--instance  Monad IO  where-    {-# INLINE return #-}-    {-# INLINE (>>)   #-}-    {-# INLINE (>>=)  #-}-    m >> k    = m >>= \ _ -> k-    return    = returnIO-    (>>=)     = bindIO-    fail s    = failIO s--returnIO :: a -> IO a-returnIO x = IO $ \ s -> (# s, x #)--bindIO :: IO a -> (a -> IO b) -> IO b-bindIO (IO m) k = IO $ \ s -> case m s of (# new_s, a #) -> unIO (k a) new_s--thenIO :: IO a -> IO b -> IO b-thenIO (IO m) k = IO $ \ s -> case m s of (# new_s, _ #) -> unIO k new_s--unIO :: IO a -> (State# RealWorld -> (# State# RealWorld, a #))-unIO (IO a) = a-\end{code}--%*********************************************************-%*                                                      *-\subsection{@getTag@}-%*                                                      *-%*********************************************************--Returns the 'tag' of a constructor application; this function is used-by the deriving code for Eq, Ord and Enum.--The primitive dataToTag# requires an evaluated constructor application-as its argument, so we provide getTag as a wrapper that performs the-evaluation before calling dataToTag#.  We could have dataToTag#-evaluate its argument, but we prefer to do it this way because (a)-dataToTag# can be an inline primop if it doesn't need to do any-evaluation, and (b) we want to expose the evaluation to the-simplifier, because it might be possible to eliminate the evaluation-in the case when the argument is already known to be evaluated.--\begin{code}-{-# INLINE getTag #-}-getTag :: a -> Int#-getTag x = x `seq` dataToTag# x-\end{code}--%*********************************************************-%*                                                      *-\subsection{Numeric primops}-%*                                                      *-%*********************************************************--Definitions of the boxed PrimOps; these will be-used in the case of partial applications, etc.--\begin{code}-{-# INLINE quotInt #-}-{-# INLINE remInt #-}--quotInt, remInt, divInt, modInt :: Int -> Int -> Int-(I# x) `quotInt`  (I# y) = I# (x `quotInt#` y)-(I# x) `remInt`   (I# y) = I# (x `remInt#`  y)-(I# x) `divInt`   (I# y) = I# (x `divInt#`  y)-(I# x) `modInt`   (I# y) = I# (x `modInt#`  y)--quotRemInt :: Int -> Int -> (Int, Int)-(I# x) `quotRemInt` (I# y) = case x `quotRemInt#` y of-                             (# q, r #) ->-                                 (I# q, I# r)--divModInt :: Int -> Int -> (Int, Int)-(I# x) `divModInt` (I# y) = case x `divModInt#` y of-                            (# q, r #) -> (I# q, I# r)--divModInt# :: Int# -> Int# -> (# Int#, Int# #)-x# `divModInt#` y#- | isTrue# (x# ># 0#) && isTrue# (y# <# 0#) =-                                    case (x# -# 1#) `quotRemInt#` y# of-                                      (# q, r #) -> (# q -# 1#, r +# y# +# 1# #)- | isTrue# (x# <# 0#) && isTrue# (y# ># 0#) =-                                    case (x# +# 1#) `quotRemInt#` y# of-                                      (# q, r #) -> (# q -# 1#, r +# y# -# 1# #)- | otherwise                                =-                                    x# `quotRemInt#` y#---- Wrappers for the shift operations.  The uncheckedShift# family are--- undefined when the amount being shifted by is greater than the size--- in bits of Int#, so these wrappers perform a check and return--- either zero or -1 appropriately.------ Note that these wrappers still produce undefined results when the--- second argument (the shift amount) is negative.---- | Shift the argument left by the specified number of bits--- (which must be non-negative).-shiftL# :: Word# -> Int# -> Word#-a `shiftL#` b   | isTrue# (b >=# WORD_SIZE_IN_BITS#) = 0##-                | otherwise                          = a `uncheckedShiftL#` b---- | Shift the argument right by the specified number of bits--- (which must be non-negative).-shiftRL# :: Word# -> Int# -> Word#-a `shiftRL#` b  | isTrue# (b >=# WORD_SIZE_IN_BITS#) = 0##-                | otherwise                          = a `uncheckedShiftRL#` b---- | Shift the argument left by the specified number of bits--- (which must be non-negative).-iShiftL# :: Int# -> Int# -> Int#-a `iShiftL#` b  | isTrue# (b >=# WORD_SIZE_IN_BITS#) = 0#-                | otherwise                          = a `uncheckedIShiftL#` b---- | Shift the argument right (signed) by the specified number of bits--- (which must be non-negative).-iShiftRA# :: Int# -> Int# -> Int#-a `iShiftRA#` b | isTrue# (b >=# WORD_SIZE_IN_BITS#) = if isTrue# (a <# 0#)-                                                          then (-1#)-                                                          else 0#-                | otherwise                          = a `uncheckedIShiftRA#` b---- | Shift the argument right (unsigned) by the specified number of bits--- (which must be non-negative).-iShiftRL# :: Int# -> Int# -> Int#-a `iShiftRL#` b | isTrue# (b >=# WORD_SIZE_IN_BITS#) = 0#-                | otherwise                          = a `uncheckedIShiftRL#` b---- Rules for C strings (the functions themselves are now in GHC.CString)-{-# RULES-"unpack"       [~1] forall a   . unpackCString# a             = build (unpackFoldrCString# a)-"unpack-list"  [1]  forall a   . unpackFoldrCString# a (:) [] = unpackCString# a-"unpack-append"     forall a n . unpackFoldrCString# a (:) n  = unpackAppendCString# a n---- There's a built-in rule (in PrelRules.lhs) for---      unpackFoldr "foo" c (unpackFoldr "baz" c n)  =  unpackFoldr "foobaz" c n--  #-}-\end{code}---#ifdef __HADDOCK__-\begin{code}--- | A special argument for the 'Control.Monad.ST.ST' type constructor,--- indexing a state embedded in the 'Prelude.IO' monad by--- 'Control.Monad.ST.stToIO'.-data RealWorld-\end{code}-#endif
GHC/Char.hs view
@@ -1,4 +1,4 @@-+{-# LANGUAGE Trustworthy #-} {-# LANGUAGE NoImplicitPrelude, MagicHash #-}  module GHC.Char (chr) where
+ GHC/Conc.hs view
@@ -0,0 +1,119 @@+{-# LANGUAGE Unsafe #-}+{-# LANGUAGE CPP, NoImplicitPrelude #-}+{-# OPTIONS_GHC -fno-warn-missing-signatures #-}+{-# OPTIONS_HADDOCK not-home #-}++-----------------------------------------------------------------------------+-- |+-- Module      :  GHC.Conc+-- Copyright   :  (c) The University of Glasgow, 1994-2002+-- License     :  see libraries/base/LICENSE+--+-- Maintainer  :  cvs-ghc@haskell.org+-- Stability   :  internal+-- Portability :  non-portable (GHC extensions)+--+-- Basic concurrency stuff.+--+-----------------------------------------------------------------------------++-- No: #hide, because bits of this module are exposed by the stm package.+-- However, we don't want this module to be the home location for the+-- bits it exports, we'd rather have Control.Concurrent and the other+-- higher level modules be the home.  Hence: #not-home++module GHC.Conc+        ( ThreadId(..)++        -- * Forking and suchlike+        , forkIO+        , forkIOWithUnmask+        , forkOn+        , forkOnWithUnmask+        , numCapabilities+        , getNumCapabilities+        , setNumCapabilities+        , getNumProcessors+        , numSparks+        , childHandler+        , myThreadId+        , killThread+        , throwTo+        , par+        , pseq+        , runSparks+        , yield+        , labelThread+        , mkWeakThreadId++        , ThreadStatus(..), BlockReason(..)+        , threadStatus+        , threadCapability++        -- * Waiting+        , threadDelay+        , registerDelay+        , threadWaitRead+        , threadWaitWrite+        , threadWaitReadSTM+        , threadWaitWriteSTM+        , closeFdWith++        -- * Allocation counter and limit+        , setAllocationCounter+        , getAllocationCounter+        , enableAllocationLimit+        , disableAllocationLimit++        -- * TVars+        , STM(..)+        , atomically+        , retry+        , orElse+        , throwSTM+        , catchSTM+        , alwaysSucceeds+        , always+        , TVar(..)+        , newTVar+        , newTVarIO+        , readTVar+        , readTVarIO+        , writeTVar+        , unsafeIOToSTM++        -- * Miscellaneous+        , withMVar+#ifdef mingw32_HOST_OS+        , asyncRead+        , asyncWrite+        , asyncDoProc++        , asyncReadBA+        , asyncWriteBA+#endif++#ifndef mingw32_HOST_OS+        , Signal, HandlerFun, setHandler, runHandlers+#endif++        , ensureIOManagerIsRunning+        , ioManagerCapabilitiesChanged++#ifdef mingw32_HOST_OS+        , ConsoleEvent(..)+        , win32ConsoleHandler+        , toWin32ConsoleEvent+#endif+        , setUncaughtExceptionHandler+        , getUncaughtExceptionHandler++        , reportError, reportStackOverflow+        ) where++import GHC.Conc.IO+import GHC.Conc.Sync++#ifndef mingw32_HOST_OS+import GHC.Conc.Signal+#endif
− GHC/Conc.lhs
@@ -1,116 +0,0 @@-\begin{code}-{-# LANGUAGE Unsafe #-}-{-# LANGUAGE CPP, NoImplicitPrelude #-}-{-# OPTIONS_GHC -fno-warn-missing-signatures #-}-{-# OPTIONS_HADDOCK not-home #-}---------------------------------------------------------------------------------- |--- Module      :  GHC.Conc--- Copyright   :  (c) The University of Glasgow, 1994-2002--- License     :  see libraries/base/LICENSE--- --- Maintainer  :  cvs-ghc@haskell.org--- Stability   :  internal--- Portability :  non-portable (GHC extensions)------ Basic concurrency stuff.--- ---------------------------------------------------------------------------------- No: #hide, because bits of this module are exposed by the stm package.--- However, we don't want this module to be the home location for the--- bits it exports, we'd rather have Control.Concurrent and the other--- higher level modules be the home.  Hence: #not-home--module GHC.Conc-        ( ThreadId(..)--        -- * Forking and suchlike-        , forkIO-        , forkIOWithUnmask-        , forkOn-        , forkOnWithUnmask-        , numCapabilities-        , getNumCapabilities-        , setNumCapabilities-        , getNumProcessors-        , numSparks-        , childHandler-        , myThreadId-        , killThread-        , throwTo-        , par-        , pseq-        , runSparks-        , yield-        , labelThread-        , mkWeakThreadId--        , ThreadStatus(..), BlockReason(..)-        , threadStatus-        , threadCapability--        -- * Waiting-        , threadDelay-        , registerDelay-        , threadWaitRead-        , threadWaitWrite-        , threadWaitReadSTM-        , threadWaitWriteSTM-        , closeFdWith--        -- * TVars-        , STM(..)-        , atomically-        , retry-        , orElse-        , throwSTM-        , catchSTM-        , alwaysSucceeds-        , always-        , TVar(..)-        , newTVar-        , newTVarIO-        , readTVar-        , readTVarIO-        , writeTVar-        , unsafeIOToSTM--        -- * Miscellaneous-        , withMVar-#ifdef mingw32_HOST_OS-        , asyncRead-        , asyncWrite-        , asyncDoProc--        , asyncReadBA-        , asyncWriteBA-#endif--#ifndef mingw32_HOST_OS-        , Signal, HandlerFun, setHandler, runHandlers-#endif--        , ensureIOManagerIsRunning-        , ioManagerCapabilitiesChanged--#ifdef mingw32_HOST_OS-        , ConsoleEvent(..)-        , win32ConsoleHandler-        , toWin32ConsoleEvent-#endif-        , setUncaughtExceptionHandler-        , getUncaughtExceptionHandler--        , reportError, reportStackOverflow-        ) where--import GHC.Conc.IO-import GHC.Conc.Sync--#ifndef mingw32_HOST_OS-import GHC.Conc.Signal-#endif--\end{code}
GHC/Conc/Signal.hs view
@@ -11,7 +11,6 @@  import Control.Concurrent.MVar (MVar, newMVar, withMVar) import Data.Dynamic (Dynamic)-import Data.Maybe (Maybe(..)) import Foreign.C.Types (CInt) import Foreign.ForeignPtr (ForeignPtr, newForeignPtr) import Foreign.StablePtr (castPtrToStablePtr, castStablePtrToPtr,
+ GHC/Conc/Sync.hs view
@@ -0,0 +1,897 @@+{-# LANGUAGE Unsafe #-}+{-# LANGUAGE CPP+           , NoImplicitPrelude+           , BangPatterns+           , MagicHash+           , UnboxedTuples+           , UnliftedFFITypes+           , DeriveDataTypeable+           , StandaloneDeriving+           , RankNTypes+  #-}+{-# OPTIONS_GHC -fno-warn-missing-signatures #-}+{-# OPTIONS_HADDOCK not-home #-}++-----------------------------------------------------------------------------+-- |+-- Module      :  GHC.Conc.Sync+-- Copyright   :  (c) The University of Glasgow, 1994-2002+-- License     :  see libraries/base/LICENSE+--+-- Maintainer  :  cvs-ghc@haskell.org+-- Stability   :  internal+-- Portability :  non-portable (GHC extensions)+--+-- Basic concurrency stuff.+--+-----------------------------------------------------------------------------++-- No: #hide, because bits of this module are exposed by the stm package.+-- However, we don't want this module to be the home location for the+-- bits it exports, we'd rather have Control.Concurrent and the other+-- higher level modules be the home.  Hence:++-- #not-home+module GHC.Conc.Sync+        ( ThreadId(..)++        -- * Forking and suchlike+        , forkIO+        , forkIOWithUnmask+        , forkOn+        , forkOnWithUnmask+        , numCapabilities+        , getNumCapabilities+        , setNumCapabilities+        , getNumProcessors+        , numSparks+        , childHandler+        , myThreadId+        , killThread+        , throwTo+        , par+        , pseq+        , runSparks+        , yield+        , labelThread+        , mkWeakThreadId++        , ThreadStatus(..), BlockReason(..)+        , threadStatus+        , threadCapability++        -- * Allocation counter and quota+        , setAllocationCounter+        , getAllocationCounter+        , enableAllocationLimit+        , disableAllocationLimit++        -- * TVars+        , STM(..)+        , atomically+        , retry+        , orElse+        , throwSTM+        , catchSTM+        , alwaysSucceeds+        , always+        , TVar(..)+        , newTVar+        , newTVarIO+        , readTVar+        , readTVarIO+        , writeTVar+        , unsafeIOToSTM++        -- * Miscellaneous+        , withMVar+        , modifyMVar_++        , setUncaughtExceptionHandler+        , getUncaughtExceptionHandler++        , reportError, reportStackOverflow++        , sharedCAF+        ) where++import Foreign+import Foreign.C++#ifndef mingw32_HOST_OS+import Data.Dynamic+#else+import Data.Typeable+#endif+import Data.Maybe++import GHC.Base+import {-# SOURCE #-} GHC.IO.Handle ( hFlush )+import {-# SOURCE #-} GHC.IO.Handle.FD ( stdout )+import GHC.IO+import GHC.IO.Encoding.UTF8+import GHC.IO.Exception+import GHC.Exception+import qualified GHC.Foreign+import GHC.IORef+import GHC.MVar+import GHC.Ptr+import GHC.Real         ( fromIntegral )+import GHC.Show         ( Show(..), showString )+import GHC.Weak++infixr 0 `par`, `pseq`++-----------------------------------------------------------------------------+-- 'ThreadId', 'par', and 'fork'+-----------------------------------------------------------------------------++data ThreadId = ThreadId ThreadId# deriving( Typeable )+-- ToDo: data ThreadId = ThreadId (Weak ThreadId#)+-- But since ThreadId# is unlifted, the Weak type must use open+-- type variables.+{- ^+A 'ThreadId' is an abstract type representing a handle to a thread.+'ThreadId' is an instance of 'Eq', 'Ord' and 'Show', where+the 'Ord' instance implements an arbitrary total ordering over+'ThreadId's. The 'Show' instance lets you convert an arbitrary-valued+'ThreadId' to string form; showing a 'ThreadId' value is occasionally+useful when debugging or diagnosing the behaviour of a concurrent+program.++/Note/: in GHC, if you have a 'ThreadId', you essentially have+a pointer to the thread itself.  This means the thread itself can\'t be+garbage collected until you drop the 'ThreadId'.+This misfeature will hopefully be corrected at a later date.++-}++instance Show ThreadId where+   showsPrec d t =+        showString "ThreadId " .+        showsPrec d (getThreadId (id2TSO t))++foreign import ccall unsafe "rts_getThreadId" getThreadId :: ThreadId# -> CInt++id2TSO :: ThreadId -> ThreadId#+id2TSO (ThreadId t) = t++foreign import ccall unsafe "cmp_thread" cmp_thread :: ThreadId# -> ThreadId# -> CInt+-- Returns -1, 0, 1++cmpThread :: ThreadId -> ThreadId -> Ordering+cmpThread t1 t2 =+   case cmp_thread (id2TSO t1) (id2TSO t2) of+      -1 -> LT+      0  -> EQ+      _  -> GT -- must be 1++instance Eq ThreadId where+   t1 == t2 =+      case t1 `cmpThread` t2 of+         EQ -> True+         _  -> False++instance Ord ThreadId where+   compare = cmpThread++-- | Every thread has an allocation counter that tracks how much+-- memory has been allocated by the thread.  The counter is+-- initialized to zero, and 'setAllocationCounter' sets the current+-- value.  The allocation counter counts *down*, so in the absence of+-- a call to 'setAllocationCounter' its value is the negation of the+-- number of bytes of memory allocated by the thread.+--+-- There are two things that you can do with this counter:+--+-- * Use it as a simple profiling mechanism, with+--   'getAllocationCounter'.+--+-- * Use it as a resource limit.  See 'enableAllocationLimit'.+--+-- Allocation accounting is accurate only to about 4Kbytes.+--+-- @since 4.8.0.0+setAllocationCounter :: Int64 -> IO ()+setAllocationCounter i = do+  ThreadId t <- myThreadId+  rts_setThreadAllocationCounter t i++-- | Return the current value of the allocation counter for the+-- current thread.+--+-- @since 4.8.0.0+getAllocationCounter :: IO Int64+getAllocationCounter = do+  ThreadId t <- myThreadId+  rts_getThreadAllocationCounter t++-- | Enables the allocation counter to be treated as a limit for the+-- current thread.  When the allocation limit is enabled, if the+-- allocation counter counts down below zero, the thread will be sent+-- the 'AllocationLimitExceeded' asynchronous exception.  When this+-- happens, the counter is reinitialised (by default+-- to 100K, but tunable with the @+RTS -xq@ option) so that it can handle+-- the exception and perform any necessary clean up.  If it exhausts+-- this additional allowance, another 'AllocationLimitExceeded' exception+-- is sent, and so forth.+--+-- Note that memory allocation is unrelated to /live memory/, also+-- known as /heap residency/.  A thread can allocate a large amount of+-- memory and retain anything between none and all of it.  It is+-- better to think of the allocation limit as a limit on+-- /CPU time/, rather than a limit on memory.+--+-- Compared to using timeouts, allocation limits don't count time+-- spent blocked or in foreign calls.+--+-- @since 4.8.0.0+enableAllocationLimit :: IO ()+enableAllocationLimit = do+  ThreadId t <- myThreadId+  rts_enableThreadAllocationLimit t++-- | Disable allocation limit processing for the current thread.+--+-- @since 4.8.0.0+disableAllocationLimit :: IO ()+disableAllocationLimit = do+  ThreadId t <- myThreadId+  rts_disableThreadAllocationLimit t++-- We cannot do these operations safely on another thread, because on+-- a 32-bit machine we cannot do atomic operations on a 64-bit value.+-- Therefore, we only expose APIs that allow getting and setting the+-- limit of the current thread.+foreign import ccall unsafe "rts_setThreadAllocationCounter"+  rts_setThreadAllocationCounter :: ThreadId# -> Int64 -> IO ()++foreign import ccall unsafe "rts_getThreadAllocationCounter"+  rts_getThreadAllocationCounter :: ThreadId# -> IO Int64++foreign import ccall unsafe "rts_enableThreadAllocationLimit"+  rts_enableThreadAllocationLimit :: ThreadId# -> IO ()++foreign import ccall unsafe "rts_disableThreadAllocationLimit"+  rts_disableThreadAllocationLimit :: ThreadId# -> IO ()++{- |+Creates a new thread to run the 'IO' computation passed as the+first argument, and returns the 'ThreadId' of the newly created+thread.++The new thread will be a lightweight, /unbound/ thread.  Foreign calls+made by this thread are not guaranteed to be made by any particular OS+thread; if you need foreign calls to be made by a particular OS+thread, then use 'Control.Concurrent.forkOS' instead.++The new thread inherits the /masked/ state of the parent (see+'Control.Exception.mask').++The newly created thread has an exception handler that discards the+exceptions 'BlockedIndefinitelyOnMVar', 'BlockedIndefinitelyOnSTM', and+'ThreadKilled', and passes all other exceptions to the uncaught+exception handler.+-}+forkIO :: IO () -> IO ThreadId+forkIO action = IO $ \ s ->+   case (fork# action_plus s) of (# s1, tid #) -> (# s1, ThreadId tid #)+ where+  action_plus = catchException action childHandler++-- | Like 'forkIO', but the child thread is passed a function that can+-- be used to unmask asynchronous exceptions.  This function is+-- typically used in the following way+--+-- >  ... mask_ $ forkIOWithUnmask $ \unmask ->+-- >                 catch (unmask ...) handler+--+-- so that the exception handler in the child thread is established+-- with asynchronous exceptions masked, meanwhile the main body of+-- the child thread is executed in the unmasked state.+--+-- Note that the unmask function passed to the child thread should+-- only be used in that thread; the behaviour is undefined if it is+-- invoked in a different thread.+--+-- @since 4.4.0.0+forkIOWithUnmask :: ((forall a . IO a -> IO a) -> IO ()) -> IO ThreadId+forkIOWithUnmask io = forkIO (io unsafeUnmask)++{- |+Like 'forkIO', but lets you specify on which capability the thread+should run.  Unlike a `forkIO` thread, a thread created by `forkOn`+will stay on the same capability for its entire lifetime (`forkIO`+threads can migrate between capabilities according to the scheduling+policy).  `forkOn` is useful for overriding the scheduling policy when+you know in advance how best to distribute the threads.++The `Int` argument specifies a /capability number/ (see+'getNumCapabilities').  Typically capabilities correspond to physical+processors, but the exact behaviour is implementation-dependent.  The+value passed to 'forkOn' is interpreted modulo the total number of+capabilities as returned by 'getNumCapabilities'.++GHC note: the number of capabilities is specified by the @+RTS -N@+option when the program is started.  Capabilities can be fixed to+actual processor cores with @+RTS -qa@ if the underlying operating+system supports that, although in practice this is usually unnecessary+(and may actually degrade performance in some cases - experimentation+is recommended).++@since 4.4.0.0+-}+forkOn :: Int -> IO () -> IO ThreadId+forkOn (I# cpu) action = IO $ \ s ->+   case (forkOn# cpu action_plus s) of (# s1, tid #) -> (# s1, ThreadId tid #)+ where+  action_plus = catchException action childHandler++-- | Like 'forkIOWithUnmask', but the child thread is pinned to the+-- given CPU, as with 'forkOn'.+--+-- @since 4.4.0.0+forkOnWithUnmask :: Int -> ((forall a . IO a -> IO a) -> IO ()) -> IO ThreadId+forkOnWithUnmask cpu io = forkOn cpu (io unsafeUnmask)++-- | the value passed to the @+RTS -N@ flag.  This is the number of+-- Haskell threads that can run truly simultaneously at any given+-- time, and is typically set to the number of physical processor cores on+-- the machine.+--+-- Strictly speaking it is better to use 'getNumCapabilities', because+-- the number of capabilities might vary at runtime.+--+numCapabilities :: Int+numCapabilities = unsafePerformIO $ getNumCapabilities++{- |+Returns the number of Haskell threads that can run truly+simultaneously (on separate physical processors) at any given time.  To change+this value, use 'setNumCapabilities'.++@since 4.4.0.0+-}+getNumCapabilities :: IO Int+getNumCapabilities = do+   n <- peek enabled_capabilities+   return (fromIntegral n)++{- |+Set the number of Haskell threads that can run truly simultaneously+(on separate physical processors) at any given time.  The number+passed to `forkOn` is interpreted modulo this value.  The initial+value is given by the @+RTS -N@ runtime flag.++This is also the number of threads that will participate in parallel+garbage collection.  It is strongly recommended that the number of+capabilities is not set larger than the number of physical processor+cores, and it may often be beneficial to leave one or more cores free+to avoid contention with other processes in the machine.++@since 4.5.0.0+-}+setNumCapabilities :: Int -> IO ()+setNumCapabilities i = c_setNumCapabilities (fromIntegral i)++foreign import ccall safe "setNumCapabilities"+  c_setNumCapabilities :: CUInt -> IO ()++-- | Returns the number of CPUs that the machine has+--+-- @since 4.5.0.0+getNumProcessors :: IO Int+getNumProcessors = fmap fromIntegral c_getNumberOfProcessors++foreign import ccall unsafe "getNumberOfProcessors"+  c_getNumberOfProcessors :: IO CUInt++-- | Returns the number of sparks currently in the local spark pool+numSparks :: IO Int+numSparks = IO $ \s -> case numSparks# s of (# s', n #) -> (# s', I# n #)++foreign import ccall "&enabled_capabilities" enabled_capabilities :: Ptr CInt++childHandler :: SomeException -> IO ()+childHandler err = catchException (real_handler err) childHandler++real_handler :: SomeException -> IO ()+real_handler se+  | Just BlockedIndefinitelyOnMVar <- fromException se  =  return ()+  | Just BlockedIndefinitelyOnSTM  <- fromException se  =  return ()+  | Just ThreadKilled              <- fromException se  =  return ()+  | Just StackOverflow             <- fromException se  =  reportStackOverflow+  | otherwise                                           =  reportError se++{- | 'killThread' raises the 'ThreadKilled' exception in the given+thread (GHC only).++> killThread tid = throwTo tid ThreadKilled++-}+killThread :: ThreadId -> IO ()+killThread tid = throwTo tid ThreadKilled++{- | 'throwTo' raises an arbitrary exception in the target thread (GHC only).++Exception delivery synchronizes between the source and target thread:+'throwTo' does not return until the exception has been raised in the+target thread. The calling thread can thus be certain that the target+thread has received the exception.  Exception delivery is also atomic+with respect to other exceptions. Atomicity is a useful property to have+when dealing with race conditions: e.g. if there are two threads that+can kill each other, it is guaranteed that only one of the threads+will get to kill the other.++Whatever work the target thread was doing when the exception was+raised is not lost: the computation is suspended until required by+another thread.++If the target thread is currently making a foreign call, then the+exception will not be raised (and hence 'throwTo' will not return)+until the call has completed.  This is the case regardless of whether+the call is inside a 'mask' or not.  However, in GHC a foreign call+can be annotated as @interruptible@, in which case a 'throwTo' will+cause the RTS to attempt to cause the call to return; see the GHC+documentation for more details.++Important note: the behaviour of 'throwTo' differs from that described in+the paper \"Asynchronous exceptions in Haskell\"+(<http://research.microsoft.com/~simonpj/Papers/asynch-exns.htm>).+In the paper, 'throwTo' is non-blocking; but the library implementation adopts+a more synchronous design in which 'throwTo' does not return until the exception+is received by the target thread.  The trade-off is discussed in Section 9 of the paper.+Like any blocking operation, 'throwTo' is therefore interruptible (see Section 5.3 of+the paper).  Unlike other interruptible operations, however, 'throwTo'+is /always/ interruptible, even if it does not actually block.++There is no guarantee that the exception will be delivered promptly,+although the runtime will endeavour to ensure that arbitrary+delays don't occur.  In GHC, an exception can only be raised when a+thread reaches a /safe point/, where a safe point is where memory+allocation occurs.  Some loops do not perform any memory allocation+inside the loop and therefore cannot be interrupted by a 'throwTo'.++If the target of 'throwTo' is the calling thread, then the behaviour+is the same as 'Control.Exception.throwIO', except that the exception+is thrown as an asynchronous exception.  This means that if there is+an enclosing pure computation, which would be the case if the current+IO operation is inside 'unsafePerformIO' or 'unsafeInterleaveIO', that+computation is not permanently replaced by the exception, but is+suspended as if it had received an asynchronous exception.++Note that if 'throwTo' is called with the current thread as the+target, the exception will be thrown even if the thread is currently+inside 'mask' or 'uninterruptibleMask'.+  -}+throwTo :: Exception e => ThreadId -> e -> IO ()+throwTo (ThreadId tid) ex = IO $ \ s ->+   case (killThread# tid (toException ex) s) of s1 -> (# s1, () #)++-- | Returns the 'ThreadId' of the calling thread (GHC only).+myThreadId :: IO ThreadId+myThreadId = IO $ \s ->+   case (myThreadId# s) of (# s1, tid #) -> (# s1, ThreadId tid #)+++-- |The 'yield' action allows (forces, in a co-operative multitasking+-- implementation) a context-switch to any other currently runnable+-- threads (if any), and is occasionally useful when implementing+-- concurrency abstractions.+yield :: IO ()+yield = IO $ \s ->+   case (yield# s) of s1 -> (# s1, () #)++{- | 'labelThread' stores a string as identifier for this thread if+you built a RTS with debugging support. This identifier will be used in+the debugging output to make distinction of different threads easier+(otherwise you only have the thread state object\'s address in the heap).++Other applications like the graphical Concurrent Haskell Debugger+(<http://www.informatik.uni-kiel.de/~fhu/chd/>) may choose to overload+'labelThread' for their purposes as well.+-}++labelThread :: ThreadId -> String -> IO ()+labelThread (ThreadId t) str =+    GHC.Foreign.withCString utf8 str $ \(Ptr p) ->+    IO $ \ s ->+     case labelThread# t p s of s1 -> (# s1, () #)++--      Nota Bene: 'pseq' used to be 'seq'+--                 but 'seq' is now defined in PrelGHC+--+-- "pseq" is defined a bit weirdly (see below)+--+-- The reason for the strange "lazy" call is that+-- it fools the compiler into thinking that pseq  and par are non-strict in+-- their second argument (even if it inlines pseq at the call site).+-- If it thinks pseq is strict in "y", then it often evaluates+-- "y" before "x", which is totally wrong.++{-# INLINE pseq  #-}+pseq :: a -> b -> b+pseq  x y = x `seq` lazy y++{-# INLINE par  #-}+par :: a -> b -> b+par  x y = case (par# x) of { _ -> lazy y }++-- | Internal function used by the RTS to run sparks.+runSparks :: IO ()+runSparks = IO loop+  where loop s = case getSpark# s of+                   (# s', n, p #) ->+                      if isTrue# (n ==# 0#)+                      then (# s', () #)+                      else p `seq` loop s'++data BlockReason+  = BlockedOnMVar+        -- ^blocked on 'MVar'+  {- possibly (see 'threadstatus' below):+  | BlockedOnMVarRead+        -- ^blocked on reading an empty 'MVar'+  -}+  | BlockedOnBlackHole+        -- ^blocked on a computation in progress by another thread+  | BlockedOnException+        -- ^blocked in 'throwTo'+  | BlockedOnSTM+        -- ^blocked in 'retry' in an STM transaction+  | BlockedOnForeignCall+        -- ^currently in a foreign call+  | BlockedOnOther+        -- ^blocked on some other resource.  Without @-threaded@,+        -- I\/O and 'threadDelay' show up as 'BlockedOnOther', with @-threaded@+        -- they show up as 'BlockedOnMVar'.+  deriving (Eq,Ord,Show)++-- | The current status of a thread+data ThreadStatus+  = ThreadRunning+        -- ^the thread is currently runnable or running+  | ThreadFinished+        -- ^the thread has finished+  | ThreadBlocked  BlockReason+        -- ^the thread is blocked on some resource+  | ThreadDied+        -- ^the thread received an uncaught exception+  deriving (Eq,Ord,Show)++threadStatus :: ThreadId -> IO ThreadStatus+threadStatus (ThreadId t) = IO $ \s ->+   case threadStatus# t s of+    (# s', stat, _cap, _locked #) -> (# s', mk_stat (I# stat) #)+   where+        -- NB. keep these in sync with includes/rts/Constants.h+     mk_stat 0  = ThreadRunning+     mk_stat 1  = ThreadBlocked BlockedOnMVar+     mk_stat 2  = ThreadBlocked BlockedOnBlackHole+     mk_stat 6  = ThreadBlocked BlockedOnSTM+     mk_stat 10 = ThreadBlocked BlockedOnForeignCall+     mk_stat 11 = ThreadBlocked BlockedOnForeignCall+     mk_stat 12 = ThreadBlocked BlockedOnException+     mk_stat 14 = ThreadBlocked BlockedOnMVar -- possibly: BlockedOnMVarRead+     -- NB. these are hardcoded in rts/PrimOps.cmm+     mk_stat 16 = ThreadFinished+     mk_stat 17 = ThreadDied+     mk_stat _  = ThreadBlocked BlockedOnOther++-- | returns the number of the capability on which the thread is currently+-- running, and a boolean indicating whether the thread is locked to+-- that capability or not.  A thread is locked to a capability if it+-- was created with @forkOn@.+--+-- @since 4.4.0.0+threadCapability :: ThreadId -> IO (Int, Bool)+threadCapability (ThreadId t) = IO $ \s ->+   case threadStatus# t s of+     (# s', _, cap#, locked# #) -> (# s', (I# cap#, isTrue# (locked# /=# 0#)) #)++-- | make a weak pointer to a 'ThreadId'.  It can be important to do+-- this if you want to hold a reference to a 'ThreadId' while still+-- allowing the thread to receive the @BlockedIndefinitely@ family of+-- exceptions (e.g. 'BlockedIndefinitelyOnMVar').  Holding a normal+-- 'ThreadId' reference will prevent the delivery of+-- @BlockedIndefinitely@ exceptions because the reference could be+-- used as the target of 'throwTo' at any time, which would unblock+-- the thread.+--+-- Holding a @Weak ThreadId@, on the other hand, will not prevent the+-- thread from receiving @BlockedIndefinitely@ exceptions.  It is+-- still possible to throw an exception to a @Weak ThreadId@, but the+-- caller must use @deRefWeak@ first to determine whether the thread+-- still exists.+--+-- @since 4.6.0.0+mkWeakThreadId :: ThreadId -> IO (Weak ThreadId)+mkWeakThreadId t@(ThreadId t#) = IO $ \s ->+   case mkWeakNoFinalizer# t# t s of+      (# s1, w #) -> (# s1, Weak w #)+++-----------------------------------------------------------------------------+-- Transactional heap operations+-----------------------------------------------------------------------------++-- TVars are shared memory locations which support atomic memory+-- transactions.++-- |A monad supporting atomic memory transactions.+newtype STM a = STM (State# RealWorld -> (# State# RealWorld, a #))+                deriving Typeable++unSTM :: STM a -> (State# RealWorld -> (# State# RealWorld, a #))+unSTM (STM a) = a++instance  Functor STM where+   fmap f x = x >>= (return . f)++instance Applicative STM where+  pure = return+  (<*>) = ap++instance  Monad STM  where+    {-# INLINE return #-}+    {-# INLINE (>>)   #-}+    {-# INLINE (>>=)  #-}+    m >> k      = thenSTM m k+    return x    = returnSTM x+    m >>= k     = bindSTM m k++bindSTM :: STM a -> (a -> STM b) -> STM b+bindSTM (STM m) k = STM ( \s ->+  case m s of+    (# new_s, a #) -> unSTM (k a) new_s+  )++thenSTM :: STM a -> STM b -> STM b+thenSTM (STM m) k = STM ( \s ->+  case m s of+    (# new_s, _ #) -> unSTM k new_s+  )++returnSTM :: a -> STM a+returnSTM x = STM (\s -> (# s, x #))++instance Alternative STM where+  empty = retry+  (<|>) = orElse++instance MonadPlus STM where+  mzero = empty+  mplus = (<|>)++-- | Unsafely performs IO in the STM monad.  Beware: this is a highly+-- dangerous thing to do.+--+--   * The STM implementation will often run transactions multiple+--     times, so you need to be prepared for this if your IO has any+--     side effects.+--+--   * The STM implementation will abort transactions that are known to+--     be invalid and need to be restarted.  This may happen in the middle+--     of `unsafeIOToSTM`, so make sure you don't acquire any resources+--     that need releasing (exception handlers are ignored when aborting+--     the transaction).  That includes doing any IO using Handles, for+--     example.  Getting this wrong will probably lead to random deadlocks.+--+--   * The transaction may have seen an inconsistent view of memory when+--     the IO runs.  Invariants that you expect to be true throughout+--     your program may not be true inside a transaction, due to the+--     way transactions are implemented.  Normally this wouldn't be visible+--     to the programmer, but using `unsafeIOToSTM` can expose it.+--+unsafeIOToSTM :: IO a -> STM a+unsafeIOToSTM (IO m) = STM m++-- |Perform a series of STM actions atomically.+--+-- You cannot use 'atomically' inside an 'unsafePerformIO' or 'unsafeInterleaveIO'.+-- Any attempt to do so will result in a runtime error.  (Reason: allowing+-- this would effectively allow a transaction inside a transaction, depending+-- on exactly when the thunk is evaluated.)+--+-- However, see 'newTVarIO', which can be called inside 'unsafePerformIO',+-- and which allows top-level TVars to be allocated.++atomically :: STM a -> IO a+atomically (STM m) = IO (\s -> (atomically# m) s )++-- |Retry execution of the current memory transaction because it has seen+-- values in TVars which mean that it should not continue (e.g. the TVars+-- represent a shared buffer that is now empty).  The implementation may+-- block the thread until one of the TVars that it has read from has been+-- udpated. (GHC only)+retry :: STM a+retry = STM $ \s# -> retry# s#++-- |Compose two alternative STM actions (GHC only).  If the first action+-- completes without retrying then it forms the result of the orElse.+-- Otherwise, if the first action retries, then the second action is+-- tried in its place.  If both actions retry then the orElse as a+-- whole retries.+orElse :: STM a -> STM a -> STM a+orElse (STM m) e = STM $ \s -> catchRetry# m (unSTM e) s++-- | A variant of 'throw' that can only be used within the 'STM' monad.+--+-- Throwing an exception in @STM@ aborts the transaction and propagates the+-- exception.+--+-- Although 'throwSTM' has a type that is an instance of the type of 'throw', the+-- two functions are subtly different:+--+-- > throw e    `seq` x  ===> throw e+-- > throwSTM e `seq` x  ===> x+--+-- The first example will cause the exception @e@ to be raised,+-- whereas the second one won\'t.  In fact, 'throwSTM' will only cause+-- an exception to be raised when it is used within the 'STM' monad.+-- The 'throwSTM' variant should be used in preference to 'throw' to+-- raise an exception within the 'STM' monad because it guarantees+-- ordering with respect to other 'STM' operations, whereas 'throw'+-- does not.+throwSTM :: Exception e => e -> STM a+throwSTM e = STM $ raiseIO# (toException e)++-- |Exception handling within STM actions.+catchSTM :: Exception e => STM a -> (e -> STM a) -> STM a+catchSTM (STM m) handler = STM $ catchSTM# m handler'+    where+      handler' e = case fromException e of+                     Just e' -> unSTM (handler e')+                     Nothing -> raiseIO# e++-- | Low-level primitive on which always and alwaysSucceeds are built.+-- checkInv differs form these in that (i) the invariant is not+-- checked when checkInv is called, only at the end of this and+-- subsequent transcations, (ii) the invariant failure is indicated+-- by raising an exception.+checkInv :: STM a -> STM ()+checkInv (STM m) = STM (\s -> (check# m) s)++-- | alwaysSucceeds adds a new invariant that must be true when passed+-- to alwaysSucceeds, at the end of the current transaction, and at+-- the end of every subsequent transaction.  If it fails at any+-- of those points then the transaction violating it is aborted+-- and the exception raised by the invariant is propagated.+alwaysSucceeds :: STM a -> STM ()+alwaysSucceeds i = do ( i >> retry ) `orElse` ( return () )+                      checkInv i++-- | always is a variant of alwaysSucceeds in which the invariant is+-- expressed as an STM Bool action that must return True.  Returning+-- False or raising an exception are both treated as invariant failures.+always :: STM Bool -> STM ()+always i = alwaysSucceeds ( do v <- i+                               if (v) then return () else ( error "Transactional invariant violation" ) )++-- |Shared memory locations that support atomic memory transactions.+data TVar a = TVar (TVar# RealWorld a)+              deriving Typeable++instance Eq (TVar a) where+        (TVar tvar1#) == (TVar tvar2#) = isTrue# (sameTVar# tvar1# tvar2#)++-- |Create a new TVar holding a value supplied+newTVar :: a -> STM (TVar a)+newTVar val = STM $ \s1# ->+    case newTVar# val s1# of+         (# s2#, tvar# #) -> (# s2#, TVar tvar# #)++-- |@IO@ version of 'newTVar'.  This is useful for creating top-level+-- 'TVar's using 'System.IO.Unsafe.unsafePerformIO', because using+-- 'atomically' inside 'System.IO.Unsafe.unsafePerformIO' isn't+-- possible.+newTVarIO :: a -> IO (TVar a)+newTVarIO val = IO $ \s1# ->+    case newTVar# val s1# of+         (# s2#, tvar# #) -> (# s2#, TVar tvar# #)++-- |Return the current value stored in a TVar.+-- This is equivalent to+--+-- >  readTVarIO = atomically . readTVar+--+-- but works much faster, because it doesn't perform a complete+-- transaction, it just reads the current value of the 'TVar'.+readTVarIO :: TVar a -> IO a+readTVarIO (TVar tvar#) = IO $ \s# -> readTVarIO# tvar# s#++-- |Return the current value stored in a TVar+readTVar :: TVar a -> STM a+readTVar (TVar tvar#) = STM $ \s# -> readTVar# tvar# s#++-- |Write the supplied value into a TVar+writeTVar :: TVar a -> a -> STM ()+writeTVar (TVar tvar#) val = STM $ \s1# ->+    case writeTVar# tvar# val s1# of+         s2# -> (# s2#, () #)++-----------------------------------------------------------------------------+-- MVar utilities+-----------------------------------------------------------------------------++withMVar :: MVar a -> (a -> IO b) -> IO b+withMVar m io =+  mask $ \restore -> do+    a <- takeMVar m+    b <- catchAny (restore (io a))+            (\e -> do putMVar m a; throw e)+    putMVar m a+    return b++modifyMVar_ :: MVar a -> (a -> IO a) -> IO ()+modifyMVar_ m io =+  mask $ \restore -> do+    a <- takeMVar m+    a' <- catchAny (restore (io a))+            (\e -> do putMVar m a; throw e)+    putMVar m a'+    return ()++-----------------------------------------------------------------------------+-- Thread waiting+-----------------------------------------------------------------------------++-- Machinery needed to ensureb that we only have one copy of certain+-- CAFs in this module even when the base package is present twice, as+-- it is when base is dynamically loaded into GHCi.  The RTS keeps+-- track of the single true value of the CAF, so even when the CAFs in+-- the dynamically-loaded base package are reverted, nothing bad+-- happens.+--+sharedCAF :: a -> (Ptr a -> IO (Ptr a)) -> IO a+sharedCAF a get_or_set =+   mask_ $ do+     stable_ref <- newStablePtr a+     let ref = castPtr (castStablePtrToPtr stable_ref)+     ref2 <- get_or_set ref+     if ref==ref2+        then return a+        else do freeStablePtr stable_ref+                deRefStablePtr (castPtrToStablePtr (castPtr ref2))++reportStackOverflow :: IO ()+reportStackOverflow = do+     ThreadId tid <- myThreadId+     callStackOverflowHook tid++reportError :: SomeException -> IO ()+reportError ex = do+   handler <- getUncaughtExceptionHandler+   handler ex++-- SUP: Are the hooks allowed to re-enter Haskell land?  If so, remove+-- the unsafe below.+foreign import ccall unsafe "stackOverflow"+        callStackOverflowHook :: ThreadId# -> IO ()++{-# NOINLINE uncaughtExceptionHandler #-}+uncaughtExceptionHandler :: IORef (SomeException -> IO ())+uncaughtExceptionHandler = unsafePerformIO (newIORef defaultHandler)+   where+      defaultHandler :: SomeException -> IO ()+      defaultHandler se@(SomeException ex) = do+         (hFlush stdout) `catchAny` (\ _ -> return ())+         let msg = case cast ex of+               Just Deadlock -> "no threads to run:  infinite loop or deadlock?"+               _ -> case cast ex of+                    Just (ErrorCall s) -> s+                    _                  -> showsPrec 0 se ""+         withCString "%s" $ \cfmt ->+          withCString msg $ \cmsg ->+            errorBelch cfmt cmsg++-- don't use errorBelch() directly, because we cannot call varargs functions+-- using the FFI.+foreign import ccall unsafe "HsBase.h errorBelch2"+   errorBelch :: CString -> CString -> IO ()++setUncaughtExceptionHandler :: (SomeException -> IO ()) -> IO ()+setUncaughtExceptionHandler = writeIORef uncaughtExceptionHandler++getUncaughtExceptionHandler :: IO (SomeException -> IO ())+getUncaughtExceptionHandler = readIORef uncaughtExceptionHandler
− GHC/Conc/Sync.lhs
@@ -1,817 +0,0 @@-\begin{code}-{-# LANGUAGE Unsafe #-}-{-# LANGUAGE CPP-           , NoImplicitPrelude-           , BangPatterns-           , MagicHash-           , UnboxedTuples-           , UnliftedFFITypes-           , DeriveDataTypeable-           , StandaloneDeriving-           , RankNTypes-  #-}-{-# OPTIONS_GHC -fno-warn-missing-signatures #-}-{-# OPTIONS_HADDOCK not-home #-}---------------------------------------------------------------------------------- |--- Module      :  GHC.Conc.Sync--- Copyright   :  (c) The University of Glasgow, 1994-2002--- License     :  see libraries/base/LICENSE------ Maintainer  :  cvs-ghc@haskell.org--- Stability   :  internal--- Portability :  non-portable (GHC extensions)------ Basic concurrency stuff.------------------------------------------------------------------------------------- No: #hide, because bits of this module are exposed by the stm package.--- However, we don't want this module to be the home location for the--- bits it exports, we'd rather have Control.Concurrent and the other--- higher level modules be the home.  Hence:---- #not-home-module GHC.Conc.Sync-        ( ThreadId(..)--        -- * Forking and suchlike-        , forkIO-        , forkIOWithUnmask-        , forkOn-        , forkOnWithUnmask-        , numCapabilities-        , getNumCapabilities-        , setNumCapabilities-        , getNumProcessors-        , numSparks-        , childHandler-        , myThreadId-        , killThread-        , throwTo-        , par-        , pseq-        , runSparks-        , yield-        , labelThread-        , mkWeakThreadId--        , ThreadStatus(..), BlockReason(..)-        , threadStatus-        , threadCapability--        -- * TVars-        , STM(..)-        , atomically-        , retry-        , orElse-        , throwSTM-        , catchSTM-        , alwaysSucceeds-        , always-        , TVar(..)-        , newTVar-        , newTVarIO-        , readTVar-        , readTVarIO-        , writeTVar-        , unsafeIOToSTM--        -- * Miscellaneous-        , withMVar-        , modifyMVar_--        , setUncaughtExceptionHandler-        , getUncaughtExceptionHandler--        , reportError, reportStackOverflow--        , sharedCAF-        ) where--import Foreign-import Foreign.C--#ifdef mingw32_HOST_OS-import Data.Typeable-#endif--#ifndef mingw32_HOST_OS-import Data.Dynamic-#endif-import Control.Monad-import Data.Maybe--import GHC.Base-import {-# SOURCE #-} GHC.IO.Handle ( hFlush )-import {-# SOURCE #-} GHC.IO.Handle.FD ( stdout )-import GHC.IO-import GHC.IO.Encoding.UTF8-import GHC.IO.Exception-import GHC.Exception-import qualified GHC.Foreign-import GHC.IORef-import GHC.MVar-import GHC.Ptr-import GHC.Real         ( fromIntegral )-import GHC.Show         ( Show(..), showString )-import GHC.Weak--infixr 0 `par`, `pseq`-\end{code}--%************************************************************************-%*                                                                      *-\subsection{@ThreadId@, @par@, and @fork@}-%*                                                                      *-%************************************************************************--\begin{code}-data ThreadId = ThreadId ThreadId# deriving( Typeable )--- ToDo: data ThreadId = ThreadId (Weak ThreadId#)--- But since ThreadId# is unlifted, the Weak type must use open--- type variables.-{- ^-A 'ThreadId' is an abstract type representing a handle to a thread.-'ThreadId' is an instance of 'Eq', 'Ord' and 'Show', where-the 'Ord' instance implements an arbitrary total ordering over-'ThreadId's. The 'Show' instance lets you convert an arbitrary-valued-'ThreadId' to string form; showing a 'ThreadId' value is occasionally-useful when debugging or diagnosing the behaviour of a concurrent-program.--/Note/: in GHC, if you have a 'ThreadId', you essentially have-a pointer to the thread itself.  This means the thread itself can\'t be-garbage collected until you drop the 'ThreadId'.-This misfeature will hopefully be corrected at a later date.---}--instance Show ThreadId where-   showsPrec d t =-        showString "ThreadId " .-        showsPrec d (getThreadId (id2TSO t))--foreign import ccall unsafe "rts_getThreadId" getThreadId :: ThreadId# -> CInt--id2TSO :: ThreadId -> ThreadId#-id2TSO (ThreadId t) = t--foreign import ccall unsafe "cmp_thread" cmp_thread :: ThreadId# -> ThreadId# -> CInt--- Returns -1, 0, 1--cmpThread :: ThreadId -> ThreadId -> Ordering-cmpThread t1 t2 =-   case cmp_thread (id2TSO t1) (id2TSO t2) of-      -1 -> LT-      0  -> EQ-      _  -> GT -- must be 1--instance Eq ThreadId where-   t1 == t2 =-      case t1 `cmpThread` t2 of-         EQ -> True-         _  -> False--instance Ord ThreadId where-   compare = cmpThread--{- |-Sparks off a new thread to run the 'IO' computation passed as the-first argument, and returns the 'ThreadId' of the newly created-thread.--The new thread will be a lightweight thread; if you want to use a foreign-library that uses thread-local storage, use 'Control.Concurrent.forkOS' instead.--GHC note: the new thread inherits the /masked/ state of the parent-(see 'Control.Exception.mask').--The newly created thread has an exception handler that discards the-exceptions 'BlockedIndefinitelyOnMVar', 'BlockedIndefinitelyOnSTM', and-'ThreadKilled', and passes all other exceptions to the uncaught-exception handler.--}-forkIO :: IO () -> IO ThreadId-forkIO action = IO $ \ s ->-   case (fork# action_plus s) of (# s1, tid #) -> (# s1, ThreadId tid #)- where-  action_plus = catchException action childHandler---- | Like 'forkIO', but the child thread is passed a function that can--- be used to unmask asynchronous exceptions.  This function is--- typically used in the following way------ >  ... mask_ $ forkIOWithUnmask $ \unmask ->--- >                 catch (unmask ...) handler------ so that the exception handler in the child thread is established--- with asynchronous exceptions masked, meanwhile the main body of--- the child thread is executed in the unmasked state.------ Note that the unmask function passed to the child thread should--- only be used in that thread; the behaviour is undefined if it is--- invoked in a different thread.------ /Since: 4.4.0.0/-forkIOWithUnmask :: ((forall a . IO a -> IO a) -> IO ()) -> IO ThreadId-forkIOWithUnmask io = forkIO (io unsafeUnmask)--{- |-Like 'forkIO', but lets you specify on which processor the thread-should run.  Unlike a `forkIO` thread, a thread created by `forkOn`-will stay on the same processor for its entire lifetime (`forkIO`-threads can migrate between processors according to the scheduling-policy).  `forkOn` is useful for overriding the scheduling policy when-you know in advance how best to distribute the threads.--The `Int` argument specifies a /capability number/ (see-'getNumCapabilities').  Typically capabilities correspond to physical-processors, but the exact behaviour is implementation-dependent.  The-value passed to 'forkOn' is interpreted modulo the total number of-capabilities as returned by 'getNumCapabilities'.--GHC note: the number of capabilities is specified by the @+RTS -N@-option when the program is started.  Capabilities can be fixed to-actual processor cores with @+RTS -qa@ if the underlying operating-system supports that, although in practice this is usually unnecessary-(and may actually degrade performance in some cases - experimentation-is recommended).--/Since: 4.4.0.0/--}-forkOn :: Int -> IO () -> IO ThreadId-forkOn (I# cpu) action = IO $ \ s ->-   case (forkOn# cpu action_plus s) of (# s1, tid #) -> (# s1, ThreadId tid #)- where-  action_plus = catchException action childHandler---- | Like 'forkIOWithUnmask', but the child thread is pinned to the--- given CPU, as with 'forkOn'.------ /Since: 4.4.0.0/-forkOnWithUnmask :: Int -> ((forall a . IO a -> IO a) -> IO ()) -> IO ThreadId-forkOnWithUnmask cpu io = forkOn cpu (io unsafeUnmask)---- | the value passed to the @+RTS -N@ flag.  This is the number of--- Haskell threads that can run truly simultaneously at any given--- time, and is typically set to the number of physical processor cores on--- the machine.------ Strictly speaking it is better to use 'getNumCapabilities', because--- the number of capabilities might vary at runtime.----numCapabilities :: Int-numCapabilities = unsafePerformIO $ getNumCapabilities--{- |-Returns the number of Haskell threads that can run truly-simultaneously (on separate physical processors) at any given time.  To change-this value, use 'setNumCapabilities'.--/Since: 4.4.0.0/--}-getNumCapabilities :: IO Int-getNumCapabilities = do-   n <- peek enabled_capabilities-   return (fromIntegral n)--{- |-Set the number of Haskell threads that can run truly simultaneously-(on separate physical processors) at any given time.  The number-passed to `forkOn` is interpreted modulo this value.  The initial-value is given by the @+RTS -N@ runtime flag.--This is also the number of threads that will participate in parallel-garbage collection.  It is strongly recommended that the number of-capabilities is not set larger than the number of physical processor-cores, and it may often be beneficial to leave one or more cores free-to avoid contention with other processes in the machine.--/Since: 4.5.0.0/--}-setNumCapabilities :: Int -> IO ()-setNumCapabilities i = c_setNumCapabilities (fromIntegral i)--foreign import ccall safe "setNumCapabilities"-  c_setNumCapabilities :: CUInt -> IO ()---- | Returns the number of CPUs that the machine has------ /Since: 4.5.0.0/-getNumProcessors :: IO Int-getNumProcessors = fmap fromIntegral c_getNumberOfProcessors--foreign import ccall unsafe "getNumberOfProcessors"-  c_getNumberOfProcessors :: IO CUInt---- | Returns the number of sparks currently in the local spark pool-numSparks :: IO Int-numSparks = IO $ \s -> case numSparks# s of (# s', n #) -> (# s', I# n #)--foreign import ccall "&enabled_capabilities" enabled_capabilities :: Ptr CInt--childHandler :: SomeException -> IO ()-childHandler err = catchException (real_handler err) childHandler--real_handler :: SomeException -> IO ()-real_handler se-  | Just BlockedIndefinitelyOnMVar <- fromException se  =  return ()-  | Just BlockedIndefinitelyOnSTM  <- fromException se  =  return ()-  | Just ThreadKilled              <- fromException se  =  return ()-  | Just StackOverflow             <- fromException se  =  reportStackOverflow-  | otherwise                                           =  reportError se--{- | 'killThread' raises the 'ThreadKilled' exception in the given-thread (GHC only).--> killThread tid = throwTo tid ThreadKilled---}-killThread :: ThreadId -> IO ()-killThread tid = throwTo tid ThreadKilled--{- | 'throwTo' raises an arbitrary exception in the target thread (GHC only).--Exception delivery synchronizes between the source and target thread:-'throwTo' does not return until the exception has been raised in the-target thread. The calling thread can thus be certain that the target-thread has received the exception.  Exception delivery is also atomic-with respect to other exceptions. Atomicity is a useful property to have-when dealing with race conditions: e.g. if there are two threads that-can kill each other, it is guaranteed that only one of the threads-will get to kill the other.--Whatever work the target thread was doing when the exception was-raised is not lost: the computation is suspended until required by-another thread.--If the target thread is currently making a foreign call, then the-exception will not be raised (and hence 'throwTo' will not return)-until the call has completed.  This is the case regardless of whether-the call is inside a 'mask' or not.  However, in GHC a foreign call-can be annotated as @interruptible@, in which case a 'throwTo' will-cause the RTS to attempt to cause the call to return; see the GHC-documentation for more details.--Important note: the behaviour of 'throwTo' differs from that described in-the paper \"Asynchronous exceptions in Haskell\"-(<http://research.microsoft.com/~simonpj/Papers/asynch-exns.htm>).-In the paper, 'throwTo' is non-blocking; but the library implementation adopts-a more synchronous design in which 'throwTo' does not return until the exception-is received by the target thread.  The trade-off is discussed in Section 9 of the paper.-Like any blocking operation, 'throwTo' is therefore interruptible (see Section 5.3 of-the paper).  Unlike other interruptible operations, however, 'throwTo'-is /always/ interruptible, even if it does not actually block.--There is no guarantee that the exception will be delivered promptly,-although the runtime will endeavour to ensure that arbitrary-delays don't occur.  In GHC, an exception can only be raised when a-thread reaches a /safe point/, where a safe point is where memory-allocation occurs.  Some loops do not perform any memory allocation-inside the loop and therefore cannot be interrupted by a 'throwTo'.--If the target of 'throwTo' is the calling thread, then the behaviour-is the same as 'Control.Exception.throwIO', except that the exception-is thrown as an asynchronous exception.  This means that if there is-an enclosing pure computation, which would be the case if the current-IO operation is inside 'unsafePerformIO' or 'unsafeInterleaveIO', that-computation is not permanently replaced by the exception, but is-suspended as if it had received an asynchronous exception.--Note that if 'throwTo' is called with the current thread as the-target, the exception will be thrown even if the thread is currently-inside 'mask' or 'uninterruptibleMask'.-  -}-throwTo :: Exception e => ThreadId -> e -> IO ()-throwTo (ThreadId tid) ex = IO $ \ s ->-   case (killThread# tid (toException ex) s) of s1 -> (# s1, () #)---- | Returns the 'ThreadId' of the calling thread (GHC only).-myThreadId :: IO ThreadId-myThreadId = IO $ \s ->-   case (myThreadId# s) of (# s1, tid #) -> (# s1, ThreadId tid #)----- |The 'yield' action allows (forces, in a co-operative multitasking--- implementation) a context-switch to any other currently runnable--- threads (if any), and is occasionally useful when implementing--- concurrency abstractions.-yield :: IO ()-yield = IO $ \s ->-   case (yield# s) of s1 -> (# s1, () #)--{- | 'labelThread' stores a string as identifier for this thread if-you built a RTS with debugging support. This identifier will be used in-the debugging output to make distinction of different threads easier-(otherwise you only have the thread state object\'s address in the heap).--Other applications like the graphical Concurrent Haskell Debugger-(<http://www.informatik.uni-kiel.de/~fhu/chd/>) may choose to overload-'labelThread' for their purposes as well.--}--labelThread :: ThreadId -> String -> IO ()-labelThread (ThreadId t) str =-    GHC.Foreign.withCString utf8 str $ \(Ptr p) ->-    IO $ \ s ->-     case labelThread# t p s of s1 -> (# s1, () #)----      Nota Bene: 'pseq' used to be 'seq'---                 but 'seq' is now defined in PrelGHC------ "pseq" is defined a bit weirdly (see below)------ The reason for the strange "lazy" call is that--- it fools the compiler into thinking that pseq  and par are non-strict in--- their second argument (even if it inlines pseq at the call site).--- If it thinks pseq is strict in "y", then it often evaluates--- "y" before "x", which is totally wrong.--{-# INLINE pseq  #-}-pseq :: a -> b -> b-pseq  x y = x `seq` lazy y--{-# INLINE par  #-}-par :: a -> b -> b-par  x y = case (par# x) of { _ -> lazy y }---- | Internal function used by the RTS to run sparks.-runSparks :: IO ()-runSparks = IO loop-  where loop s = case getSpark# s of-                   (# s', n, p #) ->-                      if isTrue# (n ==# 0#)-                      then (# s', () #)-                      else p `seq` loop s'--data BlockReason-  = BlockedOnMVar-        -- ^blocked on on 'MVar'-  | BlockedOnBlackHole-        -- ^blocked on a computation in progress by another thread-  | BlockedOnException-        -- ^blocked in 'throwTo'-  | BlockedOnSTM-        -- ^blocked in 'retry' in an STM transaction-  | BlockedOnForeignCall-        -- ^currently in a foreign call-  | BlockedOnOther-        -- ^blocked on some other resource.  Without @-threaded@,-        -- I\/O and 'threadDelay' show up as 'BlockedOnOther', with @-threaded@-        -- they show up as 'BlockedOnMVar'.-  deriving (Eq,Ord,Show)---- | The current status of a thread-data ThreadStatus-  = ThreadRunning-        -- ^the thread is currently runnable or running-  | ThreadFinished-        -- ^the thread has finished-  | ThreadBlocked  BlockReason-        -- ^the thread is blocked on some resource-  | ThreadDied-        -- ^the thread received an uncaught exception-  deriving (Eq,Ord,Show)--threadStatus :: ThreadId -> IO ThreadStatus-threadStatus (ThreadId t) = IO $ \s ->-   case threadStatus# t s of-    (# s', stat, _cap, _locked #) -> (# s', mk_stat (I# stat) #)-   where-        -- NB. keep these in sync with includes/Constants.h-     mk_stat 0  = ThreadRunning-     mk_stat 1  = ThreadBlocked BlockedOnMVar-     mk_stat 2  = ThreadBlocked BlockedOnMVar -- XXX distinguish?-     mk_stat 3  = ThreadBlocked BlockedOnBlackHole-     mk_stat 7  = ThreadBlocked BlockedOnSTM-     mk_stat 11 = ThreadBlocked BlockedOnForeignCall-     mk_stat 12 = ThreadBlocked BlockedOnForeignCall-     mk_stat 13 = ThreadBlocked BlockedOnException-     -- NB. these are hardcoded in rts/PrimOps.cmm-     mk_stat 16 = ThreadFinished-     mk_stat 17 = ThreadDied-     mk_stat _  = ThreadBlocked BlockedOnOther---- | returns the number of the capability on which the thread is currently--- running, and a boolean indicating whether the thread is locked to--- that capability or not.  A thread is locked to a capability if it--- was created with @forkOn@.------ /Since: 4.4.0.0/-threadCapability :: ThreadId -> IO (Int, Bool)-threadCapability (ThreadId t) = IO $ \s ->-   case threadStatus# t s of-     (# s', _, cap#, locked# #) -> (# s', (I# cap#, isTrue# (locked# /=# 0#)) #)---- | make a weak pointer to a 'ThreadId'.  It can be important to do--- this if you want to hold a reference to a 'ThreadId' while still--- allowing the thread to receive the @BlockedIndefinitely@ family of--- exceptions (e.g. 'BlockedIndefinitelyOnMVar').  Holding a normal--- 'ThreadId' reference will prevent the delivery of--- @BlockedIndefinitely@ exceptions because the reference could be--- used as the target of 'throwTo' at any time, which would unblock--- the thread.------ Holding a @Weak ThreadId@, on the other hand, will not prevent the--- thread from receiving @BlockedIndefinitely@ exceptions.  It is--- still possible to throw an exception to a @Weak ThreadId@, but the--- caller must use @deRefWeak@ first to determine whether the thread--- still exists.------ /Since: 4.6.0.0/-mkWeakThreadId :: ThreadId -> IO (Weak ThreadId)-mkWeakThreadId t@(ThreadId t#) = IO $ \s ->-   case mkWeakNoFinalizer# t# t s of-      (# s1, w #) -> (# s1, Weak w #)-\end{code}---%************************************************************************-%*                                                                      *-\subsection[stm]{Transactional heap operations}-%*                                                                      *-%************************************************************************--TVars are shared memory locations which support atomic memory-transactions.--\begin{code}--- |A monad supporting atomic memory transactions.-newtype STM a = STM (State# RealWorld -> (# State# RealWorld, a #))-                deriving Typeable--unSTM :: STM a -> (State# RealWorld -> (# State# RealWorld, a #))-unSTM (STM a) = a--instance  Functor STM where-   fmap f x = x >>= (return . f)--instance  Monad STM  where-    {-# INLINE return #-}-    {-# INLINE (>>)   #-}-    {-# INLINE (>>=)  #-}-    m >> k      = thenSTM m k-    return x    = returnSTM x-    m >>= k     = bindSTM m k--bindSTM :: STM a -> (a -> STM b) -> STM b-bindSTM (STM m) k = STM ( \s ->-  case m s of-    (# new_s, a #) -> unSTM (k a) new_s-  )--thenSTM :: STM a -> STM b -> STM b-thenSTM (STM m) k = STM ( \s ->-  case m s of-    (# new_s, _ #) -> unSTM k new_s-  )--returnSTM :: a -> STM a-returnSTM x = STM (\s -> (# s, x #))--instance MonadPlus STM where-  mzero = retry-  mplus = orElse---- | Unsafely performs IO in the STM monad.  Beware: this is a highly--- dangerous thing to do.------   * The STM implementation will often run transactions multiple---     times, so you need to be prepared for this if your IO has any---     side effects.------   * The STM implementation will abort transactions that are known to---     be invalid and need to be restarted.  This may happen in the middle---     of `unsafeIOToSTM`, so make sure you don't acquire any resources---     that need releasing (exception handlers are ignored when aborting---     the transaction).  That includes doing any IO using Handles, for---     example.  Getting this wrong will probably lead to random deadlocks.------   * The transaction may have seen an inconsistent view of memory when---     the IO runs.  Invariants that you expect to be true throughout---     your program may not be true inside a transaction, due to the---     way transactions are implemented.  Normally this wouldn't be visible---     to the programmer, but using `unsafeIOToSTM` can expose it.----unsafeIOToSTM :: IO a -> STM a-unsafeIOToSTM (IO m) = STM m---- |Perform a series of STM actions atomically.------ You cannot use 'atomically' inside an 'unsafePerformIO' or 'unsafeInterleaveIO'.--- Any attempt to do so will result in a runtime error.  (Reason: allowing--- this would effectively allow a transaction inside a transaction, depending--- on exactly when the thunk is evaluated.)------ However, see 'newTVarIO', which can be called inside 'unsafePerformIO',--- and which allows top-level TVars to be allocated.--atomically :: STM a -> IO a-atomically (STM m) = IO (\s -> (atomically# m) s )---- |Retry execution of the current memory transaction because it has seen--- values in TVars which mean that it should not continue (e.g. the TVars--- represent a shared buffer that is now empty).  The implementation may--- block the thread until one of the TVars that it has read from has been--- udpated. (GHC only)-retry :: STM a-retry = STM $ \s# -> retry# s#---- |Compose two alternative STM actions (GHC only).  If the first action--- completes without retrying then it forms the result of the orElse.--- Otherwise, if the first action retries, then the second action is--- tried in its place.  If both actions retry then the orElse as a--- whole retries.-orElse :: STM a -> STM a -> STM a-orElse (STM m) e = STM $ \s -> catchRetry# m (unSTM e) s---- | A variant of 'throw' that can only be used within the 'STM' monad.------ Throwing an exception in @STM@ aborts the transaction and propagates the--- exception.------ Although 'throwSTM' has a type that is an instance of the type of 'throw', the--- two functions are subtly different:------ > throw e    `seq` x  ===> throw e--- > throwSTM e `seq` x  ===> x------ The first example will cause the exception @e@ to be raised,--- whereas the second one won\'t.  In fact, 'throwSTM' will only cause--- an exception to be raised when it is used within the 'STM' monad.--- The 'throwSTM' variant should be used in preference to 'throw' to--- raise an exception within the 'STM' monad because it guarantees--- ordering with respect to other 'STM' operations, whereas 'throw'--- does not.-throwSTM :: Exception e => e -> STM a-throwSTM e = STM $ raiseIO# (toException e)---- |Exception handling within STM actions.-catchSTM :: Exception e => STM a -> (e -> STM a) -> STM a-catchSTM (STM m) handler = STM $ catchSTM# m handler'-    where-      handler' e = case fromException e of-                     Just e' -> unSTM (handler e')-                     Nothing -> raiseIO# e---- | Low-level primitive on which always and alwaysSucceeds are built.--- checkInv differs form these in that (i) the invariant is not--- checked when checkInv is called, only at the end of this and--- subsequent transcations, (ii) the invariant failure is indicated--- by raising an exception.-checkInv :: STM a -> STM ()-checkInv (STM m) = STM (\s -> (check# m) s)---- | alwaysSucceeds adds a new invariant that must be true when passed--- to alwaysSucceeds, at the end of the current transaction, and at--- the end of every subsequent transaction.  If it fails at any--- of those points then the transaction violating it is aborted--- and the exception raised by the invariant is propagated.-alwaysSucceeds :: STM a -> STM ()-alwaysSucceeds i = do ( i >> retry ) `orElse` ( return () )-                      checkInv i---- | always is a variant of alwaysSucceeds in which the invariant is--- expressed as an STM Bool action that must return True.  Returning--- False or raising an exception are both treated as invariant failures.-always :: STM Bool -> STM ()-always i = alwaysSucceeds ( do v <- i-                               if (v) then return () else ( error "Transactional invariant violation" ) )---- |Shared memory locations that support atomic memory transactions.-data TVar a = TVar (TVar# RealWorld a)-              deriving Typeable--instance Eq (TVar a) where-        (TVar tvar1#) == (TVar tvar2#) = isTrue# (sameTVar# tvar1# tvar2#)---- |Create a new TVar holding a value supplied-newTVar :: a -> STM (TVar a)-newTVar val = STM $ \s1# ->-    case newTVar# val s1# of-         (# s2#, tvar# #) -> (# s2#, TVar tvar# #)---- |@IO@ version of 'newTVar'.  This is useful for creating top-level--- 'TVar's using 'System.IO.Unsafe.unsafePerformIO', because using--- 'atomically' inside 'System.IO.Unsafe.unsafePerformIO' isn't--- possible.-newTVarIO :: a -> IO (TVar a)-newTVarIO val = IO $ \s1# ->-    case newTVar# val s1# of-         (# s2#, tvar# #) -> (# s2#, TVar tvar# #)---- |Return the current value stored in a TVar.--- This is equivalent to------ >  readTVarIO = atomically . readTVar------ but works much faster, because it doesn't perform a complete--- transaction, it just reads the current value of the 'TVar'.-readTVarIO :: TVar a -> IO a-readTVarIO (TVar tvar#) = IO $ \s# -> readTVarIO# tvar# s#---- |Return the current value stored in a TVar-readTVar :: TVar a -> STM a-readTVar (TVar tvar#) = STM $ \s# -> readTVar# tvar# s#---- |Write the supplied value into a TVar-writeTVar :: TVar a -> a -> STM ()-writeTVar (TVar tvar#) val = STM $ \s1# ->-    case writeTVar# tvar# val s1# of-         s2# -> (# s2#, () #)--\end{code}--MVar utilities--\begin{code}-withMVar :: MVar a -> (a -> IO b) -> IO b-withMVar m io =-  mask $ \restore -> do-    a <- takeMVar m-    b <- catchAny (restore (io a))-            (\e -> do putMVar m a; throw e)-    putMVar m a-    return b--modifyMVar_ :: MVar a -> (a -> IO a) -> IO ()-modifyMVar_ m io =-  mask $ \restore -> do-    a <- takeMVar m-    a' <- catchAny (restore (io a))-            (\e -> do putMVar m a; throw e)-    putMVar m a'-    return ()-\end{code}--%************************************************************************-%*                                                                      *-\subsection{Thread waiting}-%*                                                                      *-%************************************************************************--\begin{code}---- Machinery needed to ensureb that we only have one copy of certain--- CAFs in this module even when the base package is present twice, as--- it is when base is dynamically loaded into GHCi.  The RTS keeps--- track of the single true value of the CAF, so even when the CAFs in--- the dynamically-loaded base package are reverted, nothing bad--- happens.----sharedCAF :: a -> (Ptr a -> IO (Ptr a)) -> IO a-sharedCAF a get_or_set =-   mask_ $ do-     stable_ref <- newStablePtr a-     let ref = castPtr (castStablePtrToPtr stable_ref)-     ref2 <- get_or_set ref-     if ref==ref2-        then return a-        else do freeStablePtr stable_ref-                deRefStablePtr (castPtrToStablePtr (castPtr ref2))--reportStackOverflow :: IO ()-reportStackOverflow = do-     ThreadId tid <- myThreadId-     callStackOverflowHook tid--reportError :: SomeException -> IO ()-reportError ex = do-   handler <- getUncaughtExceptionHandler-   handler ex---- SUP: Are the hooks allowed to re-enter Haskell land?  If so, remove--- the unsafe below.-foreign import ccall unsafe "stackOverflow"-        callStackOverflowHook :: ThreadId# -> IO ()--{-# NOINLINE uncaughtExceptionHandler #-}-uncaughtExceptionHandler :: IORef (SomeException -> IO ())-uncaughtExceptionHandler = unsafePerformIO (newIORef defaultHandler)-   where-      defaultHandler :: SomeException -> IO ()-      defaultHandler se@(SomeException ex) = do-         (hFlush stdout) `catchAny` (\ _ -> return ())-         let msg = case cast ex of-               Just Deadlock -> "no threads to run:  infinite loop or deadlock?"-               _ -> case cast ex of-                    Just (ErrorCall s) -> s-                    _                  -> showsPrec 0 se ""-         withCString "%s" $ \cfmt ->-          withCString msg $ \cmsg ->-            errorBelch cfmt cmsg---- don't use errorBelch() directly, because we cannot call varargs functions--- using the FFI.-foreign import ccall unsafe "HsBase.h errorBelch2"-   errorBelch :: CString -> CString -> IO ()--setUncaughtExceptionHandler :: (SomeException -> IO ()) -> IO ()-setUncaughtExceptionHandler = writeIORef uncaughtExceptionHandler--getUncaughtExceptionHandler :: IO (SomeException -> IO ())-getUncaughtExceptionHandler = readIORef uncaughtExceptionHandler--\end{code}
GHC/Conc/Windows.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE Trustworthy #-}-{-# LANGUAGE CPP, NoImplicitPrelude, MagicHash, UnboxedTuples, DeriveDataTypeable #-}+{-# LANGUAGE CPP, NoImplicitPrelude, MagicHash, UnboxedTuples,+             AutoDeriveTypeable #-} {-# OPTIONS_GHC -fno-warn-missing-signatures #-} {-# OPTIONS_HADDOCK not-home #-} @@ -38,9 +39,7 @@        , toWin32ConsoleEvent        ) where -import Control.Monad import Data.Bits (shiftR)-import Data.Maybe (Maybe(..)) import Data.Typeable import GHC.Base import GHC.Conc.Sync@@ -226,7 +225,7 @@   -- conditions in which prodding is left at True but the server is   -- blocked in select().   was_set <- atomicModifyIORef prodding $ \b -> (True,b)-  unless was_set wakeupIOManager+  when (not was_set) wakeupIOManager  -- ---------------------------------------------------------------------------- -- Windows IO manager thread@@ -259,7 +258,7 @@                 _ | r2 == io_MANAGER_DIE    -> return True                 0 -> return False -- spurious wakeup                 _ -> do start_console_handler (r2 `shiftR` 1); return False-        unless exit $ service_cont wakeup delays'+        when (not exit) $ service_cont wakeup delays'      _other -> service_cont wakeup delays' -- probably timeout 
GHC/ConsoleHandler.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE Trustworthy #-}+{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE CPP #-}  -----------------------------------------------------------------------------@@ -20,6 +21,8 @@ module GHC.ConsoleHandler #if !defined(mingw32_HOST_OS) && !defined(__HADDOCK__)         where++import GHC.Base ()  -- dummy dependency #else /* whole file */         ( Handler(..)         , installHandler@@ -38,6 +41,7 @@       by GHC -} +import GHC.Base import Foreign import Foreign.C import GHC.IO.FD
GHC/Constants.hs view
@@ -1,10 +1,10 @@ {-# LANGUAGE Trustworthy #-}+{-# LANGUAGE NoImplicitPrelude #-}  module GHC.Constants where -import Prelude ()- -- TODO: This used to include HaskellConstants.hs, but that has now gone. -- We probably want to include the constants in platformConstants somehow -- instead. +import GHC.Base () -- dummy dependency
+ GHC/Enum.hs view
@@ -0,0 +1,731 @@+{-# LANGUAGE Trustworthy #-}+{-# LANGUAGE CPP, NoImplicitPrelude, BangPatterns, MagicHash #-}+{-# OPTIONS_HADDOCK hide #-}++-----------------------------------------------------------------------------+-- |+-- Module      :  GHC.Enum+-- Copyright   :  (c) The University of Glasgow, 1992-2002+-- License     :  see libraries/base/LICENSE+--+-- Maintainer  :  cvs-ghc@haskell.org+-- Stability   :  internal+-- Portability :  non-portable (GHC extensions)+--+-- The 'Enum' and 'Bounded' classes.+--+-----------------------------------------------------------------------------++#include "MachDeps.h"++module GHC.Enum(+        Bounded(..), Enum(..),+        boundedEnumFrom, boundedEnumFromThen,+        toEnumError, fromEnumError, succError, predError,++        -- Instances for Bounded and Enum: (), Char, Int++   ) where++import GHC.Base hiding ( many )+import GHC.Char+import GHC.Integer+import GHC.Num+import GHC.Show+default ()              -- Double isn't available yet++-- | The 'Bounded' class is used to name the upper and lower limits of a+-- type.  'Ord' is not a superclass of 'Bounded' since types that are not+-- totally ordered may also have upper and lower bounds.+--+-- The 'Bounded' class may be derived for any enumeration type;+-- 'minBound' is the first constructor listed in the @data@ declaration+-- and 'maxBound' is the last.+-- 'Bounded' may also be derived for single-constructor datatypes whose+-- constituent types are in 'Bounded'.++class  Bounded a  where+    minBound, maxBound :: a++-- | Class 'Enum' defines operations on sequentially ordered types.+--+-- The @enumFrom@... methods are used in Haskell's translation of+-- arithmetic sequences.+--+-- Instances of 'Enum' may be derived for any enumeration type (types+-- whose constructors have no fields).  The nullary constructors are+-- assumed to be numbered left-to-right by 'fromEnum' from @0@ through @n-1@.+-- See Chapter 10 of the /Haskell Report/ for more details.+--+-- For any type that is an instance of class 'Bounded' as well as 'Enum',+-- the following should hold:+--+-- * The calls @'succ' 'maxBound'@ and @'pred' 'minBound'@ should result in+--   a runtime error.+--+-- * 'fromEnum' and 'toEnum' should give a runtime error if the+--   result value is not representable in the result type.+--   For example, @'toEnum' 7 :: 'Bool'@ is an error.+--+-- * 'enumFrom' and 'enumFromThen' should be defined with an implicit bound,+--   thus:+--+-- >    enumFrom     x   = enumFromTo     x maxBound+-- >    enumFromThen x y = enumFromThenTo x y bound+-- >      where+-- >        bound | fromEnum y >= fromEnum x = maxBound+-- >              | otherwise                = minBound+--+class  Enum a   where+    -- | the successor of a value.  For numeric types, 'succ' adds 1.+    succ                :: a -> a+    -- | the predecessor of a value.  For numeric types, 'pred' subtracts 1.+    pred                :: a -> a+    -- | Convert from an 'Int'.+    toEnum              :: Int -> a+    -- | Convert to an 'Int'.+    -- It is implementation-dependent what 'fromEnum' returns when+    -- applied to a value that is too large to fit in an 'Int'.+    fromEnum            :: a -> Int++    -- | Used in Haskell's translation of @[n..]@.+    enumFrom            :: a -> [a]+    -- | Used in Haskell's translation of @[n,n'..]@.+    enumFromThen        :: a -> a -> [a]+    -- | Used in Haskell's translation of @[n..m]@.+    enumFromTo          :: a -> a -> [a]+    -- | Used in Haskell's translation of @[n,n'..m]@.+    enumFromThenTo      :: a -> a -> a -> [a]++    succ                   = toEnum . (+ 1)  . fromEnum+    pred                   = toEnum . (subtract 1) . fromEnum+    enumFrom x             = map toEnum [fromEnum x ..]+    enumFromThen x y       = map toEnum [fromEnum x, fromEnum y ..]+    enumFromTo x y         = map toEnum [fromEnum x .. fromEnum y]+    enumFromThenTo x1 x2 y = map toEnum [fromEnum x1, fromEnum x2 .. fromEnum y]++-- Default methods for bounded enumerations+boundedEnumFrom :: (Enum a, Bounded a) => a -> [a]+boundedEnumFrom n = map toEnum [fromEnum n .. fromEnum (maxBound `asTypeOf` n)]++boundedEnumFromThen :: (Enum a, Bounded a) => a -> a -> [a]+boundedEnumFromThen n1 n2+  | i_n2 >= i_n1  = map toEnum [i_n1, i_n2 .. fromEnum (maxBound `asTypeOf` n1)]+  | otherwise     = map toEnum [i_n1, i_n2 .. fromEnum (minBound `asTypeOf` n1)]+  where+    i_n1 = fromEnum n1+    i_n2 = fromEnum n2++------------------------------------------------------------------------+-- Helper functions+------------------------------------------------------------------------++{-# NOINLINE toEnumError #-}+toEnumError :: (Show a) => String -> Int -> (a,a) -> b+toEnumError inst_ty i bnds =+    error $ "Enum.toEnum{" ++ inst_ty ++ "}: tag (" +++            show i +++            ") is outside of bounds " +++            show bnds++{-# NOINLINE fromEnumError #-}+fromEnumError :: (Show a) => String -> a -> b+fromEnumError inst_ty x =+    error $ "Enum.fromEnum{" ++ inst_ty ++ "}: value (" +++            show x +++            ") is outside of Int's bounds " +++            show (minBound::Int, maxBound::Int)++{-# NOINLINE succError #-}+succError :: String -> a+succError inst_ty =+    error $ "Enum.succ{" ++ inst_ty ++ "}: tried to take `succ' of maxBound"++{-# NOINLINE predError #-}+predError :: String -> a+predError inst_ty =+    error $ "Enum.pred{" ++ inst_ty ++ "}: tried to take `pred' of minBound"++------------------------------------------------------------------------+-- Tuples+------------------------------------------------------------------------++instance Bounded () where+    minBound = ()+    maxBound = ()++instance Enum () where+    succ _      = error "Prelude.Enum.().succ: bad argument"+    pred _      = error "Prelude.Enum.().pred: bad argument"++    toEnum x | x == 0    = ()+             | otherwise = error "Prelude.Enum.().toEnum: bad argument"++    fromEnum () = 0+    enumFrom ()         = [()]+    enumFromThen () ()  = let many = ():many in many+    enumFromTo () ()    = [()]+    enumFromThenTo () () () = let many = ():many in many++-- Report requires instances up to 15+instance (Bounded a, Bounded b) => Bounded (a,b) where+   minBound = (minBound, minBound)+   maxBound = (maxBound, maxBound)++instance (Bounded a, Bounded b, Bounded c) => Bounded (a,b,c) where+   minBound = (minBound, minBound, minBound)+   maxBound = (maxBound, maxBound, maxBound)++instance (Bounded a, Bounded b, Bounded c, Bounded d) => Bounded (a,b,c,d) where+   minBound = (minBound, minBound, minBound, minBound)+   maxBound = (maxBound, maxBound, maxBound, maxBound)++instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e) => Bounded (a,b,c,d,e) where+   minBound = (minBound, minBound, minBound, minBound, minBound)+   maxBound = (maxBound, maxBound, maxBound, maxBound, maxBound)++instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f)+        => Bounded (a,b,c,d,e,f) where+   minBound = (minBound, minBound, minBound, minBound, minBound, minBound)+   maxBound = (maxBound, maxBound, maxBound, maxBound, maxBound, maxBound)++instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g)+        => Bounded (a,b,c,d,e,f,g) where+   minBound = (minBound, minBound, minBound, minBound, minBound, minBound, minBound)+   maxBound = (maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound)++instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g,+          Bounded h)+        => Bounded (a,b,c,d,e,f,g,h) where+   minBound = (minBound, minBound, minBound, minBound, minBound, minBound, minBound, minBound)+   maxBound = (maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound)++instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g,+          Bounded h, Bounded i)+        => Bounded (a,b,c,d,e,f,g,h,i) where+   minBound = (minBound, minBound, minBound, minBound, minBound, minBound, minBound, minBound,+               minBound)+   maxBound = (maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound,+               maxBound)++instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g,+          Bounded h, Bounded i, Bounded j)+        => Bounded (a,b,c,d,e,f,g,h,i,j) where+   minBound = (minBound, minBound, minBound, minBound, minBound, minBound, minBound, minBound,+               minBound, minBound)+   maxBound = (maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound,+               maxBound, maxBound)++instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g,+          Bounded h, Bounded i, Bounded j, Bounded k)+        => Bounded (a,b,c,d,e,f,g,h,i,j,k) where+   minBound = (minBound, minBound, minBound, minBound, minBound, minBound, minBound, minBound,+               minBound, minBound, minBound)+   maxBound = (maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound,+               maxBound, maxBound, maxBound)++instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g,+          Bounded h, Bounded i, Bounded j, Bounded k, Bounded l)+        => Bounded (a,b,c,d,e,f,g,h,i,j,k,l) where+   minBound = (minBound, minBound, minBound, minBound, minBound, minBound, minBound, minBound,+               minBound, minBound, minBound, minBound)+   maxBound = (maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound,+               maxBound, maxBound, maxBound, maxBound)++instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g,+          Bounded h, Bounded i, Bounded j, Bounded k, Bounded l, Bounded m)+        => Bounded (a,b,c,d,e,f,g,h,i,j,k,l,m) where+   minBound = (minBound, minBound, minBound, minBound, minBound, minBound, minBound, minBound,+               minBound, minBound, minBound, minBound, minBound)+   maxBound = (maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound,+               maxBound, maxBound, maxBound, maxBound, maxBound)++instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g,+          Bounded h, Bounded i, Bounded j, Bounded k, Bounded l, Bounded m, Bounded n)+        => Bounded (a,b,c,d,e,f,g,h,i,j,k,l,m,n) where+   minBound = (minBound, minBound, minBound, minBound, minBound, minBound, minBound, minBound,+               minBound, minBound, minBound, minBound, minBound, minBound)+   maxBound = (maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound,+               maxBound, maxBound, maxBound, maxBound, maxBound, maxBound)++instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g,+          Bounded h, Bounded i, Bounded j, Bounded k, Bounded l, Bounded m, Bounded n, Bounded o)+        => Bounded (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) where+   minBound = (minBound, minBound, minBound, minBound, minBound, minBound, minBound, minBound,+               minBound, minBound, minBound, minBound, minBound, minBound, minBound)+   maxBound = (maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound,+               maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound)++------------------------------------------------------------------------+-- Bool+------------------------------------------------------------------------++instance Bounded Bool where+  minBound = False+  maxBound = True++instance Enum Bool where+  succ False = True+  succ True  = error "Prelude.Enum.Bool.succ: bad argument"++  pred True  = False+  pred False  = error "Prelude.Enum.Bool.pred: bad argument"++  toEnum n | n == 0    = False+           | n == 1    = True+           | otherwise = error "Prelude.Enum.Bool.toEnum: bad argument"++  fromEnum False = 0+  fromEnum True  = 1++  -- Use defaults for the rest+  enumFrom     = boundedEnumFrom+  enumFromThen = boundedEnumFromThen++------------------------------------------------------------------------+-- Ordering+------------------------------------------------------------------------++instance Bounded Ordering where+  minBound = LT+  maxBound = GT++instance Enum Ordering where+  succ LT = EQ+  succ EQ = GT+  succ GT = error "Prelude.Enum.Ordering.succ: bad argument"++  pred GT = EQ+  pred EQ = LT+  pred LT = error "Prelude.Enum.Ordering.pred: bad argument"++  toEnum n | n == 0 = LT+           | n == 1 = EQ+           | n == 2 = GT+  toEnum _ = error "Prelude.Enum.Ordering.toEnum: bad argument"++  fromEnum LT = 0+  fromEnum EQ = 1+  fromEnum GT = 2++  -- Use defaults for the rest+  enumFrom     = boundedEnumFrom+  enumFromThen = boundedEnumFromThen++------------------------------------------------------------------------+-- Char+------------------------------------------------------------------------++instance  Bounded Char  where+    minBound =  '\0'+    maxBound =  '\x10FFFF'++instance  Enum Char  where+    succ (C# c#)+       | isTrue# (ord# c# /=# 0x10FFFF#) = C# (chr# (ord# c# +# 1#))+       | otherwise             = error ("Prelude.Enum.Char.succ: bad argument")+    pred (C# c#)+       | isTrue# (ord# c# /=# 0#) = C# (chr# (ord# c# -# 1#))+       | otherwise                = error ("Prelude.Enum.Char.pred: bad argument")++    toEnum   = chr+    fromEnum = ord++    {-# INLINE enumFrom #-}+    enumFrom (C# x) = eftChar (ord# x) 0x10FFFF#+        -- Blarg: technically I guess enumFrom isn't strict!++    {-# INLINE enumFromTo #-}+    enumFromTo (C# x) (C# y) = eftChar (ord# x) (ord# y)++    {-# INLINE enumFromThen #-}+    enumFromThen (C# x1) (C# x2) = efdChar (ord# x1) (ord# x2)++    {-# INLINE enumFromThenTo #-}+    enumFromThenTo (C# x1) (C# x2) (C# y) = efdtChar (ord# x1) (ord# x2) (ord# y)++{-# RULES+"eftChar"       [~1] forall x y.        eftChar x y       = build (\c n -> eftCharFB c n x y)+"efdChar"       [~1] forall x1 x2.      efdChar x1 x2     = build (\ c n -> efdCharFB c n x1 x2)+"efdtChar"      [~1] forall x1 x2 l.    efdtChar x1 x2 l  = build (\ c n -> efdtCharFB c n x1 x2 l)+"eftCharList"   [1]  eftCharFB  (:) [] = eftChar+"efdCharList"   [1]  efdCharFB  (:) [] = efdChar+"efdtCharList"  [1]  efdtCharFB (:) [] = efdtChar+ #-}+++-- We can do better than for Ints because we don't+-- have hassles about arithmetic overflow at maxBound+{-# INLINE [0] eftCharFB #-}+eftCharFB :: (Char -> a -> a) -> a -> Int# -> Int# -> a+eftCharFB c n x0 y = go x0+                 where+                    go x | isTrue# (x ># y) = n+                         | otherwise        = C# (chr# x) `c` go (x +# 1#)++{-# NOINLINE [1] eftChar #-}+eftChar :: Int# -> Int# -> String+eftChar x y | isTrue# (x ># y ) = []+            | otherwise         = C# (chr# x) : eftChar (x +# 1#) y+++-- For enumFromThenTo we give up on inlining+{-# NOINLINE [0] efdCharFB #-}+efdCharFB :: (Char -> a -> a) -> a -> Int# -> Int# -> a+efdCharFB c n x1 x2+  | isTrue# (delta >=# 0#) = go_up_char_fb c n x1 delta 0x10FFFF#+  | otherwise              = go_dn_char_fb c n x1 delta 0#+  where+    !delta = x2 -# x1++{-# NOINLINE [1] efdChar #-}+efdChar :: Int# -> Int# -> String+efdChar x1 x2+  | isTrue# (delta >=# 0#) = go_up_char_list x1 delta 0x10FFFF#+  | otherwise              = go_dn_char_list x1 delta 0#+  where+    !delta = x2 -# x1++{-# NOINLINE [0] efdtCharFB #-}+efdtCharFB :: (Char -> a -> a) -> a -> Int# -> Int# -> Int# -> a+efdtCharFB c n x1 x2 lim+  | isTrue# (delta >=# 0#) = go_up_char_fb c n x1 delta lim+  | otherwise              = go_dn_char_fb c n x1 delta lim+  where+    !delta = x2 -# x1++{-# NOINLINE [1] efdtChar #-}+efdtChar :: Int# -> Int# -> Int# -> String+efdtChar x1 x2 lim+  | isTrue# (delta >=# 0#) = go_up_char_list x1 delta lim+  | otherwise              = go_dn_char_list x1 delta lim+  where+    !delta = x2 -# x1++go_up_char_fb :: (Char -> a -> a) -> a -> Int# -> Int# -> Int# -> a+go_up_char_fb c n x0 delta lim+  = go_up x0+  where+    go_up x | isTrue# (x ># lim) = n+            | otherwise          = C# (chr# x) `c` go_up (x +# delta)++go_dn_char_fb :: (Char -> a -> a) -> a -> Int# -> Int# -> Int# -> a+go_dn_char_fb c n x0 delta lim+  = go_dn x0+  where+    go_dn x | isTrue# (x <# lim) = n+            | otherwise          = C# (chr# x) `c` go_dn (x +# delta)++go_up_char_list :: Int# -> Int# -> Int# -> String+go_up_char_list x0 delta lim+  = go_up x0+  where+    go_up x | isTrue# (x ># lim) = []+            | otherwise          = C# (chr# x) : go_up (x +# delta)++go_dn_char_list :: Int# -> Int# -> Int# -> String+go_dn_char_list x0 delta lim+  = go_dn x0+  where+    go_dn x | isTrue# (x <# lim) = []+            | otherwise          = C# (chr# x) : go_dn (x +# delta)+++------------------------------------------------------------------------+-- Int+------------------------------------------------------------------------++{-+Be careful about these instances.+        (a) remember that you have to count down as well as up e.g. [13,12..0]+        (b) be careful of Int overflow+        (c) remember that Int is bounded, so [1..] terminates at maxInt+-}++instance  Bounded Int where+    minBound =  minInt+    maxBound =  maxInt++instance  Enum Int  where+    succ x+       | x == maxBound  = error "Prelude.Enum.succ{Int}: tried to take `succ' of maxBound"+       | otherwise      = x + 1+    pred x+       | x == minBound  = error "Prelude.Enum.pred{Int}: tried to take `pred' of minBound"+       | otherwise      = x - 1++    toEnum   x = x+    fromEnum x = x++    {-# INLINE enumFrom #-}+    enumFrom (I# x) = eftInt x maxInt#+        where !(I# maxInt#) = maxInt+        -- Blarg: technically I guess enumFrom isn't strict!++    {-# INLINE enumFromTo #-}+    enumFromTo (I# x) (I# y) = eftInt x y++    {-# INLINE enumFromThen #-}+    enumFromThen (I# x1) (I# x2) = efdInt x1 x2++    {-# INLINE enumFromThenTo #-}+    enumFromThenTo (I# x1) (I# x2) (I# y) = efdtInt x1 x2 y+++-----------------------------------------------------+-- eftInt and eftIntFB deal with [a..b], which is the+-- most common form, so we take a lot of care+-- In particular, we have rules for deforestation++{-# RULES+"eftInt"        [~1] forall x y. eftInt x y = build (\ c n -> eftIntFB c n x y)+"eftIntList"    [1] eftIntFB  (:) [] = eftInt+ #-}++{-# NOINLINE [1] eftInt #-}+eftInt :: Int# -> Int# -> [Int]+-- [x1..x2]+eftInt x0 y | isTrue# (x0 ># y) = []+            | otherwise         = go x0+               where+                 go x = I# x : if isTrue# (x ==# y)+                               then []+                               else go (x +# 1#)++{-# INLINE [0] eftIntFB #-}+eftIntFB :: (Int -> r -> r) -> r -> Int# -> Int# -> r+eftIntFB c n x0 y | isTrue# (x0 ># y) = n+                  | otherwise         = go x0+                 where+                   go x = I# x `c` if isTrue# (x ==# y)+                                   then n+                                   else go (x +# 1#)+                        -- Watch out for y=maxBound; hence ==, not >+        -- Be very careful not to have more than one "c"+        -- so that when eftInfFB is inlined we can inline+        -- whatever is bound to "c"+++-----------------------------------------------------+-- efdInt and efdtInt deal with [a,b..] and [a,b..c].+-- The code is more complicated because of worries about Int overflow.++{-# RULES+"efdtInt"       [~1] forall x1 x2 y.+                     efdtInt x1 x2 y = build (\ c n -> efdtIntFB c n x1 x2 y)+"efdtIntUpList" [1]  efdtIntFB (:) [] = efdtInt+ #-}++efdInt :: Int# -> Int# -> [Int]+-- [x1,x2..maxInt]+efdInt x1 x2+ | isTrue# (x2 >=# x1) = case maxInt of I# y -> efdtIntUp x1 x2 y+ | otherwise           = case minInt of I# y -> efdtIntDn x1 x2 y++{-# NOINLINE [1] efdtInt #-}+efdtInt :: Int# -> Int# -> Int# -> [Int]+-- [x1,x2..y]+efdtInt x1 x2 y+ | isTrue# (x2 >=# x1) = efdtIntUp x1 x2 y+ | otherwise           = efdtIntDn x1 x2 y++{-# INLINE [0] efdtIntFB #-}+efdtIntFB :: (Int -> r -> r) -> r -> Int# -> Int# -> Int# -> r+efdtIntFB c n x1 x2 y+ | isTrue# (x2 >=# x1) = efdtIntUpFB c n x1 x2 y+ | otherwise           = efdtIntDnFB c n x1 x2 y++-- Requires x2 >= x1+efdtIntUp :: Int# -> Int# -> Int# -> [Int]+efdtIntUp x1 x2 y    -- Be careful about overflow!+ | isTrue# (y <# x2) = if isTrue# (y <# x1) then [] else [I# x1]+ | otherwise = -- Common case: x1 <= x2 <= y+               let !delta = x2 -# x1 -- >= 0+                   !y' = y -# delta  -- x1 <= y' <= y; hence y' is representable++                   -- Invariant: x <= y+                   -- Note that: z <= y' => z + delta won't overflow+                   -- so we are guaranteed not to overflow if/when we recurse+                   go_up x | isTrue# (x ># y') = [I# x]+                           | otherwise         = I# x : go_up (x +# delta)+               in I# x1 : go_up x2++-- Requires x2 >= x1+efdtIntUpFB :: (Int -> r -> r) -> r -> Int# -> Int# -> Int# -> r+efdtIntUpFB c n x1 x2 y    -- Be careful about overflow!+ | isTrue# (y <# x2) = if isTrue# (y <# x1) then n else I# x1 `c` n+ | otherwise = -- Common case: x1 <= x2 <= y+               let !delta = x2 -# x1 -- >= 0+                   !y' = y -# delta  -- x1 <= y' <= y; hence y' is representable++                   -- Invariant: x <= y+                   -- Note that: z <= y' => z + delta won't overflow+                   -- so we are guaranteed not to overflow if/when we recurse+                   go_up x | isTrue# (x ># y') = I# x `c` n+                           | otherwise         = I# x `c` go_up (x +# delta)+               in I# x1 `c` go_up x2++-- Requires x2 <= x1+efdtIntDn :: Int# -> Int# -> Int# -> [Int]+efdtIntDn x1 x2 y    -- Be careful about underflow!+ | isTrue# (y ># x2) = if isTrue# (y ># x1) then [] else [I# x1]+ | otherwise = -- Common case: x1 >= x2 >= y+               let !delta = x2 -# x1 -- <= 0+                   !y' = y -# delta  -- y <= y' <= x1; hence y' is representable++                   -- Invariant: x >= y+                   -- Note that: z >= y' => z + delta won't underflow+                   -- so we are guaranteed not to underflow if/when we recurse+                   go_dn x | isTrue# (x <# y') = [I# x]+                           | otherwise         = I# x : go_dn (x +# delta)+   in I# x1 : go_dn x2++-- Requires x2 <= x1+efdtIntDnFB :: (Int -> r -> r) -> r -> Int# -> Int# -> Int# -> r+efdtIntDnFB c n x1 x2 y    -- Be careful about underflow!+ | isTrue# (y ># x2) = if isTrue# (y ># x1) then n else I# x1 `c` n+ | otherwise = -- Common case: x1 >= x2 >= y+               let !delta = x2 -# x1 -- <= 0+                   !y' = y -# delta  -- y <= y' <= x1; hence y' is representable++                   -- Invariant: x >= y+                   -- Note that: z >= y' => z + delta won't underflow+                   -- so we are guaranteed not to underflow if/when we recurse+                   go_dn x | isTrue# (x <# y') = I# x `c` n+                           | otherwise         = I# x `c` go_dn (x +# delta)+               in I# x1 `c` go_dn x2+++------------------------------------------------------------------------+-- Word+------------------------------------------------------------------------++instance Bounded Word where+    minBound = 0++    -- use unboxed literals for maxBound, because GHC doesn't optimise+    -- (fromInteger 0xffffffff :: Word).+#if WORD_SIZE_IN_BITS == 32+    maxBound = W# (int2Word# 0xFFFFFFFF#)+#elif WORD_SIZE_IN_BITS == 64+    maxBound = W# (int2Word# 0xFFFFFFFFFFFFFFFF#)+#else+#error Unhandled value for WORD_SIZE_IN_BITS+#endif++instance Enum Word where+    succ x+        | x /= maxBound = x + 1+        | otherwise     = succError "Word"+    pred x+        | x /= minBound = x - 1+        | otherwise     = predError "Word"+    toEnum i@(I# i#)+        | i >= 0        = W# (int2Word# i#)+        | otherwise     = toEnumError "Word" i (minBound::Word, maxBound::Word)+    fromEnum x@(W# x#)+        | x <= maxIntWord = I# (word2Int# x#)+        | otherwise       = fromEnumError "Word" x++    enumFrom n             = map integerToWordX [wordToIntegerX n .. wordToIntegerX (maxBound :: Word)]+    enumFromTo n1 n2       = map integerToWordX [wordToIntegerX n1 .. wordToIntegerX n2]+    enumFromThenTo n1 n2 m = map integerToWordX [wordToIntegerX n1, wordToIntegerX n2 .. wordToIntegerX m]+    enumFromThen n1 n2     = map integerToWordX [wordToIntegerX n1, wordToIntegerX n2 .. wordToIntegerX limit]+      where+         limit :: Word+         limit  | n2 >= n1  = maxBound+                | otherwise = minBound++maxIntWord :: Word+-- The biggest word representable as an Int+maxIntWord = W# (case maxInt of I# i -> int2Word# i)++-- For some reason integerToWord and wordToInteger (GHC.Integer.Type)+-- work over Word#+integerToWordX :: Integer -> Word+integerToWordX i = W# (integerToWord i)++wordToIntegerX :: Word -> Integer+wordToIntegerX (W# x#) = wordToInteger x#++------------------------------------------------------------------------+-- Integer+------------------------------------------------------------------------++instance  Enum Integer  where+    succ x               = x + 1+    pred x               = x - 1+    toEnum (I# n)        = smallInteger n+    fromEnum n           = I# (integerToInt n)++    {-# INLINE enumFrom #-}+    {-# INLINE enumFromThen #-}+    {-# INLINE enumFromTo #-}+    {-# INLINE enumFromThenTo #-}+    enumFrom x             = enumDeltaInteger   x 1+    enumFromThen x y       = enumDeltaInteger   x (y-x)+    enumFromTo x lim       = enumDeltaToInteger x 1     lim+    enumFromThenTo x y lim = enumDeltaToInteger x (y-x) lim++{-# RULES+"enumDeltaInteger"      [~1] forall x y.  enumDeltaInteger x y     = build (\c _ -> enumDeltaIntegerFB c x y)+"efdtInteger"           [~1] forall x y l.enumDeltaToInteger x y l = build (\c n -> enumDeltaToIntegerFB c n x y l)+"enumDeltaInteger"      [1] enumDeltaIntegerFB   (:)    = enumDeltaInteger+"enumDeltaToInteger"    [1] enumDeltaToIntegerFB (:) [] = enumDeltaToInteger+ #-}++{-# NOINLINE [0] enumDeltaIntegerFB #-}+enumDeltaIntegerFB :: (Integer -> b -> b) -> Integer -> Integer -> b+enumDeltaIntegerFB c x d = x `seq` (x `c` enumDeltaIntegerFB c (x+d) d)++{-# NOINLINE [1] enumDeltaInteger #-}+enumDeltaInteger :: Integer -> Integer -> [Integer]+enumDeltaInteger x d = x `seq` (x : enumDeltaInteger (x+d) d)+-- strict accumulator, so+--     head (drop 1000000 [1 .. ]+-- works++{-# NOINLINE [0] enumDeltaToIntegerFB #-}+-- Don't inline this until RULE "enumDeltaToInteger" has had a chance to fire+enumDeltaToIntegerFB :: (Integer -> a -> a) -> a+                     -> Integer -> Integer -> Integer -> a+enumDeltaToIntegerFB c n x delta lim+  | delta >= 0 = up_fb c n x delta lim+  | otherwise  = dn_fb c n x delta lim++{-# RULES+"enumDeltaToInteger1"   [0] forall c n x . enumDeltaToIntegerFB c n x 1 = up_fb c n x 1+ #-}+-- This rule ensures that in the common case (delta = 1), we do not do the check here,+-- and also that we have the chance to inline up_fb, which would allow the constructor to be+-- inlined and good things to happen.+-- We do not do it for Int this way because hand-tuned code already exists, and+-- the special case varies more from the general case, due to the issue of overflows.++{-# NOINLINE [1] enumDeltaToInteger #-}+enumDeltaToInteger :: Integer -> Integer -> Integer -> [Integer]+enumDeltaToInteger x delta lim+  | delta >= 0 = up_list x delta lim+  | otherwise  = dn_list x delta lim++up_fb :: (Integer -> a -> a) -> a -> Integer -> Integer -> Integer -> a+up_fb c n x0 delta lim = go (x0 :: Integer)+                      where+                        go x | x > lim   = n+                             | otherwise = x `c` go (x+delta)+dn_fb :: (Integer -> a -> a) -> a -> Integer -> Integer -> Integer -> a+dn_fb c n x0 delta lim = go (x0 :: Integer)+                      where+                        go x | x < lim   = n+                             | otherwise = x `c` go (x+delta)++up_list :: Integer -> Integer -> Integer -> [Integer]+up_list x0 delta lim = go (x0 :: Integer)+                    where+                        go x | x > lim   = []+                             | otherwise = x : go (x+delta)+dn_list :: Integer -> Integer -> Integer -> [Integer]+dn_list x0 delta lim = go (x0 :: Integer)+                    where+                        go x | x < lim   = []+                             | otherwise = x : go (x+delta)
− GHC/Enum.lhs
@@ -1,739 +0,0 @@-\begin{code}-{-# LANGUAGE Trustworthy #-}-{-# LANGUAGE CPP, NoImplicitPrelude, BangPatterns, MagicHash #-}-{-# OPTIONS_HADDOCK hide #-}---------------------------------------------------------------------------------- |--- Module      :  GHC.Enum--- Copyright   :  (c) The University of Glasgow, 1992-2002--- License     :  see libraries/base/LICENSE------ Maintainer  :  cvs-ghc@haskell.org--- Stability   :  internal--- Portability :  non-portable (GHC extensions)------ The 'Enum' and 'Bounded' classes.-----------------------------------------------------------------------------------#include "MachDeps.h"--module GHC.Enum(-        Bounded(..), Enum(..),-        boundedEnumFrom, boundedEnumFromThen,-        toEnumError, fromEnumError, succError, predError,--        -- Instances for Bounded and Enum: (), Char, Int--   ) where--import GHC.Base-import GHC.Char-import GHC.Integer-import GHC.Num-import GHC.Show-default ()              -- Double isn't available yet-\end{code}---%*********************************************************-%*                                                      *-\subsection{Class declarations}-%*                                                      *-%*********************************************************--\begin{code}--- | The 'Bounded' class is used to name the upper and lower limits of a--- type.  'Ord' is not a superclass of 'Bounded' since types that are not--- totally ordered may also have upper and lower bounds.------ The 'Bounded' class may be derived for any enumeration type;--- 'minBound' is the first constructor listed in the @data@ declaration--- and 'maxBound' is the last.--- 'Bounded' may also be derived for single-constructor datatypes whose--- constituent types are in 'Bounded'.--class  Bounded a  where-    minBound, maxBound :: a---- | Class 'Enum' defines operations on sequentially ordered types.------ The @enumFrom@... methods are used in Haskell's translation of--- arithmetic sequences.------ Instances of 'Enum' may be derived for any enumeration type (types--- whose constructors have no fields).  The nullary constructors are--- assumed to be numbered left-to-right by 'fromEnum' from @0@ through @n-1@.--- See Chapter 10 of the /Haskell Report/ for more details.------ For any type that is an instance of class 'Bounded' as well as 'Enum',--- the following should hold:------ * The calls @'succ' 'maxBound'@ and @'pred' 'minBound'@ should result in---   a runtime error.------ * 'fromEnum' and 'toEnum' should give a runtime error if the---   result value is not representable in the result type.---   For example, @'toEnum' 7 :: 'Bool'@ is an error.------ * 'enumFrom' and 'enumFromThen' should be defined with an implicit bound,---   thus:------ >    enumFrom     x   = enumFromTo     x maxBound--- >    enumFromThen x y = enumFromThenTo x y bound--- >      where--- >        bound | fromEnum y >= fromEnum x = maxBound--- >              | otherwise                = minBound----class  Enum a   where-    -- | the successor of a value.  For numeric types, 'succ' adds 1.-    succ                :: a -> a-    -- | the predecessor of a value.  For numeric types, 'pred' subtracts 1.-    pred                :: a -> a-    -- | Convert from an 'Int'.-    toEnum              :: Int -> a-    -- | Convert to an 'Int'.-    -- It is implementation-dependent what 'fromEnum' returns when-    -- applied to a value that is too large to fit in an 'Int'.-    fromEnum            :: a -> Int--    -- | Used in Haskell's translation of @[n..]@.-    enumFrom            :: a -> [a]-    -- | Used in Haskell's translation of @[n,n'..]@.-    enumFromThen        :: a -> a -> [a]-    -- | Used in Haskell's translation of @[n..m]@.-    enumFromTo          :: a -> a -> [a]-    -- | Used in Haskell's translation of @[n,n'..m]@.-    enumFromThenTo      :: a -> a -> a -> [a]--    succ                   = toEnum . (+ 1)  . fromEnum-    pred                   = toEnum . (subtract 1) . fromEnum-    enumFrom x             = map toEnum [fromEnum x ..]-    enumFromThen x y       = map toEnum [fromEnum x, fromEnum y ..]-    enumFromTo x y         = map toEnum [fromEnum x .. fromEnum y]-    enumFromThenTo x1 x2 y = map toEnum [fromEnum x1, fromEnum x2 .. fromEnum y]---- Default methods for bounded enumerations-boundedEnumFrom :: (Enum a, Bounded a) => a -> [a]-boundedEnumFrom n = map toEnum [fromEnum n .. fromEnum (maxBound `asTypeOf` n)]--boundedEnumFromThen :: (Enum a, Bounded a) => a -> a -> [a]-boundedEnumFromThen n1 n2-  | i_n2 >= i_n1  = map toEnum [i_n1, i_n2 .. fromEnum (maxBound `asTypeOf` n1)]-  | otherwise     = map toEnum [i_n1, i_n2 .. fromEnum (minBound `asTypeOf` n1)]-  where-    i_n1 = fromEnum n1-    i_n2 = fromEnum n2-\end{code}--\begin{code}---------------------------------------------------------------------------- Helper functions---------------------------------------------------------------------------{-# NOINLINE toEnumError #-}-toEnumError :: (Show a) => String -> Int -> (a,a) -> b-toEnumError inst_ty i bnds =-    error $ "Enum.toEnum{" ++ inst_ty ++ "}: tag (" ++-            show i ++-            ") is outside of bounds " ++-            show bnds--{-# NOINLINE fromEnumError #-}-fromEnumError :: (Show a) => String -> a -> b-fromEnumError inst_ty x =-    error $ "Enum.fromEnum{" ++ inst_ty ++ "}: value (" ++-            show x ++-            ") is outside of Int's bounds " ++-            show (minBound::Int, maxBound::Int)--{-# NOINLINE succError #-}-succError :: String -> a-succError inst_ty =-    error $ "Enum.succ{" ++ inst_ty ++ "}: tried to take `succ' of maxBound"--{-# NOINLINE predError #-}-predError :: String -> a-predError inst_ty =-    error $ "Enum.pred{" ++ inst_ty ++ "}: tried to take `pred' of minBound"-\end{code}---%*********************************************************-%*                                                      *-\subsection{Tuples}-%*                                                      *-%*********************************************************--\begin{code}-instance Bounded () where-    minBound = ()-    maxBound = ()--instance Enum () where-    succ _      = error "Prelude.Enum.().succ: bad argument"-    pred _      = error "Prelude.Enum.().pred: bad argument"--    toEnum x | x == 0    = ()-             | otherwise = error "Prelude.Enum.().toEnum: bad argument"--    fromEnum () = 0-    enumFrom ()         = [()]-    enumFromThen () ()  = let many = ():many in many-    enumFromTo () ()    = [()]-    enumFromThenTo () () () = let many = ():many in many-\end{code}--\begin{code}--- Report requires instances up to 15-instance (Bounded a, Bounded b) => Bounded (a,b) where-   minBound = (minBound, minBound)-   maxBound = (maxBound, maxBound)--instance (Bounded a, Bounded b, Bounded c) => Bounded (a,b,c) where-   minBound = (minBound, minBound, minBound)-   maxBound = (maxBound, maxBound, maxBound)--instance (Bounded a, Bounded b, Bounded c, Bounded d) => Bounded (a,b,c,d) where-   minBound = (minBound, minBound, minBound, minBound)-   maxBound = (maxBound, maxBound, maxBound, maxBound)--instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e) => Bounded (a,b,c,d,e) where-   minBound = (minBound, minBound, minBound, minBound, minBound)-   maxBound = (maxBound, maxBound, maxBound, maxBound, maxBound)--instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f)-        => Bounded (a,b,c,d,e,f) where-   minBound = (minBound, minBound, minBound, minBound, minBound, minBound)-   maxBound = (maxBound, maxBound, maxBound, maxBound, maxBound, maxBound)--instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g)-        => Bounded (a,b,c,d,e,f,g) where-   minBound = (minBound, minBound, minBound, minBound, minBound, minBound, minBound)-   maxBound = (maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound)--instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g,-          Bounded h)-        => Bounded (a,b,c,d,e,f,g,h) where-   minBound = (minBound, minBound, minBound, minBound, minBound, minBound, minBound, minBound)-   maxBound = (maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound)--instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g,-          Bounded h, Bounded i)-        => Bounded (a,b,c,d,e,f,g,h,i) where-   minBound = (minBound, minBound, minBound, minBound, minBound, minBound, minBound, minBound,-               minBound)-   maxBound = (maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound,-               maxBound)--instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g,-          Bounded h, Bounded i, Bounded j)-        => Bounded (a,b,c,d,e,f,g,h,i,j) where-   minBound = (minBound, minBound, minBound, minBound, minBound, minBound, minBound, minBound,-               minBound, minBound)-   maxBound = (maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound,-               maxBound, maxBound)--instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g,-          Bounded h, Bounded i, Bounded j, Bounded k)-        => Bounded (a,b,c,d,e,f,g,h,i,j,k) where-   minBound = (minBound, minBound, minBound, minBound, minBound, minBound, minBound, minBound,-               minBound, minBound, minBound)-   maxBound = (maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound,-               maxBound, maxBound, maxBound)--instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g,-          Bounded h, Bounded i, Bounded j, Bounded k, Bounded l)-        => Bounded (a,b,c,d,e,f,g,h,i,j,k,l) where-   minBound = (minBound, minBound, minBound, minBound, minBound, minBound, minBound, minBound,-               minBound, minBound, minBound, minBound)-   maxBound = (maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound,-               maxBound, maxBound, maxBound, maxBound)--instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g,-          Bounded h, Bounded i, Bounded j, Bounded k, Bounded l, Bounded m)-        => Bounded (a,b,c,d,e,f,g,h,i,j,k,l,m) where-   minBound = (minBound, minBound, minBound, minBound, minBound, minBound, minBound, minBound,-               minBound, minBound, minBound, minBound, minBound)-   maxBound = (maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound,-               maxBound, maxBound, maxBound, maxBound, maxBound)--instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g,-          Bounded h, Bounded i, Bounded j, Bounded k, Bounded l, Bounded m, Bounded n)-        => Bounded (a,b,c,d,e,f,g,h,i,j,k,l,m,n) where-   minBound = (minBound, minBound, minBound, minBound, minBound, minBound, minBound, minBound,-               minBound, minBound, minBound, minBound, minBound, minBound)-   maxBound = (maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound,-               maxBound, maxBound, maxBound, maxBound, maxBound, maxBound)--instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g,-          Bounded h, Bounded i, Bounded j, Bounded k, Bounded l, Bounded m, Bounded n, Bounded o)-        => Bounded (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) where-   minBound = (minBound, minBound, minBound, minBound, minBound, minBound, minBound, minBound,-               minBound, minBound, minBound, minBound, minBound, minBound, minBound)-   maxBound = (maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound,-               maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound)-\end{code}---%*********************************************************-%*                                                      *-\subsection{Type @Bool@}-%*                                                      *-%*********************************************************--\begin{code}-instance Bounded Bool where-  minBound = False-  maxBound = True--instance Enum Bool where-  succ False = True-  succ True  = error "Prelude.Enum.Bool.succ: bad argument"--  pred True  = False-  pred False  = error "Prelude.Enum.Bool.pred: bad argument"--  toEnum n | n == 0    = False-           | n == 1    = True-           | otherwise = error "Prelude.Enum.Bool.toEnum: bad argument"--  fromEnum False = 0-  fromEnum True  = 1--  -- Use defaults for the rest-  enumFrom     = boundedEnumFrom-  enumFromThen = boundedEnumFromThen-\end{code}--%*********************************************************-%*                                                      *-\subsection{Type @Ordering@}-%*                                                      *-%*********************************************************--\begin{code}-instance Bounded Ordering where-  minBound = LT-  maxBound = GT--instance Enum Ordering where-  succ LT = EQ-  succ EQ = GT-  succ GT = error "Prelude.Enum.Ordering.succ: bad argument"--  pred GT = EQ-  pred EQ = LT-  pred LT = error "Prelude.Enum.Ordering.pred: bad argument"--  toEnum n | n == 0 = LT-           | n == 1 = EQ-           | n == 2 = GT-  toEnum _ = error "Prelude.Enum.Ordering.toEnum: bad argument"--  fromEnum LT = 0-  fromEnum EQ = 1-  fromEnum GT = 2--  -- Use defaults for the rest-  enumFrom     = boundedEnumFrom-  enumFromThen = boundedEnumFromThen-\end{code}--%*********************************************************-%*                                                      *-\subsection{Type @Char@}-%*                                                      *-%*********************************************************--\begin{code}-instance  Bounded Char  where-    minBound =  '\0'-    maxBound =  '\x10FFFF'--instance  Enum Char  where-    succ (C# c#)-       | isTrue# (ord# c# /=# 0x10FFFF#) = C# (chr# (ord# c# +# 1#))-       | otherwise             = error ("Prelude.Enum.Char.succ: bad argument")-    pred (C# c#)-       | isTrue# (ord# c# /=# 0#) = C# (chr# (ord# c# -# 1#))-       | otherwise                = error ("Prelude.Enum.Char.pred: bad argument")--    toEnum   = chr-    fromEnum = ord--    {-# INLINE enumFrom #-}-    enumFrom (C# x) = eftChar (ord# x) 0x10FFFF#-        -- Blarg: technically I guess enumFrom isn't strict!--    {-# INLINE enumFromTo #-}-    enumFromTo (C# x) (C# y) = eftChar (ord# x) (ord# y)--    {-# INLINE enumFromThen #-}-    enumFromThen (C# x1) (C# x2) = efdChar (ord# x1) (ord# x2)--    {-# INLINE enumFromThenTo #-}-    enumFromThenTo (C# x1) (C# x2) (C# y) = efdtChar (ord# x1) (ord# x2) (ord# y)--{-# RULES-"eftChar"       [~1] forall x y.        eftChar x y       = build (\c n -> eftCharFB c n x y)-"efdChar"       [~1] forall x1 x2.      efdChar x1 x2     = build (\ c n -> efdCharFB c n x1 x2)-"efdtChar"      [~1] forall x1 x2 l.    efdtChar x1 x2 l  = build (\ c n -> efdtCharFB c n x1 x2 l)-"eftCharList"   [1]  eftCharFB  (:) [] = eftChar-"efdCharList"   [1]  efdCharFB  (:) [] = efdChar-"efdtCharList"  [1]  efdtCharFB (:) [] = efdtChar- #-}----- We can do better than for Ints because we don't--- have hassles about arithmetic overflow at maxBound-{-# INLINE [0] eftCharFB #-}-eftCharFB :: (Char -> a -> a) -> a -> Int# -> Int# -> a-eftCharFB c n x0 y = go x0-                 where-                    go x | isTrue# (x ># y) = n-                         | otherwise        = C# (chr# x) `c` go (x +# 1#)--{-# NOINLINE [1] eftChar #-}-eftChar :: Int# -> Int# -> String-eftChar x y | isTrue# (x ># y ) = []-            | otherwise         = C# (chr# x) : eftChar (x +# 1#) y----- For enumFromThenTo we give up on inlining-{-# NOINLINE [0] efdCharFB #-}-efdCharFB :: (Char -> a -> a) -> a -> Int# -> Int# -> a-efdCharFB c n x1 x2-  | isTrue# (delta >=# 0#) = go_up_char_fb c n x1 delta 0x10FFFF#-  | otherwise              = go_dn_char_fb c n x1 delta 0#-  where-    !delta = x2 -# x1--{-# NOINLINE [1] efdChar #-}-efdChar :: Int# -> Int# -> String-efdChar x1 x2-  | isTrue# (delta >=# 0#) = go_up_char_list x1 delta 0x10FFFF#-  | otherwise              = go_dn_char_list x1 delta 0#-  where-    !delta = x2 -# x1--{-# NOINLINE [0] efdtCharFB #-}-efdtCharFB :: (Char -> a -> a) -> a -> Int# -> Int# -> Int# -> a-efdtCharFB c n x1 x2 lim-  | isTrue# (delta >=# 0#) = go_up_char_fb c n x1 delta lim-  | otherwise              = go_dn_char_fb c n x1 delta lim-  where-    !delta = x2 -# x1--{-# NOINLINE [1] efdtChar #-}-efdtChar :: Int# -> Int# -> Int# -> String-efdtChar x1 x2 lim-  | isTrue# (delta >=# 0#) = go_up_char_list x1 delta lim-  | otherwise              = go_dn_char_list x1 delta lim-  where-    !delta = x2 -# x1--go_up_char_fb :: (Char -> a -> a) -> a -> Int# -> Int# -> Int# -> a-go_up_char_fb c n x0 delta lim-  = go_up x0-  where-    go_up x | isTrue# (x ># lim) = n-            | otherwise          = C# (chr# x) `c` go_up (x +# delta)--go_dn_char_fb :: (Char -> a -> a) -> a -> Int# -> Int# -> Int# -> a-go_dn_char_fb c n x0 delta lim-  = go_dn x0-  where-    go_dn x | isTrue# (x <# lim) = n-            | otherwise          = C# (chr# x) `c` go_dn (x +# delta)--go_up_char_list :: Int# -> Int# -> Int# -> String-go_up_char_list x0 delta lim-  = go_up x0-  where-    go_up x | isTrue# (x ># lim) = []-            | otherwise          = C# (chr# x) : go_up (x +# delta)--go_dn_char_list :: Int# -> Int# -> Int# -> String-go_dn_char_list x0 delta lim-  = go_dn x0-  where-    go_dn x | isTrue# (x <# lim) = []-            | otherwise          = C# (chr# x) : go_dn (x +# delta)-\end{code}---%*********************************************************-%*                                                      *-\subsection{Type @Int@}-%*                                                      *-%*********************************************************--Be careful about these instances.-        (a) remember that you have to count down as well as up e.g. [13,12..0]-        (b) be careful of Int overflow-        (c) remember that Int is bounded, so [1..] terminates at maxInt--\begin{code}-instance  Bounded Int where-    minBound =  minInt-    maxBound =  maxInt--instance  Enum Int  where-    succ x-       | x == maxBound  = error "Prelude.Enum.succ{Int}: tried to take `succ' of maxBound"-       | otherwise      = x + 1-    pred x-       | x == minBound  = error "Prelude.Enum.pred{Int}: tried to take `pred' of minBound"-       | otherwise      = x - 1--    toEnum   x = x-    fromEnum x = x--    {-# INLINE enumFrom #-}-    enumFrom (I# x) = eftInt x maxInt#-        where !(I# maxInt#) = maxInt-        -- Blarg: technically I guess enumFrom isn't strict!--    {-# INLINE enumFromTo #-}-    enumFromTo (I# x) (I# y) = eftInt x y--    {-# INLINE enumFromThen #-}-    enumFromThen (I# x1) (I# x2) = efdInt x1 x2--    {-# INLINE enumFromThenTo #-}-    enumFromThenTo (I# x1) (I# x2) (I# y) = efdtInt x1 x2 y----------------------------------------------------------- eftInt and eftIntFB deal with [a..b], which is the--- most common form, so we take a lot of care--- In particular, we have rules for deforestation--{-# RULES-"eftInt"        [~1] forall x y. eftInt x y = build (\ c n -> eftIntFB c n x y)-"eftIntList"    [1] eftIntFB  (:) [] = eftInt- #-}--{-# NOINLINE [1] eftInt #-}-eftInt :: Int# -> Int# -> [Int]--- [x1..x2]-eftInt x0 y | isTrue# (x0 ># y) = []-            | otherwise         = go x0-               where-                 go x = I# x : if isTrue# (x ==# y)-                               then []-                               else go (x +# 1#)--{-# INLINE [0] eftIntFB #-}-eftIntFB :: (Int -> r -> r) -> r -> Int# -> Int# -> r-eftIntFB c n x0 y | isTrue# (x0 ># y) = n-                  | otherwise         = go x0-                 where-                   go x = I# x `c` if isTrue# (x ==# y)-                                   then n-                                   else go (x +# 1#)-                        -- Watch out for y=maxBound; hence ==, not >-        -- Be very careful not to have more than one "c"-        -- so that when eftInfFB is inlined we can inline-        -- whatever is bound to "c"----------------------------------------------------------- efdInt and efdtInt deal with [a,b..] and [a,b..c].--- The code is more complicated because of worries about Int overflow.--{-# RULES-"efdtInt"       [~1] forall x1 x2 y.-                     efdtInt x1 x2 y = build (\ c n -> efdtIntFB c n x1 x2 y)-"efdtIntUpList" [1]  efdtIntFB (:) [] = efdtInt- #-}--efdInt :: Int# -> Int# -> [Int]--- [x1,x2..maxInt]-efdInt x1 x2- | isTrue# (x2 >=# x1) = case maxInt of I# y -> efdtIntUp x1 x2 y- | otherwise           = case minInt of I# y -> efdtIntDn x1 x2 y--{-# NOINLINE [1] efdtInt #-}-efdtInt :: Int# -> Int# -> Int# -> [Int]--- [x1,x2..y]-efdtInt x1 x2 y- | isTrue# (x2 >=# x1) = efdtIntUp x1 x2 y- | otherwise           = efdtIntDn x1 x2 y--{-# INLINE [0] efdtIntFB #-}-efdtIntFB :: (Int -> r -> r) -> r -> Int# -> Int# -> Int# -> r-efdtIntFB c n x1 x2 y- | isTrue# (x2 >=# x1) = efdtIntUpFB c n x1 x2 y- | otherwise           = efdtIntDnFB c n x1 x2 y---- Requires x2 >= x1-efdtIntUp :: Int# -> Int# -> Int# -> [Int]-efdtIntUp x1 x2 y    -- Be careful about overflow!- | isTrue# (y <# x2) = if isTrue# (y <# x1) then [] else [I# x1]- | otherwise = -- Common case: x1 <= x2 <= y-               let !delta = x2 -# x1 -- >= 0-                   !y' = y -# delta  -- x1 <= y' <= y; hence y' is representable--                   -- Invariant: x <= y-                   -- Note that: z <= y' => z + delta won't overflow-                   -- so we are guaranteed not to overflow if/when we recurse-                   go_up x | isTrue# (x ># y') = [I# x]-                           | otherwise         = I# x : go_up (x +# delta)-               in I# x1 : go_up x2---- Requires x2 >= x1-efdtIntUpFB :: (Int -> r -> r) -> r -> Int# -> Int# -> Int# -> r-efdtIntUpFB c n x1 x2 y    -- Be careful about overflow!- | isTrue# (y <# x2) = if isTrue# (y <# x1) then n else I# x1 `c` n- | otherwise = -- Common case: x1 <= x2 <= y-               let !delta = x2 -# x1 -- >= 0-                   !y' = y -# delta  -- x1 <= y' <= y; hence y' is representable--                   -- Invariant: x <= y-                   -- Note that: z <= y' => z + delta won't overflow-                   -- so we are guaranteed not to overflow if/when we recurse-                   go_up x | isTrue# (x ># y') = I# x `c` n-                           | otherwise         = I# x `c` go_up (x +# delta)-               in I# x1 `c` go_up x2---- Requires x2 <= x1-efdtIntDn :: Int# -> Int# -> Int# -> [Int]-efdtIntDn x1 x2 y    -- Be careful about underflow!- | isTrue# (y ># x2) = if isTrue# (y ># x1) then [] else [I# x1]- | otherwise = -- Common case: x1 >= x2 >= y-               let !delta = x2 -# x1 -- <= 0-                   !y' = y -# delta  -- y <= y' <= x1; hence y' is representable--                   -- Invariant: x >= y-                   -- Note that: z >= y' => z + delta won't underflow-                   -- so we are guaranteed not to underflow if/when we recurse-                   go_dn x | isTrue# (x <# y') = [I# x]-                           | otherwise         = I# x : go_dn (x +# delta)-   in I# x1 : go_dn x2---- Requires x2 <= x1-efdtIntDnFB :: (Int -> r -> r) -> r -> Int# -> Int# -> Int# -> r-efdtIntDnFB c n x1 x2 y    -- Be careful about underflow!- | isTrue# (y ># x2) = if isTrue# (y ># x1) then n else I# x1 `c` n- | otherwise = -- Common case: x1 >= x2 >= y-               let !delta = x2 -# x1 -- <= 0-                   !y' = y -# delta  -- y <= y' <= x1; hence y' is representable--                   -- Invariant: x >= y-                   -- Note that: z >= y' => z + delta won't underflow-                   -- so we are guaranteed not to underflow if/when we recurse-                   go_dn x | isTrue# (x <# y') = I# x `c` n-                           | otherwise         = I# x `c` go_dn (x +# delta)-               in I# x1 `c` go_dn x2-\end{code}---%*********************************************************-%*                                                      *-\subsection{Type @Word@}-%*                                                      *-%*********************************************************--\begin{code}-instance Bounded Word where-    minBound = 0--    -- use unboxed literals for maxBound, because GHC doesn't optimise-    -- (fromInteger 0xffffffff :: Word).-#if WORD_SIZE_IN_BITS == 32-    maxBound = W# (int2Word# 0xFFFFFFFF#)-#elif WORD_SIZE_IN_BITS == 64-    maxBound = W# (int2Word# 0xFFFFFFFFFFFFFFFF#)-#else-#error Unhandled value for WORD_SIZE_IN_BITS-#endif-\end{code}---%*********************************************************-%*                                                      *-\subsection{The @Integer@ instance for @Enum@}-%*                                                      *-%*********************************************************--\begin{code}-instance  Enum Integer  where-    succ x               = x + 1-    pred x               = x - 1-    toEnum (I# n)        = smallInteger n-    fromEnum n           = I# (integerToInt n)--    {-# INLINE enumFrom #-}-    {-# INLINE enumFromThen #-}-    {-# INLINE enumFromTo #-}-    {-# INLINE enumFromThenTo #-}-    enumFrom x             = enumDeltaInteger   x 1-    enumFromThen x y       = enumDeltaInteger   x (y-x)-    enumFromTo x lim       = enumDeltaToInteger x 1     lim-    enumFromThenTo x y lim = enumDeltaToInteger x (y-x) lim--{-# RULES-"enumDeltaInteger"      [~1] forall x y.  enumDeltaInteger x y     = build (\c _ -> enumDeltaIntegerFB c x y)-"efdtInteger"           [~1] forall x y l.enumDeltaToInteger x y l = build (\c n -> enumDeltaToIntegerFB c n x y l)-"enumDeltaInteger"      [1] enumDeltaIntegerFB   (:)    = enumDeltaInteger-"enumDeltaToInteger"    [1] enumDeltaToIntegerFB (:) [] = enumDeltaToInteger- #-}--{-# NOINLINE [0] enumDeltaIntegerFB #-}-enumDeltaIntegerFB :: (Integer -> b -> b) -> Integer -> Integer -> b-enumDeltaIntegerFB c x d = x `seq` (x `c` enumDeltaIntegerFB c (x+d) d)--{-# NOINLINE [1] enumDeltaInteger #-}-enumDeltaInteger :: Integer -> Integer -> [Integer]-enumDeltaInteger x d = x `seq` (x : enumDeltaInteger (x+d) d)--- strict accumulator, so---     head (drop 1000000 [1 .. ]--- works--{-# NOINLINE [0] enumDeltaToIntegerFB #-}--- Don't inline this until RULE "enumDeltaToInteger" has had a chance to fire-enumDeltaToIntegerFB :: (Integer -> a -> a) -> a-                     -> Integer -> Integer -> Integer -> a-enumDeltaToIntegerFB c n x delta lim-  | delta >= 0 = up_fb c n x delta lim-  | otherwise  = dn_fb c n x delta lim--{-# RULES-"enumDeltaToInteger1"   [0] forall c n x . enumDeltaToIntegerFB c n x 1 = up_fb c n x 1- #-}--- This rule ensures that in the common case (delta = 1), we do not do the check here,--- and also that we have the chance to inline up_fb, which would allow the constuctor to be--- inlined and good things to happen.--{-# NOINLINE [1] enumDeltaToInteger #-}-enumDeltaToInteger :: Integer -> Integer -> Integer -> [Integer]-enumDeltaToInteger x delta lim-  | delta >= 0 = up_list x delta lim-  | otherwise  = dn_list x delta lim--up_fb :: (Integer -> a -> a) -> a -> Integer -> Integer -> Integer -> a-up_fb c n x0 delta lim = go (x0 :: Integer)-                      where-                        go x | x > lim   = n-                             | otherwise = x `c` go (x+delta)-dn_fb :: (Integer -> a -> a) -> a -> Integer -> Integer -> Integer -> a-dn_fb c n x0 delta lim = go (x0 :: Integer)-                      where-                        go x | x < lim   = n-                             | otherwise = x `c` go (x+delta)--up_list :: Integer -> Integer -> Integer -> [Integer]-up_list x0 delta lim = go (x0 :: Integer)-                    where-                        go x | x > lim   = []-                             | otherwise = x : go (x+delta)-dn_list :: Integer -> Integer -> Integer -> [Integer]-dn_list x0 delta lim = go (x0 :: Integer)-                    where-                        go x | x < lim   = []-                             | otherwise = x : go (x+delta)-\end{code}-
GHC/Environment.hs view
@@ -1,11 +1,13 @@ {-# LANGUAGE Trustworthy #-}+{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE CPP #-}  module GHC.Environment (getFullArgs) where -import Prelude import Foreign import Foreign.C+import GHC.Base+import GHC.Real ( fromIntegral )  #ifdef mingw32_HOST_OS import GHC.IO (finally)@@ -41,9 +43,8 @@ foreign import WINDOWS_CCONV unsafe "Windows.h LocalFree"     c_LocalFree :: Ptr a -> IO (Ptr a) #else-import Control.Monad- import GHC.IO.Encoding+import GHC.Num import qualified GHC.Foreign as GHC  getFullArgs :: IO [String]
+ GHC/Err.hs view
@@ -0,0 +1,47 @@+{-# LANGUAGE Trustworthy #-}+{-# LANGUAGE NoImplicitPrelude, MagicHash #-}+{-# OPTIONS_HADDOCK hide #-}++-----------------------------------------------------------------------------+-- |+-- Module      :  GHC.Err+-- Copyright   :  (c) The University of Glasgow, 1994-2002+-- License     :  see libraries/base/LICENSE+--+-- Maintainer  :  cvs-ghc@haskell.org+-- Stability   :  internal+-- Portability :  non-portable (GHC extensions)+--+-- The "GHC.Err" module defines the code for the wired-in error functions,+-- which have a special type in the compiler (with \"open tyvars\").+--+-- We cannot define these functions in a module where they might be used+-- (e.g., "GHC.Base"), because the magical wired-in type will get confused+-- with what the typechecker figures out.+--+-----------------------------------------------------------------------------++module GHC.Err( absentErr, error, undefined ) where+import GHC.CString ()+import GHC.Types+import GHC.Prim+import GHC.Integer ()   -- Make sure Integer is compiled first+                        -- because GHC depends on it in a wired-in way+                        -- so the build system doesn't see the dependency+import {-# SOURCE #-} GHC.Exception( errorCallException )++-- | 'error' stops execution and displays an error message.+error :: [Char] -> a+error s = raise# (errorCallException s)++-- | A special case of 'error'.+-- It is expected that compilers will recognize this and insert error+-- messages which are more appropriate to the context in which 'undefined'+-- appears.+undefined :: a+undefined =  error "Prelude.undefined"++-- | Used for compiler-generated error message;+-- encoding saves bytes of string junk.+absentErr :: a+absentErr = error "Oops! The program has entered an `absent' argument!\n"
− GHC/Err.lhs
@@ -1,68 +0,0 @@-\begin{code}-{-# LANGUAGE Trustworthy #-}-{-# LANGUAGE NoImplicitPrelude, MagicHash #-}-{-# OPTIONS_HADDOCK hide #-}---------------------------------------------------------------------------------- |--- Module      :  GHC.Err--- Copyright   :  (c) The University of Glasgow, 1994-2002--- License     :  see libraries/base/LICENSE--- --- Maintainer  :  cvs-ghc@haskell.org--- Stability   :  internal--- Portability :  non-portable (GHC extensions)------ The "GHC.Err" module defines the code for the wired-in error functions,--- which have a special type in the compiler (with \"open tyvars\").--- --- We cannot define these functions in a module where they might be used--- (e.g., "GHC.Base"), because the magical wired-in type will get confused--- with what the typechecker figures out.--- --------------------------------------------------------------------------------module GHC.Err( absentErr, error, undefined ) where-import GHC.CString ()-import GHC.Types-import GHC.Prim-import GHC.Integer ()   -- Make sure Integer is compiled first-                        -- because GHC depends on it in a wired-in way-                        -- so the build system doesn't see the dependency-import {-# SOURCE #-} GHC.Exception( errorCallException )-\end{code}--%*********************************************************-%*                                                      *-\subsection{Error-ish functions}-%*                                                      *-%*********************************************************--\begin{code}--- | 'error' stops execution and displays an error message.-error :: [Char] -> a-error s = raise# (errorCallException s)---- | A special case of 'error'.--- It is expected that compilers will recognize this and insert error--- messages which are more appropriate to the context in which 'undefined'--- appears. --undefined :: a-undefined =  error "Prelude.undefined"-\end{code}--%*********************************************************-%*                                                       *-\subsection{Compiler generated errors + local utils}-%*                                                       *-%*********************************************************--Used for compiler-generated error message;-encoding saves bytes of string junk.--\begin{code}-absentErr :: a-absentErr = error "Oops! The program has entered an `absent' argument!\n"-\end{code}-
GHC/Event.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE Trustworthy #-}+{-# LANGUAGE NoImplicitPrelude #-}  -- ---------------------------------------------------------------------------- -- | This module provides scalable event notification for file@@ -11,6 +12,7 @@ module GHC.Event     ( -- * Types       EventManager+    , TimerManager        -- * Creation     , getSystemEventManager@@ -24,7 +26,6 @@     , IOCallback     , FdKey(keyFd)     , registerFd-    , registerFd_     , unregisterFd     , unregisterFd_     , closeFd@@ -39,6 +40,6 @@  import GHC.Event.Manager import GHC.Event.TimerManager (TimeoutCallback, TimeoutKey, registerTimeout,-                               updateTimeout, unregisterTimeout)+                               updateTimeout, unregisterTimeout, TimerManager) import GHC.Event.Thread (getSystemEventManager, getSystemTimerManager) 
GHC/Event/Array.hs view
@@ -24,7 +24,6 @@     , useAsPtr     ) where -import Control.Monad hiding (forM_) import Data.Bits ((.|.), shiftR) import Data.IORef (IORef, atomicModifyIORef', newIORef, readIORef, writeIORef) import Data.Maybe@@ -32,7 +31,7 @@ import Foreign.ForeignPtr (ForeignPtr, withForeignPtr) import Foreign.Ptr (Ptr, nullPtr, plusPtr) import Foreign.Storable (Storable(..))-import GHC.Base+import GHC.Base hiding (empty) import GHC.ForeignPtr (mallocPlainForeignPtrBytes, newForeignPtr_) import GHC.Num (Num(..)) import GHC.Real (fromIntegral)
GHC/Event/Control.hs view
@@ -17,6 +17,7 @@     , readControlMessage     -- *** File descriptors     , controlReadFd+    , controlWriteFd     , wakeupReadFd     -- ** Control message sending     , sendWakeup@@ -27,7 +28,6 @@  #include "EventConfig.h" -import Control.Monad (when) import Foreign.ForeignPtr (ForeignPtr) import GHC.Base import GHC.Conc.Signal (Signal)@@ -68,6 +68,7 @@     , wakeupReadFd   :: {-# UNPACK #-} !Fd     , wakeupWriteFd  :: {-# UNPACK #-} !Fd #endif+    , didRegisterWakeupFd :: !Bool     } deriving (Show)  #if defined(HAVE_EVENTFD)@@ -91,7 +92,6 @@         setCloseOnExec wr         return (rd, wr)   (ctrl_rd, ctrl_wr) <- createPipe-  when shouldRegister $ c_setIOManagerControlFd ctrl_wr #if defined(HAVE_EVENTFD)   ev <- throwErrnoIfMinus1 "eventfd" $ c_eventfd 0 0   setNonBlockingFD ev True@@ -109,13 +109,19 @@            , wakeupReadFd   = fromIntegral wake_rd            , wakeupWriteFd  = fromIntegral wake_wr #endif+           , didRegisterWakeupFd = shouldRegister            }  -- | Close the control structure used by the IO manager thread.+-- N.B. If this Control is the Control whose wakeup file was registered with+-- the RTS, then *BEFORE* the wakeup file is closed, we must call+-- c_setIOManagerWakeupFd (-1), so that the RTS does not try to use the wakeup+-- file after it has been closed. closeControl :: Control -> IO () closeControl w = do   _ <- c_close . fromIntegral . controlReadFd $ w   _ <- c_close . fromIntegral . controlWriteFd $ w+  when (didRegisterWakeupFd w) $ c_setIOManagerWakeupFd (-1) #if defined(HAVE_EVENTFD)   _ <- c_close . fromIntegral . controlEventFd $ w #else@@ -200,9 +206,5 @@    c_eventfd_write :: CInt -> CULLong -> IO CInt #endif --- Used to tell the RTS how it can send messages to the I/O manager.-foreign import ccall "setIOManagerControlFd"-   c_setIOManagerControlFd :: CInt -> IO ()--foreign import ccall "setIOManagerWakeupFd"+foreign import ccall unsafe "setIOManagerWakeupFd"    c_setIOManagerWakeupFd :: CInt -> IO ()
GHC/Event/EPoll.hsc view
@@ -38,10 +38,7 @@  #include <sys/epoll.h> -import Control.Monad (when) import Data.Bits (Bits, FiniteBits, (.|.), (.&.))-import Data.Maybe (Maybe(..))-import Data.Monoid (Monoid(..)) import Data.Word (Word32) import Foreign.C.Error (eNOENT, getErrno, throwErrno,                         throwErrnoIfMinus1, throwErrnoIfMinus1_)@@ -170,7 +167,7 @@  , epollOut = EPOLLOUT  , epollErr = EPOLLERR  , epollHup = EPOLLHUP- , epollOneShot = EPOLLONESHOT              + , epollOneShot = EPOLLONESHOT  }  -- | Create a new epoll context, returning a file descriptor associated with the context.
GHC/Event/IntTable.hs view
@@ -1,4 +1,5 @@-{-# LANGUAGE BangPatterns, NoImplicitPrelude, RecordWildCards, Trustworthy #-}+{-# LANGUAGE Trustworthy #-}+{-# LANGUAGE BangPatterns, NoImplicitPrelude, RecordWildCards #-} {-# OPTIONS_GHC -fno-warn-name-shadowing #-}  module GHC.Event.IntTable@@ -12,13 +13,12 @@     , updateWith     ) where -import Control.Monad ((=<<), liftM, unless, when) import Data.Bits ((.&.), shiftL, shiftR) import Data.IORef (IORef, newIORef, readIORef, writeIORef)-import Data.Maybe (Maybe(..), isJust)+import Data.Maybe (Maybe(..), isJust, isNothing) import Foreign.ForeignPtr (ForeignPtr, mallocForeignPtr, withForeignPtr) import Foreign.Storable (peek, poke)-import GHC.Base (Monad(..), ($), const, otherwise)+import GHC.Base (Monad(..), (=<<), ($), const, liftM, otherwise, when) import GHC.Classes (Eq(..), Ord(..)) import GHC.Event.Arr (Arr) import GHC.Num (Num(..))@@ -82,6 +82,9 @@   withForeignPtr (tabSize newit) $ \ptr -> poke ptr size   writeIORef ref newit +-- | @insertWith f k v table@ inserts @k@ into @table@ with value @v@.+-- If @k@ already appears in @table@ with value @v0@, the value is updated+-- to @f v0 v@ and @Just v0@ is returned. insertWith :: (a -> a -> a) -> Int -> a -> IntTable a -> IO (Maybe a) insertWith f k v inttable@(IntTable ref) = do   it@IT{..} <- readIORef ref@@ -114,6 +117,7 @@ indexOf :: Int -> IT a -> Int indexOf k IT{..} = k .&. (Arr.size tabArr - 1) +-- | Remove the given key from the table and return its associated value. delete :: Int -> IntTable a -> IO (Maybe a) delete k t = updateWith (const Nothing) k t @@ -134,7 +138,7 @@   (fbv, oldVal, newBucket) <- go False `liftM` Arr.read tabArr idx   when (isJust oldVal) $ do     Arr.write tabArr idx newBucket-    unless (isJust fbv) $+    when (isNothing fbv) $       withForeignPtr tabSize $ \ptr -> do         size <- peek ptr         poke ptr (size - 1)
GHC/Event/Internal.hs view
@@ -16,6 +16,12 @@     , evtWrite     , evtClose     , eventIs+    -- * Lifetimes+    , Lifetime(..)+    , EventLifetime+    , eventLifetime+    , elLifetime+    , elEvent     -- * Timeout type     , Timeout(..)     -- * Helpers@@ -23,15 +29,12 @@     ) where  import Data.Bits ((.|.), (.&.))-import Data.List (foldl', intercalate)-import Data.Maybe (Maybe(..))-import Data.Monoid (Monoid(..))+import Data.OldList (foldl', filter, intercalate, null) import Foreign.C.Error (eINTR, getErrno, throwErrno) import System.Posix.Types (Fd) import GHC.Base import GHC.Num (Num(..)) import GHC.Show (Show(..))-import GHC.List (filter, null)  -- | An I\/O event. newtype Event = Event Int@@ -80,6 +83,46 @@ evtConcat = foldl' evtCombine evtNothing {-# INLINE evtConcat #-} +-- | The lifetime of a registration.+data Lifetime = OneShot | MultiShot+              deriving (Show, Eq)++-- | The longer of two lifetimes.+elSupremum :: Lifetime -> Lifetime -> Lifetime+elSupremum OneShot OneShot = OneShot+elSupremum _       _       = MultiShot+{-# INLINE elSupremum #-}++instance Monoid Lifetime where+    mempty = OneShot+    mappend = elSupremum++-- | A pair of an event and lifetime+--+-- Here we encode the event in the bottom three bits and the lifetime+-- in the fourth bit.+newtype EventLifetime = EL Int+                      deriving (Show, Eq)++instance Monoid EventLifetime where+    mempty = EL 0+    EL a `mappend` EL b = EL (a .|. b)++eventLifetime :: Event -> Lifetime -> EventLifetime+eventLifetime (Event e) l = EL (e .|. lifetimeBit l)+  where+    lifetimeBit OneShot   = 0+    lifetimeBit MultiShot = 8+{-# INLINE eventLifetime #-}++elLifetime :: EventLifetime -> Lifetime+elLifetime (EL x) = if x .&. 8 == 0 then OneShot else MultiShot+{-# INLINE elLifetime #-}++elEvent :: EventLifetime -> Event+elEvent (EL x) = Event (x .&. 0x7)+{-# INLINE elEvent #-}+ -- | A type alias for timeouts, specified in seconds. data Timeout = Timeout {-# UNPACK #-} !Double              | Forever@@ -104,6 +147,8 @@                   -> Event    -- new events to watch for ('mempty' to delete)                   -> IO Bool +    -- | Register interest in new events on a given file descriptor, set+    -- to be deactivated after the first event.     , _beModifyFdOnce :: a                          -> Fd    -- file descriptor                          -> Event -- new events to watch
GHC/Event/KQueue.hsc view
@@ -26,10 +26,7 @@ {-# INLINE available #-} #else -import Control.Monad (when) import Data.Bits (Bits(..), FiniteBits(..))-import Data.Maybe (Maybe(..))-import Data.Monoid (Monoid(..)) import Data.Word (Word16, Word32) import Foreign.C.Error (throwErrnoIfMinus1, eINTR, eINVAL,                         eNOTSUP, getErrno, throwErrno)
GHC/Event/Manager.hs view
@@ -7,6 +7,17 @@            , TypeSynonymInstances            , FlexibleInstances   #-}++-- |+-- The event manager supports event notification on fds. Each fd may+-- have multiple callbacks registered, each listening for a different+-- set of events. Registrations may be automatically deactivated after+-- the occurrence of an event ("one-shot mode") or active until+-- explicitly unregistered.+--+-- If an fd has only one-shot registrations then we use one-shot+-- polling if available. Otherwise we use multi-shot polling.+ module GHC.Event.Manager     ( -- * Types       EventManager@@ -27,15 +38,16 @@        -- * State     , callbackTableVar+    , emControl        -- * Registering interest in I/O events+    , Lifetime (..)     , Event     , evtRead     , evtWrite     , IOCallback     , FdKey(keyFd)     , FdData-    , registerFd_     , registerFd     , unregisterFd_     , unregisterFd@@ -48,27 +60,27 @@ ------------------------------------------------------------------------ -- Imports -import Control.Concurrent.MVar (MVar, newMVar, readMVar, putMVar,+import Control.Concurrent.MVar (MVar, newMVar, putMVar,                                 tryPutMVar, takeMVar, withMVar) import Control.Exception (onException)-import Control.Monad ((=<<), forM_, liftM, when, replicateM, void) import Data.Bits ((.&.))+import Data.Foldable (forM_)+import Data.Functor (void) import Data.IORef (IORef, atomicModifyIORef', mkWeakIORef, newIORef, readIORef,                    writeIORef)-import Data.Maybe (Maybe(..), maybe)-import Data.Monoid (mappend, mconcat, mempty)+import Data.Maybe (maybe)+import Data.OldList (partition) import GHC.Arr (Array, (!), listArray) import GHC.Base-import GHC.Conc.Signal (runHandlers) import GHC.Conc.Sync (yield)-import GHC.List (filter)+import GHC.List (filter, replicate) import GHC.Num (Num(..)) import GHC.Real (fromIntegral) import GHC.Show (Show(..)) import GHC.Event.Control import GHC.Event.IntTable (IntTable) import GHC.Event.Internal (Backend, Event, evtClose, evtRead, evtWrite,-                           Timeout(..))+                           Lifetime(..), EventLifetime, Timeout(..)) import GHC.Event.Unique (Unique, UniqueSource, newSource, newUnique) import System.Posix.Types (Fd) @@ -90,7 +102,7 @@  data FdData = FdData {       fdKey       :: {-# UNPACK #-} !FdKey-    , fdEvents    :: {-# UNPACK #-} !Event+    , fdEvents    :: {-# UNPACK #-} !EventLifetime     , _fdCallback :: !IOCallback     } @@ -117,7 +129,6 @@     , emState        :: {-# UNPACK #-} !(IORef State)     , emUniqueSource :: {-# UNPACK #-} !UniqueSource     , emControl      :: {-# UNPACK #-} !Control-    , emOneShot      :: !Bool     , emLock         :: {-# UNPACK #-} !(MVar ())     } @@ -151,7 +162,7 @@   case msg of     CMsgWakeup      -> return ()     CMsgDie         -> writeIORef (emState mgr) Finished-    CMsgSignal fp s -> runHandlers fp s+    _               -> return ()  newDefaultBackend :: IO Backend #if defined(HAVE_KQUEUE)@@ -165,11 +176,12 @@ #endif  -- | Create a new event manager.-new :: Bool -> IO EventManager-new oneShot = newWith oneShot =<< newDefaultBackend+new :: IO EventManager+new = newWith =<< newDefaultBackend -newWith :: Bool -> Backend -> IO EventManager-newWith oneShot be = do+-- | Create a new 'EventManager' with the given polling backend.+newWith :: Backend -> IO EventManager+newWith be = do   iofds <- fmap (listArray (0, callbackArraySize-1)) $            replicateM callbackArraySize (newMVar =<< IT.new 8)   ctrl <- newControl False@@ -186,12 +198,13 @@                          , emState = state                          , emUniqueSource = us                          , emControl = ctrl-                         , emOneShot = oneShot                          , emLock = lockVar                          }   registerControlFd mgr (controlReadFd ctrl) evtRead   registerControlFd mgr (wakeupReadFd ctrl) evtRead   return mgr+  where+    replicateM n x = sequence (replicate n x)  failOnInvalidFile :: String -> Fd -> IO Bool -> IO () failOnInvalidFile loc fd m = do@@ -292,52 +305,53 @@ -- | Register interest in the given events, without waking the event -- manager thread.  The 'Bool' return value indicates whether the -- event manager ought to be woken.-registerFd_ :: EventManager -> IOCallback -> Fd -> Event+registerFd_ :: EventManager -> IOCallback -> Fd -> Event -> Lifetime             -> IO (FdKey, Bool)-registerFd_ mgr@(EventManager{..}) cb fd evs = do+registerFd_ mgr@(EventManager{..}) cb fd evs lt = do   u <- newUnique emUniqueSource   let fd'  = fromIntegral fd       reg  = FdKey fd u-      !fdd = FdData reg evs cb-  (modify,ok) <- withMVar (callbackTableVar mgr fd) $ \tbl ->-    if haveOneShot && emOneShot-    then do-      oldFdd <- IT.insertWith (++) fd' [fdd] tbl-      let evs' = maybe evs (combineEvents evs) oldFdd-      ok <- I.modifyFdOnce emBackend fd evs'-      if ok-        then return (False, True)-        else IT.reset fd' oldFdd tbl >> return (False, False)-    else do-      oldFdd <- IT.insertWith (++) fd' [fdd] tbl-      let (oldEvs, newEvs) =-            case oldFdd of-              Nothing   -> (mempty, evs)-              Just prev -> (eventsOf prev, combineEvents evs prev)-          modify = oldEvs /= newEvs-      ok <- if modify-            then I.modifyFd emBackend fd oldEvs newEvs-            else return True-      if ok-        then return (modify, True)-        else IT.reset fd' oldFdd tbl >> return (False, False)+      el = I.eventLifetime evs lt+      !fdd = FdData reg el cb+  (modify,ok) <- withMVar (callbackTableVar mgr fd) $ \tbl -> do+    oldFdd <- IT.insertWith (++) fd' [fdd] tbl+    let prevEvs :: EventLifetime+        prevEvs = maybe mempty eventsOf oldFdd++        el' :: EventLifetime+        el' = prevEvs `mappend` el+    case I.elLifetime el' of+      -- All registrations want one-shot semantics and this is supported+      OneShot | haveOneShot -> do+        ok <- I.modifyFdOnce emBackend fd (I.elEvent el')+        if ok+          then return (False, True)+          else IT.reset fd' oldFdd tbl >> return (False, False)++      -- We don't want or don't support one-shot semantics+      _ -> do+        let modify = prevEvs /= el'+        ok <- if modify+              then let newEvs = I.elEvent el'+                       oldEvs = I.elEvent prevEvs+                   in I.modifyFd emBackend fd oldEvs newEvs+              else return True+        if ok+          then return (modify, True)+          else IT.reset fd' oldFdd tbl >> return (False, False)   -- this simulates behavior of old IO manager:   -- i.e. just call the callback if the registration fails.   when (not ok) (cb reg evs)   return (reg,modify) {-# INLINE registerFd_ #-} -combineEvents :: Event -> [FdData] -> Event-combineEvents ev [fdd] = mappend ev (fdEvents fdd)-combineEvents ev fdds  = mappend ev (eventsOf fdds)-{-# INLINE combineEvents #-}---- | @registerFd mgr cb fd evs@ registers interest in the events @evs@--- on the file descriptor @fd@.  @cb@ is called for each event that--- occurs.  Returns a cookie that can be handed to 'unregisterFd'.-registerFd :: EventManager -> IOCallback -> Fd -> Event -> IO FdKey-registerFd mgr cb fd evs = do-  (r, wake) <- registerFd_ mgr cb fd evs+-- | @registerFd mgr cb fd evs lt@ registers interest in the events @evs@+-- on the file descriptor @fd@ for lifetime @lt@. @cb@ is called for+-- each event that occurs.  Returns a cookie that can be handed to+-- 'unregisterFd'.+registerFd :: EventManager -> IOCallback -> Fd -> Event -> Lifetime -> IO FdKey+registerFd mgr cb fd evs lt = do+  (r, wake) <- registerFd_ mgr cb fd evs lt   when wake $ wakeManager mgr   return r {-# INLINE registerFd #-}@@ -349,7 +363,7 @@     when we register an event.      For more information, please read:-        http://hackage.haskell.org/trac/ghc/ticket/7651+        http://ghc.haskell.org/trac/ghc/ticket/7651 -} -- | Wake up the event manager. wakeManager :: EventManager -> IO ()@@ -361,8 +375,9 @@ wakeManager mgr = sendWakeup (emControl mgr) #endif -eventsOf :: [FdData] -> Event-eventsOf = mconcat . map fdEvents+eventsOf :: [FdData] -> EventLifetime+eventsOf [fdd] = fdEvents fdd+eventsOf fdds  = mconcat $ map fdEvents fdds  -- | Drop a previous file descriptor registration, without waking the -- event manager thread.  The return value indicates whether the event@@ -372,16 +387,19 @@   withMVar (callbackTableVar mgr fd) $ \tbl -> do     let dropReg = nullToNothing . filter ((/= u) . keyUnique . fdKey)         fd' = fromIntegral fd+        pairEvents :: [FdData] -> IO (EventLifetime, EventLifetime)         pairEvents prev = do           r <- maybe mempty eventsOf `fmap` IT.lookup fd' tbl           return (eventsOf prev, r)-    (oldEvs, newEvs) <- IT.updateWith dropReg fd' tbl >>=+    (oldEls, newEls) <- IT.updateWith dropReg fd' tbl >>=                         maybe (return (mempty, mempty)) pairEvents-    let modify = oldEvs /= newEvs+    let modify = oldEls /= newEls     when modify $ failOnInvalidFile "unregisterFd_" fd $-      if haveOneShot && emOneShot && newEvs /= mempty-      then I.modifyFdOnce emBackend fd newEvs-      else I.modifyFd emBackend fd oldEvs newEvs+      case I.elLifetime newEls of+        OneShot | I.elEvent newEls /= mempty, haveOneShot ->+          I.modifyFdOnce emBackend fd (I.elEvent newEls)+        _ ->+          I.modifyFd emBackend fd (I.elEvent oldEls) (I.elEvent newEls)     return modify  -- | Drop a previous file descriptor registration.@@ -398,13 +416,13 @@     case prev of       Nothing  -> close fd >> return []       Just fds -> do-        let oldEvs = eventsOf fds-        when (oldEvs /= mempty) $ do-          _ <- I.modifyFd (emBackend mgr) fd oldEvs mempty+        let oldEls = eventsOf fds+        when (I.elEvent oldEls /= mempty) $ do+          _ <- I.modifyFd (emBackend mgr) fd (I.elEvent oldEls) mempty           wakeManager mgr         close fd         return fds-  forM_ fds $ \(FdData reg ev cb) -> cb reg (ev `mappend` evtClose)+  forM_ fds $ \(FdData reg el cb) -> cb reg (I.elEvent el `mappend` evtClose)  -- | Close a file descriptor in a race-safe way. -- It assumes the caller will update the callback tables and that the caller@@ -419,63 +437,63 @@   case prev of     Nothing  -> return (return ())     Just fds -> do-      let oldEvs = eventsOf fds-      when (oldEvs /= mempty) $ do-        _ <- I.modifyFd (emBackend mgr) fd oldEvs mempty+      let oldEls = eventsOf fds+      when (oldEls /= mempty) $ do+        _ <- I.modifyFd (emBackend mgr) fd (I.elEvent oldEls) mempty         wakeManager mgr       return $-        forM_ fds $ \(FdData reg ev cb) -> cb reg (ev `mappend` evtClose)+        forM_ fds $ \(FdData reg el cb) ->+          cb reg (I.elEvent el `mappend` evtClose)  ------------------------------------------------------------------------ -- Utilities  -- | Call the callbacks corresponding to the given file descriptor. onFdEvent :: EventManager -> Fd -> Event -> IO ()-onFdEvent mgr fd evs =-  if fd == controlReadFd (emControl mgr) || fd == wakeupReadFd (emControl mgr)-  then handleControlEvent mgr fd evs-  else-    if emOneShot mgr-    then-      do fdds <- withMVar (callbackTableVar mgr fd) $ \tbl ->-           IT.delete fd' tbl >>=-           maybe (return []) (selectCallbacks tbl)-         forM_ fdds $ \(FdData reg _ cb) -> cb reg evs-    else-      do found <- IT.lookup fd' =<< readMVar (callbackTableVar mgr fd)-         case found of-           Just cbs -> forM_ cbs $ \(FdData reg ev cb) -> do-             when (evs `I.eventIs` ev) $ cb reg evs-           Nothing  -> return ()+onFdEvent mgr fd evs+  | fd == controlReadFd (emControl mgr) || fd == wakeupReadFd (emControl mgr) =+    handleControlEvent mgr fd evs++  | otherwise = do+    fdds <- withMVar (callbackTableVar mgr fd) $ \tbl ->+        IT.delete (fromIntegral fd) tbl >>= maybe (return []) selectCallbacks+    forM_ fdds $ \(FdData reg _ cb) -> cb reg evs   where-    fd' :: Int-    fd' = fromIntegral fd+    -- | Here we look through the list of registrations for the fd of interest+    -- and sort out which match the events that were triggered. We re-arm+    -- the fd as appropriate and return this subset.+    selectCallbacks :: [FdData] -> IO [FdData]+    selectCallbacks fdds = do+        let matches :: FdData -> Bool+            matches fd' = evs `I.eventIs` I.elEvent (fdEvents fd')+            (triggered, saved) = partition matches fdds+            savedEls = eventsOf saved+            allEls = eventsOf fdds -    selectCallbacks :: IntTable [FdData] -> [FdData] -> IO [FdData]-    selectCallbacks tbl cbs = aux cbs [] []-      where-        -- nothing to rearm.-        aux [] _    []          =-          if haveOneShot-          then return cbs-          else do _ <- I.modifyFd (emBackend mgr) fd (eventsOf cbs) mempty-                  return cbs+        case I.elLifetime allEls of+          -- we previously armed the fd for multiple shots, no need to rearm+          MultiShot | allEls == savedEls ->+            return () -        -- reinsert and rearm; note that we already have the lock on the-        -- callback table for this fd, and we deleted above, so we know there-        -- is no entry in the table for this fd.-        aux [] fdds saved@(_:_) = do-          _ <- if haveOneShot-               then I.modifyFdOnce (emBackend mgr) fd $ eventsOf saved-               else I.modifyFd (emBackend mgr) fd (eventsOf cbs) $ eventsOf saved-          _ <- IT.insertWith (\_ _ -> saved) fd' saved tbl-          return fdds+          -- either we previously registered for one shot or the+          -- events of interest have changed, we must re-arm+          _ -> do+            case I.elLifetime savedEls of+              OneShot | haveOneShot ->+                -- if there are no saved events there is no need to re-arm+                unless (OneShot == I.elLifetime (eventsOf triggered)+                        && mempty == savedEls) $+                  void $ I.modifyFdOnce (emBackend mgr) fd (I.elEvent savedEls)+              _ ->+                void $ I.modifyFd (emBackend mgr) fd+                                  (I.elEvent allEls) (I.elEvent savedEls)+            return () -        -- continue, saving those callbacks that don't match the event-        aux (fdd@(FdData _ evs' _) : cbs') fdds saved-          | evs `I.eventIs` evs' = aux cbs' (fdd:fdds) saved-          | otherwise            = aux cbs' fdds (fdd:saved)+        return triggered  nullToNothing :: [a] -> Maybe [a] nullToNothing []       = Nothing nullToNothing xs@(_:_) = Just xs++unless :: Monad m => Bool -> m () -> m ()+unless p = when (not p)
GHC/Event/PSQ.hs view
@@ -88,8 +88,7 @@     , atMost     ) where -import Data.Maybe (Maybe(..))-import GHC.Base+import GHC.Base hiding (empty) import GHC.Num (Num(..)) import GHC.Show (Show(showsPrec)) import GHC.Event.Unique (Unique)
GHC/Event/Poll.hsc view
@@ -14,6 +14,7 @@  #if !defined(HAVE_POLL_H) import GHC.Base+import qualified GHC.Event.Internal as E  new :: IO E.Backend new = error "Poll back end not implemented for this platform"@@ -25,10 +26,7 @@ #include <poll.h>  import Control.Concurrent.MVar (MVar, newMVar, swapMVar)-import Control.Monad ((=<<), liftM, liftM2, unless) import Data.Bits (Bits, FiniteBits, (.|.), (.&.))-import Data.Maybe (Maybe(..))-import Data.Monoid (Monoid(..)) import Data.Word import Foreign.C.Types (CInt(..), CShort(..)) import Foreign.Ptr (Ptr)@@ -94,7 +92,7 @@         c_pollLoop ptr (fromIntegral len) (fromTimeout tout)       Nothing   ->         c_poll_unsafe ptr (fromIntegral len) 0-  unless (n == 0) $ do+  when (n /= 0) $ do     A.loop a 0 $ \i e -> do       let r = pfdRevents e       if r /= 0@@ -114,12 +112,17 @@     -- expired) OR the full timeout has passed.     c_pollLoop :: Ptr PollFd -> (#type nfds_t) -> Int -> IO CInt     c_pollLoop ptr len tout-        | tout <= maxPollTimeout = c_poll ptr len (fromIntegral tout)+        | isShortTimeout = c_poll ptr len (fromIntegral tout)         | otherwise = do             result <- c_poll ptr len (fromIntegral maxPollTimeout)             if result == 0                then c_pollLoop ptr len (fromIntegral (tout - maxPollTimeout))                else return result+        where+          -- maxPollTimeout is smaller than 0 IFF Int is smaller than CInt.+          -- This means any possible Int input to poll can be safely directly+          -- converted to CInt.+          isShortTimeout = tout <= maxPollTimeout || maxPollTimeout < 0      -- We need to account for 3 cases:     --     1. Int and CInt are of equal size.@@ -133,11 +136,10 @@     -- c_pollLoop recursing if the provided timeout is larger.     --     -- In case 3, "fromIntegral (maxBound :: CInt) :: Int" will result in a-    -- negative Int, max will thus return maxBound :: Int. Since poll doesn't-    -- accept values bigger than maxBound :: Int and CInt is larger than Int,-    -- there is no problem converting Int to CInt for the c_poll call.+    -- negative Int. This will cause isShortTimeout to be true and result in+    -- the timeout being directly converted to a CInt.     maxPollTimeout :: Int-    maxPollTimeout = max maxBound (fromIntegral (maxBound :: CInt))+    maxPollTimeout = fromIntegral (maxBound :: CInt)  fromTimeout :: E.Timeout -> Int fromTimeout E.Forever     = -1
GHC/Event/Thread.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE Trustworthy #-} {-# LANGUAGE BangPatterns, NoImplicitPrelude #-}+ module GHC.Event.Thread     ( getSystemEventManager     , getSystemTimerManager@@ -12,17 +13,18 @@     , closeFdWith     , threadDelay     , registerDelay+    , blockedOnBadFD -- used by RTS     ) where -import Control.Exception (finally)-import Control.Monad (forM, forM_, sequence_, zipWithM, when)+import Control.Exception (finally, SomeException, toException)+import Data.Foldable (forM_, mapM_, sequence_) import Data.IORef (IORef, newIORef, readIORef, writeIORef)-import Data.List (zipWith3)-import Data.Maybe (Maybe(..)) import Data.Tuple (snd) import Foreign.C.Error (eBADF, errnoToIOError)+import Foreign.C.Types (CInt(..), CUInt(..)) import Foreign.Ptr (Ptr) import GHC.Base+import GHC.List (zipWith, zipWith3) import GHC.Conc.Sync (TVar, ThreadId, ThreadStatus(..), atomically, forkIO,                       labelThread, modifyMVar_, withMVar, newTVar, sharedCAF,                       getNumCapabilities, threadCapability, myThreadId, forkOn,@@ -32,12 +34,15 @@ import GHC.IOArray (IOArray, newIOArray, readIOArray, writeIOArray,                     boundsIOArray) import GHC.MVar (MVar, newEmptyMVar, newMVar, putMVar, takeMVar)+import GHC.Event.Control (controlWriteFd) import GHC.Event.Internal (eventIs, evtClose) import GHC.Event.Manager (Event, EventManager, evtRead, evtWrite, loop,                              new, registerFd, unregisterFd_) import qualified GHC.Event.Manager as M import qualified GHC.Event.TimerManager as TM import GHC.Num ((-), (+))+import GHC.Real (fromIntegral)+import GHC.Show (showSignedInt) import System.IO.Unsafe (unsafePerformIO) import System.Posix.Types (Fd) @@ -95,32 +100,36 @@ closeFdWith close fd = do   eventManagerArray <- readIORef eventManager   let (low, high) = boundsIOArray eventManagerArray-  mgrs <- forM [low..high] $ \i -> do+  mgrs <- flip mapM [low..high] $ \i -> do     Just (_,!mgr) <- readIOArray eventManagerArray i     return mgr   mask_ $ do-    tables <- forM mgrs $ \mgr -> takeMVar $ M.callbackTableVar mgr fd+    tables <- flip mapM mgrs $ \mgr -> takeMVar $ M.callbackTableVar mgr fd     cbApps <- zipWithM (\mgr table -> M.closeFd_ mgr table fd) mgrs tables     close fd `finally` sequence_ (zipWith3 finish mgrs tables cbApps)   where     finish mgr table cbApp = putMVar (M.callbackTableVar mgr fd) table >> cbApp+    zipWithM f xs ys = sequence (zipWith f xs ys)  threadWait :: Event -> Fd -> IO () threadWait evt fd = mask_ $ do   m <- newEmptyMVar   mgr <- getSystemEventManager_-  reg <- registerFd mgr (\_ e -> putMVar m e) fd evt+  reg <- registerFd mgr (\_ e -> putMVar m e) fd evt M.OneShot   evt' <- takeMVar m `onException` unregisterFd_ mgr reg   if evt' `eventIs` evtClose     then ioError $ errnoToIOError "threadWait" eBADF Nothing Nothing     else return () +-- used at least by RTS in 'select()' IO manager backend+blockedOnBadFD :: SomeException+blockedOnBadFD = toException $ errnoToIOError "awaitEvent" eBADF Nothing Nothing  threadWaitSTM :: Event -> Fd -> IO (STM (), IO ()) threadWaitSTM evt fd = mask_ $ do   m <- newTVarIO Nothing   mgr <- getSystemEventManager_-  reg <- registerFd mgr (\_ e -> atomically (writeTVar m (Just e))) fd evt+  reg <- registerFd mgr (\_ e -> atomically (writeTVar m (Just e))) fd evt M.OneShot   let waitAction =         do mevt <- readTVar m            case mevt of@@ -237,14 +246,17 @@   withMVar ioManagerLock $ \_ -> do     eventManagerArray <- readIORef eventManager     let (_, high) = boundsIOArray eventManagerArray-    forM_ [0..high] (startIOManagerThread eventManagerArray)+    mapM_ (startIOManagerThread eventManagerArray) [0..high]     writeIORef numEnabledEventManagers (high+1) +show_int :: Int -> String+show_int i = showSignedInt 0 i ""+ restartPollLoop :: EventManager -> Int -> IO ThreadId restartPollLoop mgr i = do   M.release mgr   !t <- forkOn i $ loop mgr-  labelThread t "IOManager"+  labelThread t ("IOManager on cap " ++ show_int i)   return t  startIOManagerThread :: IOArray Int (Maybe (ThreadId, EventManager))@@ -252,9 +264,13 @@                         -> IO () startIOManagerThread eventManagerArray i = do   let create = do-        !mgr <- new True-        !t <- forkOn i $ loop mgr-        labelThread t "IOManager"+        !mgr <- new+        !t <- forkOn i $ do+                c_setIOManagerControlFd+                  (fromIntegral i)+                  (fromIntegral $ controlWriteFd $ M.emControl mgr)+                loop mgr+        labelThread t ("IOManager on cap " ++ show_int i)         writeIOArray eventManagerArray i (Just (t,mgr))   old <- readIOArray eventManagerArray i   case old of@@ -269,6 +285,7 @@           -- the fork, for example. In this case we should clean up           -- open pipes and everything else related to the event manager.           -- See #4449+          c_setIOManagerControlFd (fromIntegral i) (-1)           M.cleanup em           create         _other         -> return ()@@ -277,8 +294,10 @@ startTimerManagerThread = modifyMVar_ timerManagerThreadVar $ \old -> do   let create = do         !mgr <- TM.new+        c_setTimerManagerControlFd+          (fromIntegral $ controlWriteFd $ TM.emControl mgr)         writeIORef timerManager $ Just mgr-        !t <- forkIO $ TM.loop mgr `finally` shutdownManagers+        !t <- forkIO $ TM.loop mgr         labelThread t "TimerManager"         return $ Just t   case old of@@ -296,21 +315,11 @@           mem <- readIORef timerManager           _ <- case mem of                  Nothing -> return ()-                 Just em -> TM.cleanup em+                 Just em -> do c_setTimerManagerControlFd (-1)+                               TM.cleanup em           create         _other         -> return st -shutdownManagers :: IO ()-shutdownManagers =-  withMVar ioManagerLock $ \_ -> do-    eventManagerArray <- readIORef eventManager-    let (_, high) = boundsIOArray eventManagerArray-    forM_ [0..high] $ \i -> do-      mmgr <- readIOArray eventManagerArray i-      case mmgr of-        Nothing -> return ()-        Just (_,mgr) -> M.shutdown mgr- foreign import ccall unsafe "rtsSupportsBoundThreads" threaded :: Bool  ioManagerCapabilitiesChanged :: IO ()@@ -344,3 +353,10 @@               Just (_,mgr) <- readIOArray eventManagerArray i               tid <- restartPollLoop mgr i               writeIOArray eventManagerArray i (Just (tid,mgr))++-- Used to tell the RTS how it can send messages to the I/O manager.+foreign import ccall unsafe "setIOManagerControlFd"+   c_setIOManagerControlFd :: CUInt -> CInt -> IO ()++foreign import ccall unsafe "setTimerManagerControlFd"+   c_setTimerManagerControlFd :: CInt -> IO ()
GHC/Event/TimerManager.hs view
@@ -15,6 +15,7 @@     , new     , newWith     , newDefaultBackend+    , emControl        -- * Running     , finished@@ -38,11 +39,9 @@ -- Imports  import Control.Exception (finally)-import Control.Monad ((=<<), liftM, sequence_, when)+import Data.Foldable (sequence_) import Data.IORef (IORef, atomicModifyIORef', mkWeakIORef, newIORef, readIORef,                    writeIORef)-import Data.Maybe (Maybe(..))-import Data.Monoid (mempty) import GHC.Base import GHC.Conc.Signal (runHandlers) import GHC.Num (Num(..))@@ -81,32 +80,6 @@  -- | A priority search queue, with timeouts as priorities. type TimeoutQueue = Q.PSQ TimeoutCallback--{--Instead of directly modifying the 'TimeoutQueue' in-e.g. 'registerTimeout' we keep a list of edits to perform, in the form-of a chain of function closures, and have the I/O manager thread-perform the edits later.  This exist to address the following GC-problem:--Since e.g. 'registerTimeout' doesn't force the evaluation of the-thunks inside the 'emTimeouts' IORef a number of thunks build up-inside the IORef.  If the I/O manager thread doesn't evaluate these-thunks soon enough they'll get promoted to the old generation and-become roots for all subsequent minor GCs.--When the thunks eventually get evaluated they will each create a new-intermediate 'TimeoutQueue' that immediately becomes garbage.  Since-the thunks serve as roots until the next major GC these intermediate-'TimeoutQueue's will get copied unnecesarily in the next minor GC,-increasing GC time.  This problem is known as "floating garbage".--Keeping a list of edits doesn't stop this from happening but makes the-amount of data that gets copied smaller.--TODO: Evaluate the content of the IORef to WHNF on each insert once-this bug is resolved: http://hackage.haskell.org/trac/ghc/ticket/3838--}  -- | An edit to apply to a 'TimeoutQueue'. type TimeoutEdit = TimeoutQueue -> TimeoutQueue
GHC/Event/Unique.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE Trustworthy #-} {-# LANGUAGE BangPatterns, GeneralizedNewtypeDeriving, NoImplicitPrelude #-}+ module GHC.Event.Unique     (       UniqueSource@@ -17,7 +18,7 @@ -- We used to use IORefs here, but Simon switched us to STM when we -- found that our use of atomicModifyIORef was subject to a severe RTS -- performance problem when used in a tight loop from multiple--- threads: http://hackage.haskell.org/trac/ghc/ticket/3838+-- threads: http://ghc.haskell.org/trac/ghc/ticket/3838 -- -- There seems to be no performance cost to using a TVar instead. 
+ GHC/Exception.hs view
@@ -0,0 +1,197 @@+{-# LANGUAGE Trustworthy #-}+{-# LANGUAGE NoImplicitPrelude+           , ExistentialQuantification+           , MagicHash+           , DeriveDataTypeable+  #-}+{-# OPTIONS_HADDOCK hide #-}++-----------------------------------------------------------------------------+-- |+-- Module      :  GHC.Exception+-- Copyright   :  (c) The University of Glasgow, 1998-2002+-- License     :  see libraries/base/LICENSE+--+-- Maintainer  :  cvs-ghc@haskell.org+-- Stability   :  internal+-- Portability :  non-portable (GHC extensions)+--+-- Exceptions and exception-handling functions.+--+-----------------------------------------------------------------------------++module GHC.Exception+       ( Exception(..)    -- Class+       , throw+       , SomeException(..), ErrorCall(..), ArithException(..)+       , divZeroException, overflowException, ratioZeroDenomException+       , errorCallException+       ) where++import Data.Maybe+import Data.Typeable (Typeable, cast)+   -- loop: Data.Typeable -> GHC.Err -> GHC.Exception+import GHC.Base+import GHC.Show++{- |+The @SomeException@ type is the root of the exception type hierarchy.+When an exception of type @e@ is thrown, behind the scenes it is+encapsulated in a @SomeException@.+-}+data SomeException = forall e . Exception e => SomeException e+    deriving Typeable++instance Show SomeException where+    showsPrec p (SomeException e) = showsPrec p e++{- |+Any type that you wish to throw or catch as an exception must be an+instance of the @Exception@ class. The simplest case is a new exception+type directly below the root:++> data MyException = ThisException | ThatException+>     deriving (Show, Typeable)+>+> instance Exception MyException++The default method definitions in the @Exception@ class do what we need+in this case. You can now throw and catch @ThisException@ and+@ThatException@ as exceptions:++@+*Main> throw ThisException \`catch\` \\e -> putStrLn (\"Caught \" ++ show (e :: MyException))+Caught ThisException+@++In more complicated examples, you may wish to define a whole hierarchy+of exceptions:++> ---------------------------------------------------------------------+> -- Make the root exception type for all the exceptions in a compiler+>+> data SomeCompilerException = forall e . Exception e => SomeCompilerException e+>     deriving Typeable+>+> instance Show SomeCompilerException where+>     show (SomeCompilerException e) = show e+>+> instance Exception SomeCompilerException+>+> compilerExceptionToException :: Exception e => e -> SomeException+> compilerExceptionToException = toException . SomeCompilerException+>+> compilerExceptionFromException :: Exception e => SomeException -> Maybe e+> compilerExceptionFromException x = do+>     SomeCompilerException a <- fromException x+>     cast a+>+> ---------------------------------------------------------------------+> -- Make a subhierarchy for exceptions in the frontend of the compiler+>+> data SomeFrontendException = forall e . Exception e => SomeFrontendException e+>     deriving Typeable+>+> instance Show SomeFrontendException where+>     show (SomeFrontendException e) = show e+>+> instance Exception SomeFrontendException where+>     toException = compilerExceptionToException+>     fromException = compilerExceptionFromException+>+> frontendExceptionToException :: Exception e => e -> SomeException+> frontendExceptionToException = toException . SomeFrontendException+>+> frontendExceptionFromException :: Exception e => SomeException -> Maybe e+> frontendExceptionFromException x = do+>     SomeFrontendException a <- fromException x+>     cast a+>+> ---------------------------------------------------------------------+> -- Make an exception type for a particular frontend compiler exception+>+> data MismatchedParentheses = MismatchedParentheses+>     deriving (Typeable, Show)+>+> instance Exception MismatchedParentheses where+>     toException   = frontendExceptionToException+>     fromException = frontendExceptionFromException++We can now catch a @MismatchedParentheses@ exception as+@MismatchedParentheses@, @SomeFrontendException@ or+@SomeCompilerException@, but not other types, e.g. @IOException@:++@+*Main> throw MismatchedParentheses `catch` \e -> putStrLn (\"Caught \" ++ show (e :: MismatchedParentheses))+Caught MismatchedParentheses+*Main> throw MismatchedParentheses `catch` \e -> putStrLn (\"Caught \" ++ show (e :: SomeFrontendException))+Caught MismatchedParentheses+*Main> throw MismatchedParentheses `catch` \e -> putStrLn (\"Caught \" ++ show (e :: SomeCompilerException))+Caught MismatchedParentheses+*Main> throw MismatchedParentheses `catch` \e -> putStrLn (\"Caught \" ++ show (e :: IOException))+*** Exception: MismatchedParentheses+@++-}+class (Typeable e, Show e) => Exception e where+    toException   :: e -> SomeException+    fromException :: SomeException -> Maybe e++    toException = SomeException+    fromException (SomeException e) = cast e++    -- | Render this exception value in a human-friendly manner.+    --+    -- Default implementation: @'show'@.+    --+    -- @since 4.8.0.0+    displayException :: e -> String+    displayException = show++instance Exception SomeException where+    toException se = se+    fromException = Just+    displayException (SomeException e) = displayException e++-- | Throw an exception.  Exceptions may be thrown from purely+-- functional code, but may only be caught within the 'IO' monad.+throw :: Exception e => e -> a+throw e = raise# (toException e)++-- |This is thrown when the user calls 'error'. The @String@ is the+-- argument given to 'error'.+newtype ErrorCall = ErrorCall String+    deriving (Eq, Ord, Typeable)++instance Exception ErrorCall++instance Show ErrorCall where+    showsPrec _ (ErrorCall err) = showString err++errorCallException :: String -> SomeException+errorCallException s = toException (ErrorCall s)++-- |Arithmetic exceptions.+data ArithException+  = Overflow+  | Underflow+  | LossOfPrecision+  | DivideByZero+  | Denormal+  | RatioZeroDenominator -- ^ @since 4.6.0.0+  deriving (Eq, Ord, Typeable)++divZeroException, overflowException, ratioZeroDenomException  :: SomeException+divZeroException        = toException DivideByZero+overflowException       = toException Overflow+ratioZeroDenomException = toException RatioZeroDenominator++instance Exception ArithException++instance Show ArithException where+  showsPrec _ Overflow        = showString "arithmetic overflow"+  showsPrec _ Underflow       = showString "arithmetic underflow"+  showsPrec _ LossOfPrecision = showString "loss of precision"+  showsPrec _ DivideByZero    = showString "divide by zero"+  showsPrec _ Denormal        = showString "denormal"+  showsPrec _ RatioZeroDenominator = showString "Ratio has zero denominator"
+ GHC/Exception.hs-boot view
@@ -0,0 +1,34 @@+{-# LANGUAGE Trustworthy #-}+{-# LANGUAGE NoImplicitPrelude #-}++{-+This SOURCE-imported hs-boot module cuts a big dependency loop:++         GHC.Exception+imports  Data.Maybe+imports  GHC.Base+imports  GHC.Err+imports  {-# SOURCE #-} GHC.Exception++More dramatically++         GHC.Exception+imports  Data.Typeable+imports  Data.Typeable.Internals+imports  GHC.Arr (fingerprint representation etc)+imports  GHC.Real+imports  {-# SOURCE #-} GHC.Exception++However, GHC.Exceptions loop-breaking exports are all nice,+well-behaved, non-bottom values.  The clients use 'raise#'+to get a visibly-bottom value.+-}++module GHC.Exception ( SomeException, errorCallException,+                       divZeroException, overflowException, ratioZeroDenomException+    ) where+import GHC.Types( Char )++data SomeException+divZeroException, overflowException, ratioZeroDenomException  :: SomeException+errorCallException :: [Char] -> SomeException
− GHC/Exception.lhs
@@ -1,210 +0,0 @@-\begin{code}-{-# LANGUAGE Trustworthy #-}-{-# LANGUAGE NoImplicitPrelude-           , ExistentialQuantification-           , MagicHash-           , DeriveDataTypeable-  #-}-{-# OPTIONS_HADDOCK hide #-}---------------------------------------------------------------------------------- |--- Module      :  GHC.Exception--- Copyright   :  (c) The University of Glasgow, 1998-2002--- License     :  see libraries/base/LICENSE--- --- Maintainer  :  cvs-ghc@haskell.org--- Stability   :  internal--- Portability :  non-portable (GHC extensions)------ Exceptions and exception-handling functions.--- --------------------------------------------------------------------------------module GHC.Exception-       ( Exception(..)    -- Class-       , throw-       , SomeException(..), ErrorCall(..), ArithException(..)-       , divZeroException, overflowException, ratioZeroDenomException-       , errorCallException-       ) where--import Data.Maybe-import Data.Typeable (Typeable, cast)-   -- loop: Data.Typeable -> GHC.Err -> GHC.Exception-import GHC.Base-import GHC.Show-\end{code}--%*********************************************************-%*                                                      *-\subsection{Exceptions}-%*                                                      *-%*********************************************************--\begin{code}-{- |-The @SomeException@ type is the root of the exception type hierarchy.-When an exception of type @e@ is thrown, behind the scenes it is-encapsulated in a @SomeException@.--}-data SomeException = forall e . Exception e => SomeException e-    deriving Typeable--instance Show SomeException where-    showsPrec p (SomeException e) = showsPrec p e--{- |-Any type that you wish to throw or catch as an exception must be an-instance of the @Exception@ class. The simplest case is a new exception-type directly below the root:--> data MyException = ThisException | ThatException->     deriving (Show, Typeable)->-> instance Exception MyException--The default method definitions in the @Exception@ class do what we need-in this case. You can now throw and catch @ThisException@ and-@ThatException@ as exceptions:--@-*Main> throw ThisException \`catch\` \\e -> putStrLn (\"Caught \" ++ show (e :: MyException))-Caught ThisException-@--In more complicated examples, you may wish to define a whole hierarchy-of exceptions:--> ----------------------------------------------------------------------> -- Make the root exception type for all the exceptions in a compiler->-> data SomeCompilerException = forall e . Exception e => SomeCompilerException e->     deriving Typeable->-> instance Show SomeCompilerException where->     show (SomeCompilerException e) = show e->-> instance Exception SomeCompilerException->-> compilerExceptionToException :: Exception e => e -> SomeException-> compilerExceptionToException = toException . SomeCompilerException->-> compilerExceptionFromException :: Exception e => SomeException -> Maybe e-> compilerExceptionFromException x = do->     SomeCompilerException a <- fromException x->     cast a->-> ----------------------------------------------------------------------> -- Make a subhierarchy for exceptions in the frontend of the compiler->-> data SomeFrontendException = forall e . Exception e => SomeFrontendException e->     deriving Typeable->-> instance Show SomeFrontendException where->     show (SomeFrontendException e) = show e->-> instance Exception SomeFrontendException where->     toException = compilerExceptionToException->     fromException = compilerExceptionFromException->-> frontendExceptionToException :: Exception e => e -> SomeException-> frontendExceptionToException = toException . SomeFrontendException->-> frontendExceptionFromException :: Exception e => SomeException -> Maybe e-> frontendExceptionFromException x = do->     SomeFrontendException a <- fromException x->     cast a->-> ----------------------------------------------------------------------> -- Make an exception type for a particular frontend compiler exception->-> data MismatchedParentheses = MismatchedParentheses->     deriving (Typeable, Show)->-> instance Exception MismatchedParentheses where->     toException   = frontendExceptionToException->     fromException = frontendExceptionFromException--We can now catch a @MismatchedParentheses@ exception as-@MismatchedParentheses@, @SomeFrontendException@ or-@SomeCompilerException@, but not other types, e.g. @IOException@:--@-*Main> throw MismatchedParentheses `catch` \e -> putStrLn (\"Caught \" ++ show (e :: MismatchedParentheses))-Caught MismatchedParentheses-*Main> throw MismatchedParentheses `catch` \e -> putStrLn (\"Caught \" ++ show (e :: SomeFrontendException))-Caught MismatchedParentheses-*Main> throw MismatchedParentheses `catch` \e -> putStrLn (\"Caught \" ++ show (e :: SomeCompilerException))-Caught MismatchedParentheses-*Main> throw MismatchedParentheses `catch` \e -> putStrLn (\"Caught \" ++ show (e :: IOException))-*** Exception: MismatchedParentheses-@---}-class (Typeable e, Show e) => Exception e where-    toException   :: e -> SomeException-    fromException :: SomeException -> Maybe e--    toException = SomeException-    fromException (SomeException e) = cast e--instance Exception SomeException where-    toException se = se-    fromException = Just-\end{code}--%*********************************************************-%*                                                      *-\subsection{Primitive throw}-%*                                                      *-%*********************************************************--\begin{code}--- | Throw an exception.  Exceptions may be thrown from purely--- functional code, but may only be caught within the 'IO' monad.-throw :: Exception e => e -> a-throw e = raise# (toException e)-\end{code}--\begin{code}--- |This is thrown when the user calls 'error'. The @String@ is the--- argument given to 'error'.-newtype ErrorCall = ErrorCall String-    deriving (Eq, Ord, Typeable)--instance Exception ErrorCall--instance Show ErrorCall where-    showsPrec _ (ErrorCall err) = showString err--errorCallException :: String -> SomeException-errorCallException s = toException (ErrorCall s)----------- |Arithmetic exceptions.-data ArithException-  = Overflow-  | Underflow-  | LossOfPrecision-  | DivideByZero-  | Denormal-  | RatioZeroDenominator -- ^ /Since: 4.6.0.0/-  deriving (Eq, Ord, Typeable)--divZeroException, overflowException, ratioZeroDenomException  :: SomeException-divZeroException  	= toException DivideByZero-overflowException 	= toException Overflow-ratioZeroDenomException = toException RatioZeroDenominator--instance Exception ArithException--instance Show ArithException where-  showsPrec _ Overflow        = showString "arithmetic overflow"-  showsPrec _ Underflow       = showString "arithmetic underflow"-  showsPrec _ LossOfPrecision = showString "loss of precision"-  showsPrec _ DivideByZero    = showString "divide by zero"-  showsPrec _ Denormal        = showString "denormal"-  showsPrec _ RatioZeroDenominator = showString "Ratio has zero denominator"-\end{code}
− GHC/Exception.lhs-boot
@@ -1,38 +0,0 @@-This SOURCE-imported hs-boot module cuts a big dependency loop:--         GHC.Exception-imports  Data.Maybe-imports  GHC.Base-imports  GHC.Err-imports  {-# SOURCE #-} GHC.Exception--More dramatically--         GHC.Exception-imports  Data.Typeable-imports  Data.Typeable.Internals-imports  GHC.Arr (fingerprint representation etc)-imports  GHC.Real-imports  {-# SOURCE #-} GHC.Exception--However, GHC.Exceptions loop-breaking exports are all nice,-well-behaved, non-bottom values.  The clients use 'raise#'-to get a visibly-bottom value.--\begin{code}-{-# LANGUAGE Trustworthy #-}-{-# LANGUAGE NoImplicitPrelude #-}--------------------------------------------------------------------------------                  Ghc.Exception.hs-boot------------------------------------------------------------------------------module GHC.Exception ( SomeException, errorCallException,-                       divZeroException, overflowException, ratioZeroDenomException  -    ) where -import GHC.Types( Char )--data SomeException-divZeroException, overflowException, ratioZeroDenomException  :: SomeException-errorCallException :: [Char] -> SomeException-\end{code}
GHC/Exts.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE Unsafe #-}-{-# LANGUAGE MagicHash, UnboxedTuples, DeriveDataTypeable, TypeFamilies, MultiParamTypeClasses, FlexibleInstances #-}+{-# LANGUAGE MagicHash, UnboxedTuples, AutoDeriveTypeable, TypeFamilies,+             MultiParamTypeClasses, FlexibleInstances, NoImplicitPrelude #-}  ----------------------------------------------------------------------------- -- |@@ -49,7 +50,7 @@         --         -- | These are available from the /Trustworthy/ module "Data.Coerce" as well         ---        -- /Since: 4.7.0.0/+        -- @since 4.7.0.0         Data.Coerce.coerce, Data.Coerce.Coercible,          -- * Transform comprehensions@@ -71,19 +72,19 @@         IsList(..)        ) where -import Prelude--import GHC.Prim hiding (coerce, Coercible)-import GHC.Base hiding (coerce, Coercible) -- implicitly comes from GHC.Prim+import GHC.Prim hiding (coerce, Constraint)+import GHC.Base hiding (coerce) -- implicitly comes from GHC.Prim import GHC.Word import GHC.Int import GHC.Ptr import GHC.Stack+ import qualified Data.Coerce import Data.String-import Data.List+import Data.OldList import Data.Data import Data.Ord+import Data.Version ( Version(..), makeVersion ) import qualified Debug.Trace  -- XXX This should really be in Data.Tuple, where the definitions are@@ -126,9 +127,9 @@   {- **********************************************************************-*									*+*                                                                       * *              SpecConstr annotation                                    *-*									*+*                                                                       * ********************************************************************** -}  -- Annotating a type with NoSpecConstr will make SpecConstr@@ -143,15 +144,15 @@   {- **********************************************************************-*									*+*                                                                       * *              The IsList class                                         *-*									*+*                                                                       * ********************************************************************** -}  -- | The 'IsList' class and its methods are intended to be used in --   conjunction with the OverloadedLists extension. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 class IsList l where   -- | The 'Item' type function returns the type of items of the structure   --   @l@.@@ -177,3 +178,9 @@   type (Item [a]) = a   fromList = id   toList = id++-- | @since 4.8.0.0+instance IsList Version where+  type (Item Version) = Int+  fromList = makeVersion+  toList = versionBranch
GHC/Fingerprint.hs view
@@ -30,7 +30,6 @@ import Foreign import Foreign.C import System.IO-import Control.Monad (when)  import GHC.Fingerprint.Type @@ -73,7 +72,7 @@ -- | Computes the hash of a given file. -- This function loops over the handle, running in constant memory. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 getFileHash :: FilePath -> IO Fingerprint getFileHash path = withBinaryFile path ReadMode $ \h -> do   allocaBytes SIZEOF_STRUCT_MD5CONTEXT $ \pctxt -> do
GHC/Fingerprint.hs-boot view
@@ -1,5 +1,6 @@-{-# LANGUAGE Unsafe #-}+{-# LANGUAGE Trustworthy #-} {-# LANGUAGE NoImplicitPrelude #-}+ module GHC.Fingerprint (         fingerprintString,         fingerprintFingerprints
GHC/Fingerprint/Type.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE Trustworthy #-} {-# LANGUAGE NoImplicitPrelude #-}+ -- ---------------------------------------------------------------------------- -- --  (c) The University of Glasgow 2006
+ GHC/Float.hs view
@@ -0,0 +1,1153 @@+{-# LANGUAGE Trustworthy #-}+{-# LANGUAGE CPP+           , NoImplicitPrelude+           , MagicHash+           , UnboxedTuples+  #-}+-- We believe we could deorphan this module, by moving lots of things+-- around, but we haven't got there yet:+{-# OPTIONS_GHC -fno-warn-orphans #-}+{-# OPTIONS_HADDOCK hide #-}++-----------------------------------------------------------------------------+-- |+-- Module      :  GHC.Float+-- Copyright   :  (c) The University of Glasgow 1994-2002+--                Portions obtained from hbc (c) Lennart Augusstson+-- License     :  see libraries/base/LICENSE+--+-- Maintainer  :  cvs-ghc@haskell.org+-- Stability   :  internal+-- Portability :  non-portable (GHC Extensions)+--+-- The types 'Float' and 'Double', and the classes 'Floating' and 'RealFloat'.+--+-----------------------------------------------------------------------------++#include "ieee-flpt.h"++module GHC.Float( module GHC.Float, Float(..), Double(..), Float#, Double#+                , double2Int, int2Double, float2Int, int2Float )+    where++import Data.Maybe++import Data.Bits+import GHC.Base+import GHC.List+import GHC.Enum+import GHC.Show+import GHC.Num+import GHC.Real+import GHC.Arr+import GHC.Float.RealFracMethods+import GHC.Float.ConversionUtils+import GHC.Integer.Logarithms ( integerLogBase# )+import GHC.Integer.Logarithms.Internals++infixr 8  **++------------------------------------------------------------------------+-- Standard numeric classes+------------------------------------------------------------------------++-- | Trigonometric and hyperbolic functions and related functions.+class  (Fractional a) => Floating a  where+    pi                  :: a+    exp, log, sqrt      :: a -> a+    (**), logBase       :: a -> a -> a+    sin, cos, tan       :: a -> a+    asin, acos, atan    :: a -> a+    sinh, cosh, tanh    :: a -> a+    asinh, acosh, atanh :: a -> a++    {-# INLINE (**) #-}+    {-# INLINE logBase #-}+    {-# INLINE sqrt #-}+    {-# INLINE tan #-}+    {-# INLINE tanh #-}+    x ** y              =  exp (log x * y)+    logBase x y         =  log y / log x+    sqrt x              =  x ** 0.5+    tan  x              =  sin  x / cos  x+    tanh x              =  sinh x / cosh x++-- | Efficient, machine-independent access to the components of a+-- floating-point number.+class  (RealFrac a, Floating a) => RealFloat a  where+    -- | a constant function, returning the radix of the representation+    -- (often @2@)+    floatRadix          :: a -> Integer+    -- | a constant function, returning the number of digits of+    -- 'floatRadix' in the significand+    floatDigits         :: a -> Int+    -- | a constant function, returning the lowest and highest values+    -- the exponent may assume+    floatRange          :: a -> (Int,Int)+    -- | The function 'decodeFloat' applied to a real floating-point+    -- number returns the significand expressed as an 'Integer' and an+    -- appropriately scaled exponent (an 'Int').  If @'decodeFloat' x@+    -- yields @(m,n)@, then @x@ is equal in value to @m*b^^n@, where @b@+    -- is the floating-point radix, and furthermore, either @m@ and @n@+    -- are both zero or else @b^(d-1) <= 'abs' m < b^d@, where @d@ is+    -- the value of @'floatDigits' x@.+    -- In particular, @'decodeFloat' 0 = (0,0)@. If the type+    -- contains a negative zero, also @'decodeFloat' (-0.0) = (0,0)@.+    -- /The result of/ @'decodeFloat' x@ /is unspecified if either of/+    -- @'isNaN' x@ /or/ @'isInfinite' x@ /is/ 'True'.+    decodeFloat         :: a -> (Integer,Int)+    -- | 'encodeFloat' performs the inverse of 'decodeFloat' in the+    -- sense that for finite @x@ with the exception of @-0.0@,+    -- @'uncurry' 'encodeFloat' ('decodeFloat' x) = x@.+    -- @'encodeFloat' m n@ is one of the two closest representable+    -- floating-point numbers to @m*b^^n@ (or @&#177;Infinity@ if overflow+    -- occurs); usually the closer, but if @m@ contains too many bits,+    -- the result may be rounded in the wrong direction.+    encodeFloat         :: Integer -> Int -> a+    -- | 'exponent' corresponds to the second component of 'decodeFloat'.+    -- @'exponent' 0 = 0@ and for finite nonzero @x@,+    -- @'exponent' x = snd ('decodeFloat' x) + 'floatDigits' x@.+    -- If @x@ is a finite floating-point number, it is equal in value to+    -- @'significand' x * b ^^ 'exponent' x@, where @b@ is the+    -- floating-point radix.+    -- The behaviour is unspecified on infinite or @NaN@ values.+    exponent            :: a -> Int+    -- | The first component of 'decodeFloat', scaled to lie in the open+    -- interval (@-1@,@1@), either @0.0@ or of absolute value @>= 1\/b@,+    -- where @b@ is the floating-point radix.+    -- The behaviour is unspecified on infinite or @NaN@ values.+    significand         :: a -> a+    -- | multiplies a floating-point number by an integer power of the radix+    scaleFloat          :: Int -> a -> a+    -- | 'True' if the argument is an IEEE \"not-a-number\" (NaN) value+    isNaN               :: a -> Bool+    -- | 'True' if the argument is an IEEE infinity or negative infinity+    isInfinite          :: a -> Bool+    -- | 'True' if the argument is too small to be represented in+    -- normalized format+    isDenormalized      :: a -> Bool+    -- | 'True' if the argument is an IEEE negative zero+    isNegativeZero      :: a -> Bool+    -- | 'True' if the argument is an IEEE floating point number+    isIEEE              :: a -> Bool+    -- | a version of arctangent taking two real floating-point arguments.+    -- For real floating @x@ and @y@, @'atan2' y x@ computes the angle+    -- (from the positive x-axis) of the vector from the origin to the+    -- point @(x,y)@.  @'atan2' y x@ returns a value in the range [@-pi@,+    -- @pi@].  It follows the Common Lisp semantics for the origin when+    -- signed zeroes are supported.  @'atan2' y 1@, with @y@ in a type+    -- that is 'RealFloat', should return the same value as @'atan' y@.+    -- A default definition of 'atan2' is provided, but implementors+    -- can provide a more accurate implementation.+    atan2               :: a -> a -> a+++    exponent x          =  if m == 0 then 0 else n + floatDigits x+                           where (m,n) = decodeFloat x++    significand x       =  encodeFloat m (negate (floatDigits x))+                           where (m,_) = decodeFloat x++    scaleFloat 0 x      =  x+    scaleFloat k x+      | isFix           =  x+      | otherwise       =  encodeFloat m (n + clamp b k)+                           where (m,n) = decodeFloat x+                                 (l,h) = floatRange x+                                 d     = floatDigits x+                                 b     = h - l + 4*d+                                 -- n+k may overflow, which would lead+                                 -- to wrong results, hence we clamp the+                                 -- scaling parameter.+                                 -- If n + k would be larger than h,+                                 -- n + clamp b k must be too, simliar+                                 -- for smaller than l - d.+                                 -- Add a little extra to keep clear+                                 -- from the boundary cases.+                                 isFix = x == 0 || isNaN x || isInfinite x++    atan2 y x+      | x > 0            =  atan (y/x)+      | x == 0 && y > 0  =  pi/2+      | x <  0 && y > 0  =  pi + atan (y/x)+      |(x <= 0 && y < 0)            ||+       (x <  0 && isNegativeZero y) ||+       (isNegativeZero x && isNegativeZero y)+                         = -atan2 (-y) x+      | y == 0 && (x < 0 || isNegativeZero x)+                          =  pi    -- must be after the previous test on zero y+      | x==0 && y==0      =  y     -- must be after the other double zero tests+      | otherwise         =  x + y -- x or y is a NaN, return a NaN (via +)++------------------------------------------------------------------------+-- Float+------------------------------------------------------------------------++instance  Num Float  where+    (+)         x y     =  plusFloat x y+    (-)         x y     =  minusFloat x y+    negate      x       =  negateFloat x+    (*)         x y     =  timesFloat x y+    abs x    | x == 0    = 0 -- handles (-0.0)+             | x >  0    = x+             | otherwise = negateFloat x+    signum x | x > 0     = 1+             | x < 0     = negateFloat 1+             | otherwise = x -- handles 0.0, (-0.0), and NaN++    {-# INLINE fromInteger #-}+    fromInteger i = F# (floatFromInteger i)++instance  Real Float  where+    toRational (F# x#)  =+        case decodeFloat_Int# x# of+          (# m#, e# #)+            | isTrue# (e# >=# 0#)                               ->+                    (smallInteger m# `shiftLInteger` e#) :% 1+            | isTrue# ((int2Word# m# `and#` 1##) `eqWord#` 0##) ->+                    case elimZerosInt# m# (negateInt# e#) of+                      (# n, d# #) -> n :% shiftLInteger 1 d#+            | otherwise                                         ->+                    smallInteger m# :% shiftLInteger 1 (negateInt# e#)++instance  Fractional Float  where+    (/) x y             =  divideFloat x y+    {-# INLINE fromRational #-}+    fromRational (n:%d) = rationalToFloat n d+    recip x             =  1.0 / x++rationalToFloat :: Integer -> Integer -> Float+{-# NOINLINE [1] rationalToFloat #-}+rationalToFloat n 0+    | n == 0        = 0/0+    | n < 0         = (-1)/0+    | otherwise     = 1/0+rationalToFloat n d+    | n == 0        = encodeFloat 0 0+    | n < 0         = -(fromRat'' minEx mantDigs (-n) d)+    | otherwise     = fromRat'' minEx mantDigs n d+      where+        minEx       = FLT_MIN_EXP+        mantDigs    = FLT_MANT_DIG++-- RULES for Integer and Int+{-# RULES+"properFraction/Float->Integer"     properFraction = properFractionFloatInteger+"truncate/Float->Integer"           truncate = truncateFloatInteger+"floor/Float->Integer"              floor = floorFloatInteger+"ceiling/Float->Integer"            ceiling = ceilingFloatInteger+"round/Float->Integer"              round = roundFloatInteger+"properFraction/Float->Int"         properFraction = properFractionFloatInt+"truncate/Float->Int"               truncate = float2Int+"floor/Float->Int"                  floor = floorFloatInt+"ceiling/Float->Int"                ceiling = ceilingFloatInt+"round/Float->Int"                  round = roundFloatInt+  #-}+instance  RealFrac Float  where++        -- ceiling, floor, and truncate are all small+    {-# INLINE [1] ceiling #-}+    {-# INLINE [1] floor #-}+    {-# INLINE [1] truncate #-}++-- We assume that FLT_RADIX is 2 so that we can use more efficient code+#if FLT_RADIX != 2+#error FLT_RADIX must be 2+#endif+    properFraction (F# x#)+      = case decodeFloat_Int# x# of+        (# m#, n# #) ->+            let m = I# m#+                n = I# n#+            in+            if n >= 0+            then (fromIntegral m * (2 ^ n), 0.0)+            else let i = if m >= 0 then                m `shiftR` negate n+                                   else negate (negate m `shiftR` negate n)+                     f = m - (i `shiftL` negate n)+                 in (fromIntegral i, encodeFloat (fromIntegral f) n)++    truncate x  = case properFraction x of+                     (n,_) -> n++    round x     = case properFraction x of+                     (n,r) -> let+                                m         = if r < 0.0 then n - 1 else n + 1+                                half_down = abs r - 0.5+                              in+                              case (compare half_down 0.0) of+                                LT -> n+                                EQ -> if even n then n else m+                                GT -> m++    ceiling x   = case properFraction x of+                    (n,r) -> if r > 0.0 then n + 1 else n++    floor x     = case properFraction x of+                    (n,r) -> if r < 0.0 then n - 1 else n++instance  Floating Float  where+    pi                  =  3.141592653589793238+    exp x               =  expFloat x+    log x               =  logFloat x+    sqrt x              =  sqrtFloat x+    sin x               =  sinFloat x+    cos x               =  cosFloat x+    tan x               =  tanFloat x+    asin x              =  asinFloat x+    acos x              =  acosFloat x+    atan x              =  atanFloat x+    sinh x              =  sinhFloat x+    cosh x              =  coshFloat x+    tanh x              =  tanhFloat x+    (**) x y            =  powerFloat x y+    logBase x y         =  log y / log x++    asinh x = log (x + sqrt (1.0+x*x))+    acosh x = log (x + (x+1.0) * sqrt ((x-1.0)/(x+1.0)))+    atanh x = 0.5 * log ((1.0+x) / (1.0-x))++instance  RealFloat Float  where+    floatRadix _        =  FLT_RADIX        -- from float.h+    floatDigits _       =  FLT_MANT_DIG     -- ditto+    floatRange _        =  (FLT_MIN_EXP, FLT_MAX_EXP) -- ditto++    decodeFloat (F# f#) = case decodeFloat_Int# f# of+                          (# i, e #) -> (smallInteger i, I# e)++    encodeFloat i (I# e) = F# (encodeFloatInteger i e)++    exponent x          = case decodeFloat x of+                            (m,n) -> if m == 0 then 0 else n + floatDigits x++    significand x       = case decodeFloat x of+                            (m,_) -> encodeFloat m (negate (floatDigits x))++    scaleFloat 0 x      = x+    scaleFloat k x+      | isFix           = x+      | otherwise       = case decodeFloat x of+                            (m,n) -> encodeFloat m (n + clamp bf k)+                        where bf = FLT_MAX_EXP - (FLT_MIN_EXP) + 4*FLT_MANT_DIG+                              isFix = x == 0 || isFloatFinite x == 0++    isNaN x          = 0 /= isFloatNaN x+    isInfinite x     = 0 /= isFloatInfinite x+    isDenormalized x = 0 /= isFloatDenormalized x+    isNegativeZero x = 0 /= isFloatNegativeZero x+    isIEEE _         = True++instance  Show Float  where+    showsPrec   x = showSignedFloat showFloat x+    showList = showList__ (showsPrec 0)++------------------------------------------------------------------------+-- Double+------------------------------------------------------------------------++instance  Num Double  where+    (+)         x y     =  plusDouble x y+    (-)         x y     =  minusDouble x y+    negate      x       =  negateDouble x+    (*)         x y     =  timesDouble x y+    abs x    | x == 0    = 0 -- handles (-0.0)+             | x >  0    = x+             | otherwise = negateDouble x+    signum x | x > 0     = 1+             | x < 0     = negateDouble 1+             | otherwise = x -- handles 0.0, (-0.0), and NaN+++    {-# INLINE fromInteger #-}+    fromInteger i = D# (doubleFromInteger i)+++instance  Real Double  where+    toRational (D# x#)  =+        case decodeDoubleInteger x# of+          (# m, e# #)+            | isTrue# (e# >=# 0#)                                  ->+                shiftLInteger m e# :% 1+            | isTrue# ((integerToWord m `and#` 1##) `eqWord#` 0##) ->+                case elimZerosInteger m (negateInt# e#) of+                    (# n, d# #) ->  n :% shiftLInteger 1 d#+            | otherwise                                            ->+                m :% shiftLInteger 1 (negateInt# e#)++instance  Fractional Double  where+    (/) x y             =  divideDouble x y+    {-# INLINE fromRational #-}+    fromRational (n:%d) = rationalToDouble n d+    recip x             =  1.0 / x++rationalToDouble :: Integer -> Integer -> Double+{-# NOINLINE [1] rationalToDouble #-}+rationalToDouble n 0+    | n == 0        = 0/0+    | n < 0         = (-1)/0+    | otherwise     = 1/0+rationalToDouble n d+    | n == 0        = encodeFloat 0 0+    | n < 0         = -(fromRat'' minEx mantDigs (-n) d)+    | otherwise     = fromRat'' minEx mantDigs n d+      where+        minEx       = DBL_MIN_EXP+        mantDigs    = DBL_MANT_DIG++instance  Floating Double  where+    pi                  =  3.141592653589793238+    exp x               =  expDouble x+    log x               =  logDouble x+    sqrt x              =  sqrtDouble x+    sin  x              =  sinDouble x+    cos  x              =  cosDouble x+    tan  x              =  tanDouble x+    asin x              =  asinDouble x+    acos x              =  acosDouble x+    atan x              =  atanDouble x+    sinh x              =  sinhDouble x+    cosh x              =  coshDouble x+    tanh x              =  tanhDouble x+    (**) x y            =  powerDouble x y+    logBase x y         =  log y / log x++    asinh x = log (x + sqrt (1.0+x*x))+    acosh x = log (x + (x+1.0) * sqrt ((x-1.0)/(x+1.0)))+    atanh x = 0.5 * log ((1.0+x) / (1.0-x))++-- RULES for Integer and Int+{-# RULES+"properFraction/Double->Integer"    properFraction = properFractionDoubleInteger+"truncate/Double->Integer"          truncate = truncateDoubleInteger+"floor/Double->Integer"             floor = floorDoubleInteger+"ceiling/Double->Integer"           ceiling = ceilingDoubleInteger+"round/Double->Integer"             round = roundDoubleInteger+"properFraction/Double->Int"        properFraction = properFractionDoubleInt+"truncate/Double->Int"              truncate = double2Int+"floor/Double->Int"                 floor = floorDoubleInt+"ceiling/Double->Int"               ceiling = ceilingDoubleInt+"round/Double->Int"                 round = roundDoubleInt+  #-}+instance  RealFrac Double  where++        -- ceiling, floor, and truncate are all small+    {-# INLINE [1] ceiling #-}+    {-# INLINE [1] floor #-}+    {-# INLINE [1] truncate #-}++    properFraction x+      = case (decodeFloat x)      of { (m,n) ->+        if n >= 0 then+            (fromInteger m * 2 ^ n, 0.0)+        else+            case (quotRem m (2^(negate n))) of { (w,r) ->+            (fromInteger w, encodeFloat r n)+            }+        }++    truncate x  = case properFraction x of+                     (n,_) -> n++    round x     = case properFraction x of+                     (n,r) -> let+                                m         = if r < 0.0 then n - 1 else n + 1+                                half_down = abs r - 0.5+                              in+                              case (compare half_down 0.0) of+                                LT -> n+                                EQ -> if even n then n else m+                                GT -> m++    ceiling x   = case properFraction x of+                    (n,r) -> if r > 0.0 then n + 1 else n++    floor x     = case properFraction x of+                    (n,r) -> if r < 0.0 then n - 1 else n++instance  RealFloat Double  where+    floatRadix _        =  FLT_RADIX        -- from float.h+    floatDigits _       =  DBL_MANT_DIG     -- ditto+    floatRange _        =  (DBL_MIN_EXP, DBL_MAX_EXP) -- ditto++    decodeFloat (D# x#)+      = case decodeDoubleInteger x#   of+          (# i, j #) -> (i, I# j)++    encodeFloat i (I# j) = D# (encodeDoubleInteger i j)++    exponent x          = case decodeFloat x of+                            (m,n) -> if m == 0 then 0 else n + floatDigits x++    significand x       = case decodeFloat x of+                            (m,_) -> encodeFloat m (negate (floatDigits x))++    scaleFloat 0 x      = x+    scaleFloat k x+      | isFix           = x+      | otherwise       = case decodeFloat x of+                            (m,n) -> encodeFloat m (n + clamp bd k)+                        where bd = DBL_MAX_EXP - (DBL_MIN_EXP) + 4*DBL_MANT_DIG+                              isFix = x == 0 || isDoubleFinite x == 0++    isNaN x             = 0 /= isDoubleNaN x+    isInfinite x        = 0 /= isDoubleInfinite x+    isDenormalized x    = 0 /= isDoubleDenormalized x+    isNegativeZero x    = 0 /= isDoubleNegativeZero x+    isIEEE _            = True++instance  Show Double  where+    showsPrec   x = showSignedFloat showFloat x+    showList = showList__ (showsPrec 0)+++------------------------------------------------------------------------+-- Enum instances+------------------------------------------------------------------------++{-+The @Enum@ instances for Floats and Doubles are slightly unusual.+The @toEnum@ function truncates numbers to Int.  The definitions+of @enumFrom@ and @enumFromThen@ allow floats to be used in arithmetic+series: [0,0.1 .. 1.0].  However, roundoff errors make these somewhat+dubious.  This example may have either 10 or 11 elements, depending on+how 0.1 is represented.++NOTE: The instances for Float and Double do not make use of the default+methods for @enumFromTo@ and @enumFromThenTo@, as these rely on there being+a `non-lossy' conversion to and from Ints. Instead we make use of the+1.2 default methods (back in the days when Enum had Ord as a superclass)+for these (@numericEnumFromTo@ and @numericEnumFromThenTo@ below.)+-}++instance  Enum Float  where+    succ x         = x + 1+    pred x         = x - 1+    toEnum         = int2Float+    fromEnum       = fromInteger . truncate   -- may overflow+    enumFrom       = numericEnumFrom+    enumFromTo     = numericEnumFromTo+    enumFromThen   = numericEnumFromThen+    enumFromThenTo = numericEnumFromThenTo++instance  Enum Double  where+    succ x         = x + 1+    pred x         = x - 1+    toEnum         =  int2Double+    fromEnum       =  fromInteger . truncate   -- may overflow+    enumFrom       =  numericEnumFrom+    enumFromTo     =  numericEnumFromTo+    enumFromThen   =  numericEnumFromThen+    enumFromThenTo =  numericEnumFromThenTo++------------------------------------------------------------------------+-- Printing floating point+------------------------------------------------------------------------++-- | Show a signed 'RealFloat' value to full precision+-- using standard decimal notation for arguments whose absolute value lies+-- between @0.1@ and @9,999,999@, and scientific notation otherwise.+showFloat :: (RealFloat a) => a -> ShowS+showFloat x  =  showString (formatRealFloat FFGeneric Nothing x)++-- These are the format types.  This type is not exported.++data FFFormat = FFExponent | FFFixed | FFGeneric++-- This is just a compatibility stub, as the "alt" argument formerly+-- didn't exist.+formatRealFloat :: (RealFloat a) => FFFormat -> Maybe Int -> a -> String+formatRealFloat fmt decs x = formatRealFloatAlt fmt decs False x++formatRealFloatAlt :: (RealFloat a) => FFFormat -> Maybe Int -> Bool -> a+                 -> String+formatRealFloatAlt fmt decs alt x+   | isNaN x                   = "NaN"+   | isInfinite x              = if x < 0 then "-Infinity" else "Infinity"+   | x < 0 || isNegativeZero x = '-':doFmt fmt (floatToDigits (toInteger base) (-x))+   | otherwise                 = doFmt fmt (floatToDigits (toInteger base) x)+ where+  base = 10++  doFmt format (is, e) =+    let ds = map intToDigit is in+    case format of+     FFGeneric ->+      doFmt (if e < 0 || e > 7 then FFExponent else FFFixed)+            (is,e)+     FFExponent ->+      case decs of+       Nothing ->+        let show_e' = show (e-1) in+        case ds of+          "0"     -> "0.0e0"+          [d]     -> d : ".0e" ++ show_e'+          (d:ds') -> d : '.' : ds' ++ "e" ++ show_e'+          []      -> error "formatRealFloat/doFmt/FFExponent: []"+       Just dec ->+        let dec' = max dec 1 in+        case is of+         [0] -> '0' :'.' : take dec' (repeat '0') ++ "e0"+         _ ->+          let+           (ei,is') = roundTo base (dec'+1) is+           (d:ds') = map intToDigit (if ei > 0 then init is' else is')+          in+          d:'.':ds' ++ 'e':show (e-1+ei)+     FFFixed ->+      let+       mk0 ls = case ls of { "" -> "0" ; _ -> ls}+      in+      case decs of+       Nothing+          | e <= 0    -> "0." ++ replicate (-e) '0' ++ ds+          | otherwise ->+             let+                f 0 s    rs  = mk0 (reverse s) ++ '.':mk0 rs+                f n s    ""  = f (n-1) ('0':s) ""+                f n s (r:rs) = f (n-1) (r:s) rs+             in+                f e "" ds+       Just dec ->+        let dec' = max dec 0 in+        if e >= 0 then+         let+          (ei,is') = roundTo base (dec' + e) is+          (ls,rs)  = splitAt (e+ei) (map intToDigit is')+         in+         mk0 ls ++ (if null rs && not alt then "" else '.':rs)+        else+         let+          (ei,is') = roundTo base dec' (replicate (-e) 0 ++ is)+          d:ds' = map intToDigit (if ei > 0 then is' else 0:is')+         in+         d : (if null ds' && not alt then "" else '.':ds')+++roundTo :: Int -> Int -> [Int] -> (Int,[Int])+roundTo base d is =+  case f d True is of+    x@(0,_) -> x+    (1,xs)  -> (1, 1:xs)+    _       -> error "roundTo: bad Value"+ where+  b2 = base `quot` 2++  f n _ []     = (0, replicate n 0)+  f 0 e (x:xs) | x == b2 && e && all (== 0) xs = (0, [])   -- Round to even when at exactly half the base+               | otherwise = (if x >= b2 then 1 else 0, [])+  f n _ (i:xs)+     | i' == base = (1,0:ds)+     | otherwise  = (0,i':ds)+      where+       (c,ds) = f (n-1) (even i) xs+       i'     = c + i++-- Based on "Printing Floating-Point Numbers Quickly and Accurately"+-- by R.G. Burger and R.K. Dybvig in PLDI 96.+-- This version uses a much slower logarithm estimator. It should be improved.++-- | 'floatToDigits' takes a base and a non-negative 'RealFloat' number,+-- and returns a list of digits and an exponent.+-- In particular, if @x>=0@, and+--+-- > floatToDigits base x = ([d1,d2,...,dn], e)+--+-- then+--+--      (1) @n >= 1@+--+--      (2) @x = 0.d1d2...dn * (base**e)@+--+--      (3) @0 <= di <= base-1@++floatToDigits :: (RealFloat a) => Integer -> a -> ([Int], Int)+floatToDigits _ 0 = ([0], 0)+floatToDigits base x =+ let+  (f0, e0) = decodeFloat x+  (minExp0, _) = floatRange x+  p = floatDigits x+  b = floatRadix x+  minExp = minExp0 - p -- the real minimum exponent+  -- Haskell requires that f be adjusted so denormalized numbers+  -- will have an impossibly low exponent.  Adjust for this.+  (f, e) =+   let n = minExp - e0 in+   if n > 0 then (f0 `quot` (expt b n), e0+n) else (f0, e0)+  (r, s, mUp, mDn) =+   if e >= 0 then+    let be = expt b e in+    if f == expt b (p-1) then+      (f*be*b*2, 2*b, be*b, be)     -- according to Burger and Dybvig+    else+      (f*be*2, 2, be, be)+   else+    if e > minExp && f == expt b (p-1) then+      (f*b*2, expt b (-e+1)*2, b, 1)+    else+      (f*2, expt b (-e)*2, 1, 1)+  k :: Int+  k =+   let+    k0 :: Int+    k0 =+     if b == 2 && base == 10 then+        -- logBase 10 2 is very slightly larger than 8651/28738+        -- (about 5.3558e-10), so if log x >= 0, the approximation+        -- k1 is too small, hence we add one and need one fixup step less.+        -- If log x < 0, the approximation errs rather on the high side.+        -- That is usually more than compensated for by ignoring the+        -- fractional part of logBase 2 x, but when x is a power of 1/2+        -- or slightly larger and the exponent is a multiple of the+        -- denominator of the rational approximation to logBase 10 2,+        -- k1 is larger than logBase 10 x. If k1 > 1 + logBase 10 x,+        -- we get a leading zero-digit we don't want.+        -- With the approximation 3/10, this happened for+        -- 0.5^1030, 0.5^1040, ..., 0.5^1070 and values close above.+        -- The approximation 8651/28738 guarantees k1 < 1 + logBase 10 x+        -- for IEEE-ish floating point types with exponent fields+        -- <= 17 bits and mantissae of several thousand bits, earlier+        -- convergents to logBase 10 2 would fail for long double.+        -- Using quot instead of div is a little faster and requires+        -- fewer fixup steps for negative lx.+        let lx = p - 1 + e0+            k1 = (lx * 8651) `quot` 28738+        in if lx >= 0 then k1 + 1 else k1+     else+        -- f :: Integer, log :: Float -> Float,+        --               ceiling :: Float -> Int+        ceiling ((log (fromInteger (f+1) :: Float) ++                 fromIntegral e * log (fromInteger b)) /+                   log (fromInteger base))+--WAS:            fromInt e * log (fromInteger b))++    fixup n =+      if n >= 0 then+        if r + mUp <= expt base n * s then n else fixup (n+1)+      else+        if expt base (-n) * (r + mUp) <= s then n else fixup (n+1)+   in+   fixup k0++  gen ds rn sN mUpN mDnN =+   let+    (dn, rn') = (rn * base) `quotRem` sN+    mUpN' = mUpN * base+    mDnN' = mDnN * base+   in+   case (rn' < mDnN', rn' + mUpN' > sN) of+    (True,  False) -> dn : ds+    (False, True)  -> dn+1 : ds+    (True,  True)  -> if rn' * 2 < sN then dn : ds else dn+1 : ds+    (False, False) -> gen (dn:ds) rn' sN mUpN' mDnN'++  rds =+   if k >= 0 then+      gen [] r (s * expt base k) mUp mDn+   else+     let bk = expt base (-k) in+     gen [] (r * bk) s (mUp * bk) (mDn * bk)+ in+ (map fromIntegral (reverse rds), k)++------------------------------------------------------------------------+-- Converting from a Rational to a RealFloa+------------------------------------------------------------------------++{-+[In response to a request for documentation of how fromRational works,+Joe Fasel writes:] A quite reasonable request!  This code was added to+the Prelude just before the 1.2 release, when Lennart, working with an+early version of hbi, noticed that (read . show) was not the identity+for floating-point numbers.  (There was a one-bit error about half the+time.)  The original version of the conversion function was in fact+simply a floating-point divide, as you suggest above. The new version+is, I grant you, somewhat denser.++Unfortunately, Joe's code doesn't work!  Here's an example:++main = putStr (shows (1.82173691287639817263897126389712638972163e-300::Double) "\n")++This program prints+        0.0000000000000000+instead of+        1.8217369128763981e-300++Here's Joe's code:++\begin{pseudocode}+fromRat :: (RealFloat a) => Rational -> a+fromRat x = x'+        where x' = f e++--              If the exponent of the nearest floating-point number to x+--              is e, then the significand is the integer nearest xb^(-e),+--              where b is the floating-point radix.  We start with a good+--              guess for e, and if it is correct, the exponent of the+--              floating-point number we construct will again be e.  If+--              not, one more iteration is needed.++              f e   = if e' == e then y else f e'+                      where y      = encodeFloat (round (x * (1 % b)^^e)) e+                            (_,e') = decodeFloat y+              b     = floatRadix x'++--              We obtain a trial exponent by doing a floating-point+--              division of x's numerator by its denominator.  The+--              result of this division may not itself be the ultimate+--              result, because of an accumulation of three rounding+--              errors.++              (s,e) = decodeFloat (fromInteger (numerator x) `asTypeOf` x'+                                        / fromInteger (denominator x))+\end{pseudocode}++Now, here's Lennart's code (which works):+-}++-- | Converts a 'Rational' value into any type in class 'RealFloat'.+{-# RULES+"fromRat/Float"     fromRat = (fromRational :: Rational -> Float)+"fromRat/Double"    fromRat = (fromRational :: Rational -> Double)+  #-}++{-# NOINLINE [1] fromRat #-}+fromRat :: (RealFloat a) => Rational -> a++-- Deal with special cases first, delegating the real work to fromRat'+fromRat (n :% 0) | n > 0     =  1/0        -- +Infinity+                 | n < 0     = -1/0        -- -Infinity+                 | otherwise =  0/0        -- NaN++fromRat (n :% d) | n > 0     = fromRat' (n :% d)+                 | n < 0     = - fromRat' ((-n) :% d)+                 | otherwise = encodeFloat 0 0             -- Zero++-- Conversion process:+-- Scale the rational number by the RealFloat base until+-- it lies in the range of the mantissa (as used by decodeFloat/encodeFloat).+-- Then round the rational to an Integer and encode it with the exponent+-- that we got from the scaling.+-- To speed up the scaling process we compute the log2 of the number to get+-- a first guess of the exponent.++fromRat' :: (RealFloat a) => Rational -> a+-- Invariant: argument is strictly positive+fromRat' x = r+  where b = floatRadix r+        p = floatDigits r+        (minExp0, _) = floatRange r+        minExp = minExp0 - p            -- the real minimum exponent+        xMax   = toRational (expt b p)+        p0 = (integerLogBase b (numerator x) - integerLogBase b (denominator x) - p) `max` minExp+        -- if x = n/d and ln = integerLogBase b n, ld = integerLogBase b d,+        -- then b^(ln-ld-1) < x < b^(ln-ld+1)+        f = if p0 < 0 then 1 :% expt b (-p0) else expt b p0 :% 1+        x0 = x / f+        -- if ln - ld >= minExp0, then b^(p-1) < x0 < b^(p+1), so there's at most+        -- one scaling step needed, otherwise, x0 < b^p and no scaling is needed+        (x', p') = if x0 >= xMax then (x0 / toRational b, p0+1) else (x0, p0)+        r = encodeFloat (round x') p'++-- Exponentiation with a cache for the most common numbers.+minExpt, maxExpt :: Int+minExpt = 0+maxExpt = 1100++expt :: Integer -> Int -> Integer+expt base n =+    if base == 2 && n >= minExpt && n <= maxExpt then+        expts!n+    else+        if base == 10 && n <= maxExpt10 then+            expts10!n+        else+            base^n++expts :: Array Int Integer+expts = array (minExpt,maxExpt) [(n,2^n) | n <- [minExpt .. maxExpt]]++maxExpt10 :: Int+maxExpt10 = 324++expts10 :: Array Int Integer+expts10 = array (minExpt,maxExpt10) [(n,10^n) | n <- [minExpt .. maxExpt10]]++-- Compute the (floor of the) log of i in base b.+-- Simplest way would be just divide i by b until it's smaller then b, but that would+-- be very slow!  We are just slightly more clever, except for base 2, where+-- we take advantage of the representation of Integers.+-- The general case could be improved by a lookup table for+-- approximating the result by integerLog2 i / integerLog2 b.+integerLogBase :: Integer -> Integer -> Int+integerLogBase b i+   | i < b     = 0+   | b == 2    = I# (integerLog2# i)+   | otherwise = I# (integerLogBase# b i)++{-+Unfortunately, the old conversion code was awfully slow due to+a) a slow integer logarithm+b) repeated calculation of gcd's++For the case of Rational's coming from a Float or Double via toRational,+we can exploit the fact that the denominator is a power of two, which for+these brings a huge speedup since we need only shift and add instead+of division.++The below is an adaption of fromRat' for the conversion to+Float or Double exploiting the known floatRadix and avoiding+divisions as much as possible.+-}++{-# SPECIALISE fromRat'' :: Int -> Int -> Integer -> Integer -> Float,+                            Int -> Int -> Integer -> Integer -> Double #-}+fromRat'' :: RealFloat a => Int -> Int -> Integer -> Integer -> a+-- Invariant: n and d strictly positive+fromRat'' minEx@(I# me#) mantDigs@(I# md#) n d =+    case integerLog2IsPowerOf2# d of+      (# ld#, pw# #)+        | isTrue# (pw# ==# 0#) ->+          case integerLog2# n of+            ln# | isTrue# (ln# >=# (ld# +# me# -# 1#)) ->+                  -- this means n/d >= 2^(minEx-1), i.e. we are guaranteed to get+                  -- a normalised number, round to mantDigs bits+                  if isTrue# (ln# <# md#)+                    then encodeFloat n (I# (negateInt# ld#))+                    else let n'  = n `shiftR` (I# (ln# +# 1# -# md#))+                             n'' = case roundingMode# n (ln# -# md#) of+                                    0# -> n'+                                    2# -> n' + 1+                                    _  -> case fromInteger n' .&. (1 :: Int) of+                                            0 -> n'+                                            _ -> n' + 1+                         in encodeFloat n'' (I# (ln# -# ld# +# 1# -# md#))+                | otherwise ->+                  -- n/d < 2^(minEx-1), a denorm or rounded to 2^(minEx-1)+                  -- the exponent for encoding is always minEx-mantDigs+                  -- so we must shift right by (minEx-mantDigs) - (-ld)+                  case ld# +# (me# -# md#) of+                    ld'# | isTrue# (ld'# <=# 0#) -> -- we would shift left, so we don't shift+                           encodeFloat n (I# ((me# -# md#) -# ld'#))+                         | isTrue# (ld'# <=# ln#) ->+                           let n' = n `shiftR` (I# ld'#)+                           in case roundingMode# n (ld'# -# 1#) of+                                0# -> encodeFloat n' (minEx - mantDigs)+                                1# -> if fromInteger n' .&. (1 :: Int) == 0+                                        then encodeFloat n' (minEx-mantDigs)+                                        else encodeFloat (n' + 1) (minEx-mantDigs)+                                _  -> encodeFloat (n' + 1) (minEx-mantDigs)+                         | isTrue# (ld'# ># (ln# +# 1#)) -> encodeFloat 0 0 -- result of shift < 0.5+                         | otherwise ->  -- first bit of n shifted to 0.5 place+                           case integerLog2IsPowerOf2# n of+                            (# _, 0# #) -> encodeFloat 0 0  -- round to even+                            (# _, _ #)  -> encodeFloat 1 (minEx - mantDigs)+        | otherwise ->+          let ln = I# (integerLog2# n)+              ld = I# ld#+              -- 2^(ln-ld-1) < n/d < 2^(ln-ld+1)+              p0 = max minEx (ln - ld)+              (n', d')+                | p0 < mantDigs = (n `shiftL` (mantDigs - p0), d)+                | p0 == mantDigs = (n, d)+                | otherwise     = (n, d `shiftL` (p0 - mantDigs))+              -- if ln-ld < minEx, then n'/d' < 2^mantDigs, else+              -- 2^(mantDigs-1) < n'/d' < 2^(mantDigs+1) and we+              -- may need one scaling step+              scale p a b+                | (b `shiftL` mantDigs) <= a = (p+1, a, b `shiftL` 1)+                | otherwise = (p, a, b)+              (p', n'', d'') = scale (p0-mantDigs) n' d'+              -- n''/d'' < 2^mantDigs and p' == minEx-mantDigs or n''/d'' >= 2^(mantDigs-1)+              rdq = case n'' `quotRem` d'' of+                     (q,r) -> case compare (r `shiftL` 1) d'' of+                                LT -> q+                                EQ -> if fromInteger q .&. (1 :: Int) == 0+                                        then q else q+1+                                GT -> q+1+          in  encodeFloat rdq p'++------------------------------------------------------------------------+-- Floating point numeric primops+------------------------------------------------------------------------++-- Definitions of the boxed PrimOps; these will be+-- used in the case of partial applications, etc.++plusFloat, minusFloat, timesFloat, divideFloat :: Float -> Float -> Float+plusFloat   (F# x) (F# y) = F# (plusFloat# x y)+minusFloat  (F# x) (F# y) = F# (minusFloat# x y)+timesFloat  (F# x) (F# y) = F# (timesFloat# x y)+divideFloat (F# x) (F# y) = F# (divideFloat# x y)++negateFloat :: Float -> Float+negateFloat (F# x)        = F# (negateFloat# x)++gtFloat, geFloat, eqFloat, neFloat, ltFloat, leFloat :: Float -> Float -> Bool+gtFloat     (F# x) (F# y) = isTrue# (gtFloat# x y)+geFloat     (F# x) (F# y) = isTrue# (geFloat# x y)+eqFloat     (F# x) (F# y) = isTrue# (eqFloat# x y)+neFloat     (F# x) (F# y) = isTrue# (neFloat# x y)+ltFloat     (F# x) (F# y) = isTrue# (ltFloat# x y)+leFloat     (F# x) (F# y) = isTrue# (leFloat# x y)++expFloat, logFloat, sqrtFloat :: Float -> Float+sinFloat, cosFloat, tanFloat  :: Float -> Float+asinFloat, acosFloat, atanFloat  :: Float -> Float+sinhFloat, coshFloat, tanhFloat  :: Float -> Float+expFloat    (F# x) = F# (expFloat# x)+logFloat    (F# x) = F# (logFloat# x)+sqrtFloat   (F# x) = F# (sqrtFloat# x)+sinFloat    (F# x) = F# (sinFloat# x)+cosFloat    (F# x) = F# (cosFloat# x)+tanFloat    (F# x) = F# (tanFloat# x)+asinFloat   (F# x) = F# (asinFloat# x)+acosFloat   (F# x) = F# (acosFloat# x)+atanFloat   (F# x) = F# (atanFloat# x)+sinhFloat   (F# x) = F# (sinhFloat# x)+coshFloat   (F# x) = F# (coshFloat# x)+tanhFloat   (F# x) = F# (tanhFloat# x)++powerFloat :: Float -> Float -> Float+powerFloat  (F# x) (F# y) = F# (powerFloat# x y)++-- definitions of the boxed PrimOps; these will be+-- used in the case of partial applications, etc.++plusDouble, minusDouble, timesDouble, divideDouble :: Double -> Double -> Double+plusDouble   (D# x) (D# y) = D# (x +## y)+minusDouble  (D# x) (D# y) = D# (x -## y)+timesDouble  (D# x) (D# y) = D# (x *## y)+divideDouble (D# x) (D# y) = D# (x /## y)++negateDouble :: Double -> Double+negateDouble (D# x)        = D# (negateDouble# x)++gtDouble, geDouble, eqDouble, neDouble, leDouble, ltDouble :: Double -> Double -> Bool+gtDouble    (D# x) (D# y) = isTrue# (x >##  y)+geDouble    (D# x) (D# y) = isTrue# (x >=## y)+eqDouble    (D# x) (D# y) = isTrue# (x ==## y)+neDouble    (D# x) (D# y) = isTrue# (x /=## y)+ltDouble    (D# x) (D# y) = isTrue# (x <##  y)+leDouble    (D# x) (D# y) = isTrue# (x <=## y)++double2Float :: Double -> Float+double2Float (D# x) = F# (double2Float# x)++float2Double :: Float -> Double+float2Double (F# x) = D# (float2Double# x)++expDouble, logDouble, sqrtDouble :: Double -> Double+sinDouble, cosDouble, tanDouble  :: Double -> Double+asinDouble, acosDouble, atanDouble  :: Double -> Double+sinhDouble, coshDouble, tanhDouble  :: Double -> Double+expDouble    (D# x) = D# (expDouble# x)+logDouble    (D# x) = D# (logDouble# x)+sqrtDouble   (D# x) = D# (sqrtDouble# x)+sinDouble    (D# x) = D# (sinDouble# x)+cosDouble    (D# x) = D# (cosDouble# x)+tanDouble    (D# x) = D# (tanDouble# x)+asinDouble   (D# x) = D# (asinDouble# x)+acosDouble   (D# x) = D# (acosDouble# x)+atanDouble   (D# x) = D# (atanDouble# x)+sinhDouble   (D# x) = D# (sinhDouble# x)+coshDouble   (D# x) = D# (coshDouble# x)+tanhDouble   (D# x) = D# (tanhDouble# x)++powerDouble :: Double -> Double -> Double+powerDouble  (D# x) (D# y) = D# (x **## y)++foreign import ccall unsafe "isFloatNaN" isFloatNaN :: Float -> Int+foreign import ccall unsafe "isFloatInfinite" isFloatInfinite :: Float -> Int+foreign import ccall unsafe "isFloatDenormalized" isFloatDenormalized :: Float -> Int+foreign import ccall unsafe "isFloatNegativeZero" isFloatNegativeZero :: Float -> Int+foreign import ccall unsafe "isFloatFinite" isFloatFinite :: Float -> Int++foreign import ccall unsafe "isDoubleNaN" isDoubleNaN :: Double -> Int+foreign import ccall unsafe "isDoubleInfinite" isDoubleInfinite :: Double -> Int+foreign import ccall unsafe "isDoubleDenormalized" isDoubleDenormalized :: Double -> Int+foreign import ccall unsafe "isDoubleNegativeZero" isDoubleNegativeZero :: Double -> Int+foreign import ccall unsafe "isDoubleFinite" isDoubleFinite :: Double -> Int++------------------------------------------------------------------------+-- Coercion rules+------------------------------------------------------------------------++word2Double :: Word -> Double+word2Double (W# w) = D# (word2Double# w)++word2Float :: Word -> Float+word2Float (W# w) = F# (word2Float# w)++{-# RULES+"fromIntegral/Int->Float"   fromIntegral = int2Float+"fromIntegral/Int->Double"  fromIntegral = int2Double+"fromIntegral/Word->Float"  fromIntegral = word2Float+"fromIntegral/Word->Double" fromIntegral = word2Double+"realToFrac/Float->Float"   realToFrac   = id :: Float -> Float+"realToFrac/Float->Double"  realToFrac   = float2Double+"realToFrac/Double->Float"  realToFrac   = double2Float+"realToFrac/Double->Double" realToFrac   = id :: Double -> Double+"realToFrac/Int->Double"    realToFrac   = int2Double   -- See Note [realToFrac int-to-float]+"realToFrac/Int->Float"     realToFrac   = int2Float    --      ..ditto+    #-}++{-+Note [realToFrac int-to-float]+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+Don found that the RULES for realToFrac/Int->Double and simliarly+Float made a huge difference to some stream-fusion programs.  Here's+an example++      import Data.Array.Vector++      n = 40000000++      main = do+            let c = replicateU n (2::Double)+                a = mapU realToFrac (enumFromToU 0 (n-1) ) :: UArr Double+            print (sumU (zipWithU (*) c a))++Without the RULE we get this loop body:++      case $wtoRational sc_sY4 of ww_aM7 { (# ww1_aM9, ww2_aMa #) ->+      case $wfromRat ww1_aM9 ww2_aMa of tpl_X1P { D# ipv_sW3 ->+      Main.$s$wfold+        (+# sc_sY4 1)+        (+# wild_X1i 1)+        (+## sc2_sY6 (*## 2.0 ipv_sW3))++And with the rule:++     Main.$s$wfold+        (+# sc_sXT 1)+        (+# wild_X1h 1)+        (+## sc2_sXV (*## 2.0 (int2Double# sc_sXT)))++The running time of the program goes from 120 seconds to 0.198 seconds+with the native backend, and 0.143 seconds with the C backend.++A few more details in Trac #2251, and the patch message+"Add RULES for realToFrac from Int".+-}++-- Utils++showSignedFloat :: (RealFloat a)+  => (a -> ShowS)       -- ^ a function that can show unsigned values+  -> Int                -- ^ the precedence of the enclosing context+  -> a                  -- ^ the value to show+  -> ShowS+showSignedFloat showPos p x+   | x < 0 || isNegativeZero x+       = showParen (p > 6) (showChar '-' . showPos (-x))+   | otherwise = showPos x++{-+We need to prevent over/underflow of the exponent in encodeFloat when+called from scaleFloat, hence we clamp the scaling parameter.+We must have a large enough range to cover the maximum difference of+exponents returned by decodeFloat.+-}+clamp :: Int -> Int -> Int+clamp bd k = max (-bd) (min bd k)
− GHC/Float.lhs
@@ -1,1200 +0,0 @@-\begin{code}-{-# LANGUAGE Trustworthy #-}-{-# LANGUAGE CPP-           , NoImplicitPrelude-           , MagicHash-           , UnboxedTuples-  #-}--- We believe we could deorphan this module, by moving lots of things--- around, but we haven't got there yet:-{-# OPTIONS_GHC -fno-warn-orphans #-}-{-# OPTIONS_HADDOCK hide #-}---------------------------------------------------------------------------------- |--- Module      :  GHC.Float--- Copyright   :  (c) The University of Glasgow 1994-2002---                Portions obtained from hbc (c) Lennart Augusstson--- License     :  see libraries/base/LICENSE------ Maintainer  :  cvs-ghc@haskell.org--- Stability   :  internal--- Portability :  non-portable (GHC Extensions)------ The types 'Float' and 'Double', and the classes 'Floating' and 'RealFloat'.-----------------------------------------------------------------------------------#include "ieee-flpt.h"--module GHC.Float( module GHC.Float, Float(..), Double(..), Float#, Double#-                , double2Int, int2Double, float2Int, int2Float )-    where--import Data.Maybe--import Data.Bits-import GHC.Base-import GHC.List-import GHC.Enum-import GHC.Show-import GHC.Num-import GHC.Real-import GHC.Arr-import GHC.Float.RealFracMethods-import GHC.Float.ConversionUtils-import GHC.Integer.Logarithms ( integerLogBase# )-import GHC.Integer.Logarithms.Internals--infixr 8  **-\end{code}--%*********************************************************-%*                                                      *-\subsection{Standard numeric classes}-%*                                                      *-%*********************************************************--\begin{code}--- | Trigonometric and hyperbolic functions and related functions.------ Minimal complete definition:---      'pi', 'exp', 'log', 'sin', 'cos', 'sinh', 'cosh',---      'asin', 'acos', 'atan', 'asinh', 'acosh' and 'atanh'-class  (Fractional a) => Floating a  where-    pi                  :: a-    exp, log, sqrt      :: a -> a-    (**), logBase       :: a -> a -> a-    sin, cos, tan       :: a -> a-    asin, acos, atan    :: a -> a-    sinh, cosh, tanh    :: a -> a-    asinh, acosh, atanh :: a -> a--    {-# INLINE (**) #-}-    {-# INLINE logBase #-}-    {-# INLINE sqrt #-}-    {-# INLINE tan #-}-    {-# INLINE tanh #-}-    x ** y              =  exp (log x * y)-    logBase x y         =  log y / log x-    sqrt x              =  x ** 0.5-    tan  x              =  sin  x / cos  x-    tanh x              =  sinh x / cosh x---- | Efficient, machine-independent access to the components of a--- floating-point number.------ Minimal complete definition:---      all except 'exponent', 'significand', 'scaleFloat' and 'atan2'-class  (RealFrac a, Floating a) => RealFloat a  where-    -- | a constant function, returning the radix of the representation-    -- (often @2@)-    floatRadix          :: a -> Integer-    -- | a constant function, returning the number of digits of-    -- 'floatRadix' in the significand-    floatDigits         :: a -> Int-    -- | a constant function, returning the lowest and highest values-    -- the exponent may assume-    floatRange          :: a -> (Int,Int)-    -- | The function 'decodeFloat' applied to a real floating-point-    -- number returns the significand expressed as an 'Integer' and an-    -- appropriately scaled exponent (an 'Int').  If @'decodeFloat' x@-    -- yields @(m,n)@, then @x@ is equal in value to @m*b^^n@, where @b@-    -- is the floating-point radix, and furthermore, either @m@ and @n@-    -- are both zero or else @b^(d-1) <= 'abs' m < b^d@, where @d@ is-    -- the value of @'floatDigits' x@.-    -- In particular, @'decodeFloat' 0 = (0,0)@. If the type-    -- contains a negative zero, also @'decodeFloat' (-0.0) = (0,0)@.-    -- /The result of/ @'decodeFloat' x@ /is unspecified if either of/-    -- @'isNaN' x@ /or/ @'isInfinite' x@ /is/ 'True'.-    decodeFloat         :: a -> (Integer,Int)-    -- | 'encodeFloat' performs the inverse of 'decodeFloat' in the-    -- sense that for finite @x@ with the exception of @-0.0@,-    -- @'uncurry' 'encodeFloat' ('decodeFloat' x) = x@.-    -- @'encodeFloat' m n@ is one of the two closest representable-    -- floating-point numbers to @m*b^^n@ (or @&#177;Infinity@ if overflow-    -- occurs); usually the closer, but if @m@ contains too many bits,-    -- the result may be rounded in the wrong direction.-    encodeFloat         :: Integer -> Int -> a-    -- | 'exponent' corresponds to the second component of 'decodeFloat'.-    -- @'exponent' 0 = 0@ and for finite nonzero @x@,-    -- @'exponent' x = snd ('decodeFloat' x) + 'floatDigits' x@.-    -- If @x@ is a finite floating-point number, it is equal in value to-    -- @'significand' x * b ^^ 'exponent' x@, where @b@ is the-    -- floating-point radix.-    -- The behaviour is unspecified on infinite or @NaN@ values.-    exponent            :: a -> Int-    -- | The first component of 'decodeFloat', scaled to lie in the open-    -- interval (@-1@,@1@), either @0.0@ or of absolute value @>= 1\/b@,-    -- where @b@ is the floating-point radix.-    -- The behaviour is unspecified on infinite or @NaN@ values.-    significand         :: a -> a-    -- | multiplies a floating-point number by an integer power of the radix-    scaleFloat          :: Int -> a -> a-    -- | 'True' if the argument is an IEEE \"not-a-number\" (NaN) value-    isNaN               :: a -> Bool-    -- | 'True' if the argument is an IEEE infinity or negative infinity-    isInfinite          :: a -> Bool-    -- | 'True' if the argument is too small to be represented in-    -- normalized format-    isDenormalized      :: a -> Bool-    -- | 'True' if the argument is an IEEE negative zero-    isNegativeZero      :: a -> Bool-    -- | 'True' if the argument is an IEEE floating point number-    isIEEE              :: a -> Bool-    -- | a version of arctangent taking two real floating-point arguments.-    -- For real floating @x@ and @y@, @'atan2' y x@ computes the angle-    -- (from the positive x-axis) of the vector from the origin to the-    -- point @(x,y)@.  @'atan2' y x@ returns a value in the range [@-pi@,-    -- @pi@].  It follows the Common Lisp semantics for the origin when-    -- signed zeroes are supported.  @'atan2' y 1@, with @y@ in a type-    -- that is 'RealFloat', should return the same value as @'atan' y@.-    -- A default definition of 'atan2' is provided, but implementors-    -- can provide a more accurate implementation.-    atan2               :: a -> a -> a---    exponent x          =  if m == 0 then 0 else n + floatDigits x-                           where (m,n) = decodeFloat x--    significand x       =  encodeFloat m (negate (floatDigits x))-                           where (m,_) = decodeFloat x--    scaleFloat 0 x      =  x-    scaleFloat k x-      | isFix           =  x-      | otherwise       =  encodeFloat m (n + clamp b k)-                           where (m,n) = decodeFloat x-                                 (l,h) = floatRange x-                                 d     = floatDigits x-                                 b     = h - l + 4*d-                                 -- n+k may overflow, which would lead-                                 -- to wrong results, hence we clamp the-                                 -- scaling parameter.-                                 -- If n + k would be larger than h,-                                 -- n + clamp b k must be too, simliar-                                 -- for smaller than l - d.-                                 -- Add a little extra to keep clear-                                 -- from the boundary cases.-                                 isFix = x == 0 || isNaN x || isInfinite x--    atan2 y x-      | x > 0            =  atan (y/x)-      | x == 0 && y > 0  =  pi/2-      | x <  0 && y > 0  =  pi + atan (y/x)-      |(x <= 0 && y < 0)            ||-       (x <  0 && isNegativeZero y) ||-       (isNegativeZero x && isNegativeZero y)-                         = -atan2 (-y) x-      | y == 0 && (x < 0 || isNegativeZero x)-                          =  pi    -- must be after the previous test on zero y-      | x==0 && y==0      =  y     -- must be after the other double zero tests-      | otherwise         =  x + y -- x or y is a NaN, return a NaN (via +)-\end{code}---%*********************************************************-%*                                                      *-\subsection{Type @Float@}-%*                                                      *-%*********************************************************--\begin{code}-instance  Num Float  where-    (+)         x y     =  plusFloat x y-    (-)         x y     =  minusFloat x y-    negate      x       =  negateFloat x-    (*)         x y     =  timesFloat x y-    abs x | x >= 0.0    =  x-          | otherwise   =  negateFloat x-    signum x | x == 0.0  = 0-             | x > 0.0   = 1-             | otherwise = negate 1--    {-# INLINE fromInteger #-}-    fromInteger i = F# (floatFromInteger i)--instance  Real Float  where-    toRational (F# x#)  =-        case decodeFloat_Int# x# of-          (# m#, e# #)-            | isTrue# (e# >=# 0#)                               ->-                    (smallInteger m# `shiftLInteger` e#) :% 1-            | isTrue# ((int2Word# m# `and#` 1##) `eqWord#` 0##) ->-                    case elimZerosInt# m# (negateInt# e#) of-                      (# n, d# #) -> n :% shiftLInteger 1 d#-            | otherwise                                         ->-                    smallInteger m# :% shiftLInteger 1 (negateInt# e#)--instance  Fractional Float  where-    (/) x y             =  divideFloat x y-    {-# INLINE fromRational #-}-    fromRational (n:%d) = rationalToFloat n d-    recip x             =  1.0 / x--rationalToFloat :: Integer -> Integer -> Float-{-# NOINLINE [1] rationalToFloat #-}-rationalToFloat n 0-    | n == 0        = 0/0-    | n < 0         = (-1)/0-    | otherwise     = 1/0-rationalToFloat n d-    | n == 0        = encodeFloat 0 0-    | n < 0         = -(fromRat'' minEx mantDigs (-n) d)-    | otherwise     = fromRat'' minEx mantDigs n d-      where-        minEx       = FLT_MIN_EXP-        mantDigs    = FLT_MANT_DIG---- RULES for Integer and Int-{-# RULES-"properFraction/Float->Integer"     properFraction = properFractionFloatInteger-"truncate/Float->Integer"           truncate = truncateFloatInteger-"floor/Float->Integer"              floor = floorFloatInteger-"ceiling/Float->Integer"            ceiling = ceilingFloatInteger-"round/Float->Integer"              round = roundFloatInteger-"properFraction/Float->Int"         properFraction = properFractionFloatInt-"truncate/Float->Int"               truncate = float2Int-"floor/Float->Int"                  floor = floorFloatInt-"ceiling/Float->Int"                ceiling = ceilingFloatInt-"round/Float->Int"                  round = roundFloatInt-  #-}-instance  RealFrac Float  where--        -- ceiling, floor, and truncate are all small-    {-# INLINE [1] ceiling #-}-    {-# INLINE [1] floor #-}-    {-# INLINE [1] truncate #-}---- We assume that FLT_RADIX is 2 so that we can use more efficient code-#if FLT_RADIX != 2-#error FLT_RADIX must be 2-#endif-    properFraction (F# x#)-      = case decodeFloat_Int# x# of-        (# m#, n# #) ->-            let m = I# m#-                n = I# n#-            in-            if n >= 0-            then (fromIntegral m * (2 ^ n), 0.0)-            else let i = if m >= 0 then                m `shiftR` negate n-                                   else negate (negate m `shiftR` negate n)-                     f = m - (i `shiftL` negate n)-                 in (fromIntegral i, encodeFloat (fromIntegral f) n)--    truncate x  = case properFraction x of-                     (n,_) -> n--    round x     = case properFraction x of-                     (n,r) -> let-                                m         = if r < 0.0 then n - 1 else n + 1-                                half_down = abs r - 0.5-                              in-                              case (compare half_down 0.0) of-                                LT -> n-                                EQ -> if even n then n else m-                                GT -> m--    ceiling x   = case properFraction x of-                    (n,r) -> if r > 0.0 then n + 1 else n--    floor x     = case properFraction x of-                    (n,r) -> if r < 0.0 then n - 1 else n--instance  Floating Float  where-    pi                  =  3.141592653589793238-    exp x               =  expFloat x-    log x               =  logFloat x-    sqrt x              =  sqrtFloat x-    sin x               =  sinFloat x-    cos x               =  cosFloat x-    tan x               =  tanFloat x-    asin x              =  asinFloat x-    acos x              =  acosFloat x-    atan x              =  atanFloat x-    sinh x              =  sinhFloat x-    cosh x              =  coshFloat x-    tanh x              =  tanhFloat x-    (**) x y            =  powerFloat x y-    logBase x y         =  log y / log x--    asinh x = log (x + sqrt (1.0+x*x))-    acosh x = log (x + (x+1.0) * sqrt ((x-1.0)/(x+1.0)))-    atanh x = 0.5 * log ((1.0+x) / (1.0-x))--instance  RealFloat Float  where-    floatRadix _        =  FLT_RADIX        -- from float.h-    floatDigits _       =  FLT_MANT_DIG     -- ditto-    floatRange _        =  (FLT_MIN_EXP, FLT_MAX_EXP) -- ditto--    decodeFloat (F# f#) = case decodeFloat_Int# f# of-                          (# i, e #) -> (smallInteger i, I# e)--    encodeFloat i (I# e) = F# (encodeFloatInteger i e)--    exponent x          = case decodeFloat x of-                            (m,n) -> if m == 0 then 0 else n + floatDigits x--    significand x       = case decodeFloat x of-                            (m,_) -> encodeFloat m (negate (floatDigits x))--    scaleFloat 0 x      = x-    scaleFloat k x-      | isFix           = x-      | otherwise       = case decodeFloat x of-                            (m,n) -> encodeFloat m (n + clamp bf k)-                        where bf = FLT_MAX_EXP - (FLT_MIN_EXP) + 4*FLT_MANT_DIG-                              isFix = x == 0 || isFloatFinite x == 0--    isNaN x          = 0 /= isFloatNaN x-    isInfinite x     = 0 /= isFloatInfinite x-    isDenormalized x = 0 /= isFloatDenormalized x-    isNegativeZero x = 0 /= isFloatNegativeZero x-    isIEEE _         = True--instance  Show Float  where-    showsPrec   x = showSignedFloat showFloat x-    showList = showList__ (showsPrec 0)-\end{code}--%*********************************************************-%*                                                      *-\subsection{Type @Double@}-%*                                                      *-%*********************************************************--\begin{code}-instance  Num Double  where-    (+)         x y     =  plusDouble x y-    (-)         x y     =  minusDouble x y-    negate      x       =  negateDouble x-    (*)         x y     =  timesDouble x y-    abs x | x >= 0.0    =  x-          | otherwise   =  negateDouble x-    signum x | x == 0.0  = 0-             | x > 0.0   = 1-             | otherwise = negate 1--    {-# INLINE fromInteger #-}-    fromInteger i = D# (doubleFromInteger i)---instance  Real Double  where-    toRational (D# x#)  =-        case decodeDoubleInteger x# of-          (# m, e# #)-            | isTrue# (e# >=# 0#)                                  ->-                shiftLInteger m e# :% 1-            | isTrue# ((integerToWord m `and#` 1##) `eqWord#` 0##) ->-                case elimZerosInteger m (negateInt# e#) of-                    (# n, d# #) ->  n :% shiftLInteger 1 d#-            | otherwise                                            ->-                m :% shiftLInteger 1 (negateInt# e#)--instance  Fractional Double  where-    (/) x y             =  divideDouble x y-    {-# INLINE fromRational #-}-    fromRational (n:%d) = rationalToDouble n d-    recip x             =  1.0 / x--rationalToDouble :: Integer -> Integer -> Double-{-# NOINLINE [1] rationalToDouble #-}-rationalToDouble n 0-    | n == 0        = 0/0-    | n < 0         = (-1)/0-    | otherwise     = 1/0-rationalToDouble n d-    | n == 0        = encodeFloat 0 0-    | n < 0         = -(fromRat'' minEx mantDigs (-n) d)-    | otherwise     = fromRat'' minEx mantDigs n d-      where-        minEx       = DBL_MIN_EXP-        mantDigs    = DBL_MANT_DIG--instance  Floating Double  where-    pi                  =  3.141592653589793238-    exp x               =  expDouble x-    log x               =  logDouble x-    sqrt x              =  sqrtDouble x-    sin  x              =  sinDouble x-    cos  x              =  cosDouble x-    tan  x              =  tanDouble x-    asin x              =  asinDouble x-    acos x              =  acosDouble x-    atan x              =  atanDouble x-    sinh x              =  sinhDouble x-    cosh x              =  coshDouble x-    tanh x              =  tanhDouble x-    (**) x y            =  powerDouble x y-    logBase x y         =  log y / log x--    asinh x = log (x + sqrt (1.0+x*x))-    acosh x = log (x + (x+1.0) * sqrt ((x-1.0)/(x+1.0)))-    atanh x = 0.5 * log ((1.0+x) / (1.0-x))---- RULES for Integer and Int-{-# RULES-"properFraction/Double->Integer"    properFraction = properFractionDoubleInteger-"truncate/Double->Integer"          truncate = truncateDoubleInteger-"floor/Double->Integer"             floor = floorDoubleInteger-"ceiling/Double->Integer"           ceiling = ceilingDoubleInteger-"round/Double->Integer"             round = roundDoubleInteger-"properFraction/Double->Int"        properFraction = properFractionDoubleInt-"truncate/Double->Int"              truncate = double2Int-"floor/Double->Int"                 floor = floorDoubleInt-"ceiling/Double->Int"               ceiling = ceilingDoubleInt-"round/Double->Int"                 round = roundDoubleInt-  #-}-instance  RealFrac Double  where--        -- ceiling, floor, and truncate are all small-    {-# INLINE [1] ceiling #-}-    {-# INLINE [1] floor #-}-    {-# INLINE [1] truncate #-}--    properFraction x-      = case (decodeFloat x)      of { (m,n) ->-        if n >= 0 then-            (fromInteger m * 2 ^ n, 0.0)-        else-            case (quotRem m (2^(negate n))) of { (w,r) ->-            (fromInteger w, encodeFloat r n)-            }-        }--    truncate x  = case properFraction x of-                     (n,_) -> n--    round x     = case properFraction x of-                     (n,r) -> let-                                m         = if r < 0.0 then n - 1 else n + 1-                                half_down = abs r - 0.5-                              in-                              case (compare half_down 0.0) of-                                LT -> n-                                EQ -> if even n then n else m-                                GT -> m--    ceiling x   = case properFraction x of-                    (n,r) -> if r > 0.0 then n + 1 else n--    floor x     = case properFraction x of-                    (n,r) -> if r < 0.0 then n - 1 else n--instance  RealFloat Double  where-    floatRadix _        =  FLT_RADIX        -- from float.h-    floatDigits _       =  DBL_MANT_DIG     -- ditto-    floatRange _        =  (DBL_MIN_EXP, DBL_MAX_EXP) -- ditto--    decodeFloat (D# x#)-      = case decodeDoubleInteger x#   of-          (# i, j #) -> (i, I# j)--    encodeFloat i (I# j) = D# (encodeDoubleInteger i j)--    exponent x          = case decodeFloat x of-                            (m,n) -> if m == 0 then 0 else n + floatDigits x--    significand x       = case decodeFloat x of-                            (m,_) -> encodeFloat m (negate (floatDigits x))--    scaleFloat 0 x      = x-    scaleFloat k x-      | isFix           = x-      | otherwise       = case decodeFloat x of-                            (m,n) -> encodeFloat m (n + clamp bd k)-                        where bd = DBL_MAX_EXP - (DBL_MIN_EXP) + 4*DBL_MANT_DIG-                              isFix = x == 0 || isDoubleFinite x == 0--    isNaN x             = 0 /= isDoubleNaN x-    isInfinite x        = 0 /= isDoubleInfinite x-    isDenormalized x    = 0 /= isDoubleDenormalized x-    isNegativeZero x    = 0 /= isDoubleNegativeZero x-    isIEEE _            = True--instance  Show Double  where-    showsPrec   x = showSignedFloat showFloat x-    showList = showList__ (showsPrec 0)-\end{code}--%*********************************************************-%*                                                      *-\subsection{@Enum@ instances}-%*                                                      *-%*********************************************************--The @Enum@ instances for Floats and Doubles are slightly unusual.-The @toEnum@ function truncates numbers to Int.  The definitions-of @enumFrom@ and @enumFromThen@ allow floats to be used in arithmetic-series: [0,0.1 .. 1.0].  However, roundoff errors make these somewhat-dubious.  This example may have either 10 or 11 elements, depending on-how 0.1 is represented.--NOTE: The instances for Float and Double do not make use of the default-methods for @enumFromTo@ and @enumFromThenTo@, as these rely on there being-a `non-lossy' conversion to and from Ints. Instead we make use of the-1.2 default methods (back in the days when Enum had Ord as a superclass)-for these (@numericEnumFromTo@ and @numericEnumFromThenTo@ below.)--\begin{code}-instance  Enum Float  where-    succ x         = x + 1-    pred x         = x - 1-    toEnum         = int2Float-    fromEnum       = fromInteger . truncate   -- may overflow-    enumFrom       = numericEnumFrom-    enumFromTo     = numericEnumFromTo-    enumFromThen   = numericEnumFromThen-    enumFromThenTo = numericEnumFromThenTo--instance  Enum Double  where-    succ x         = x + 1-    pred x         = x - 1-    toEnum         =  int2Double-    fromEnum       =  fromInteger . truncate   -- may overflow-    enumFrom       =  numericEnumFrom-    enumFromTo     =  numericEnumFromTo-    enumFromThen   =  numericEnumFromThen-    enumFromThenTo =  numericEnumFromThenTo-\end{code}---%*********************************************************-%*                                                      *-\subsection{Printing floating point}-%*                                                      *-%*********************************************************---\begin{code}--- | Show a signed 'RealFloat' value to full precision--- using standard decimal notation for arguments whose absolute value lies--- between @0.1@ and @9,999,999@, and scientific notation otherwise.-showFloat :: (RealFloat a) => a -> ShowS-showFloat x  =  showString (formatRealFloat FFGeneric Nothing x)---- These are the format types.  This type is not exported.--data FFFormat = FFExponent | FFFixed | FFGeneric---- This is just a compatibility stub, as the "alt" argument formerly--- didn't exist.-formatRealFloat :: (RealFloat a) => FFFormat -> Maybe Int -> a -> String-formatRealFloat fmt decs x = formatRealFloatAlt fmt decs False x--formatRealFloatAlt :: (RealFloat a) => FFFormat -> Maybe Int -> Bool -> a-                 -> String-formatRealFloatAlt fmt decs alt x-   | isNaN x                   = "NaN"-   | isInfinite x              = if x < 0 then "-Infinity" else "Infinity"-   | x < 0 || isNegativeZero x = '-':doFmt fmt (floatToDigits (toInteger base) (-x))-   | otherwise                 = doFmt fmt (floatToDigits (toInteger base) x)- where-  base = 10--  doFmt format (is, e) =-    let ds = map intToDigit is in-    case format of-     FFGeneric ->-      doFmt (if e < 0 || e > 7 then FFExponent else FFFixed)-            (is,e)-     FFExponent ->-      case decs of-       Nothing ->-        let show_e' = show (e-1) in-        case ds of-          "0"     -> "0.0e0"-          [d]     -> d : ".0e" ++ show_e'-          (d:ds') -> d : '.' : ds' ++ "e" ++ show_e'-          []      -> error "formatRealFloat/doFmt/FFExponent: []"-       Just dec ->-        let dec' = max dec 1 in-        case is of-         [0] -> '0' :'.' : take dec' (repeat '0') ++ "e0"-         _ ->-          let-           (ei,is') = roundTo base (dec'+1) is-           (d:ds') = map intToDigit (if ei > 0 then init is' else is')-          in-          d:'.':ds' ++ 'e':show (e-1+ei)-     FFFixed ->-      let-       mk0 ls = case ls of { "" -> "0" ; _ -> ls}-      in-      case decs of-       Nothing-          | e <= 0    -> "0." ++ replicate (-e) '0' ++ ds-          | otherwise ->-             let-                f 0 s    rs  = mk0 (reverse s) ++ '.':mk0 rs-                f n s    ""  = f (n-1) ('0':s) ""-                f n s (r:rs) = f (n-1) (r:s) rs-             in-                f e "" ds-       Just dec ->-        let dec' = max dec 0 in-        if e >= 0 then-         let-          (ei,is') = roundTo base (dec' + e) is-          (ls,rs)  = splitAt (e+ei) (map intToDigit is')-         in-         mk0 ls ++ (if null rs && not alt then "" else '.':rs)-        else-         let-          (ei,is') = roundTo base dec' (replicate (-e) 0 ++ is)-          d:ds' = map intToDigit (if ei > 0 then is' else 0:is')-         in-         d : (if null ds' && not alt then "" else '.':ds')---roundTo :: Int -> Int -> [Int] -> (Int,[Int])-roundTo base d is =-  case f d True is of-    x@(0,_) -> x-    (1,xs)  -> (1, 1:xs)-    _       -> error "roundTo: bad Value"- where-  b2 = base `quot` 2--  f n _ []     = (0, replicate n 0)-  f 0 e (x:xs) | x == b2 && e && all (== 0) xs = (0, [])   -- Round to even when at exactly half the base-               | otherwise = (if x >= b2 then 1 else 0, [])-  f n _ (i:xs)-     | i' == base = (1,0:ds)-     | otherwise  = (0,i':ds)-      where-       (c,ds) = f (n-1) (even i) xs-       i'     = c + i---- Based on "Printing Floating-Point Numbers Quickly and Accurately"--- by R.G. Burger and R.K. Dybvig in PLDI 96.--- This version uses a much slower logarithm estimator. It should be improved.---- | 'floatToDigits' takes a base and a non-negative 'RealFloat' number,--- and returns a list of digits and an exponent.--- In particular, if @x>=0@, and------ > floatToDigits base x = ([d1,d2,...,dn], e)------ then------      (1) @n >= 1@------      (2) @x = 0.d1d2...dn * (base**e)@------      (3) @0 <= di <= base-1@--floatToDigits :: (RealFloat a) => Integer -> a -> ([Int], Int)-floatToDigits _ 0 = ([0], 0)-floatToDigits base x =- let-  (f0, e0) = decodeFloat x-  (minExp0, _) = floatRange x-  p = floatDigits x-  b = floatRadix x-  minExp = minExp0 - p -- the real minimum exponent-  -- Haskell requires that f be adjusted so denormalized numbers-  -- will have an impossibly low exponent.  Adjust for this.-  (f, e) =-   let n = minExp - e0 in-   if n > 0 then (f0 `quot` (expt b n), e0+n) else (f0, e0)-  (r, s, mUp, mDn) =-   if e >= 0 then-    let be = expt b e in-    if f == expt b (p-1) then-      (f*be*b*2, 2*b, be*b, be)     -- according to Burger and Dybvig-    else-      (f*be*2, 2, be, be)-   else-    if e > minExp && f == expt b (p-1) then-      (f*b*2, expt b (-e+1)*2, b, 1)-    else-      (f*2, expt b (-e)*2, 1, 1)-  k :: Int-  k =-   let-    k0 :: Int-    k0 =-     if b == 2 && base == 10 then-        -- logBase 10 2 is very slightly larger than 8651/28738-        -- (about 5.3558e-10), so if log x >= 0, the approximation-        -- k1 is too small, hence we add one and need one fixup step less.-        -- If log x < 0, the approximation errs rather on the high side.-        -- That is usually more than compensated for by ignoring the-        -- fractional part of logBase 2 x, but when x is a power of 1/2-        -- or slightly larger and the exponent is a multiple of the-        -- denominator of the rational approximation to logBase 10 2,-        -- k1 is larger than logBase 10 x. If k1 > 1 + logBase 10 x,-        -- we get a leading zero-digit we don't want.-        -- With the approximation 3/10, this happened for-        -- 0.5^1030, 0.5^1040, ..., 0.5^1070 and values close above.-        -- The approximation 8651/28738 guarantees k1 < 1 + logBase 10 x-        -- for IEEE-ish floating point types with exponent fields-        -- <= 17 bits and mantissae of several thousand bits, earlier-        -- convergents to logBase 10 2 would fail for long double.-        -- Using quot instead of div is a little faster and requires-        -- fewer fixup steps for negative lx.-        let lx = p - 1 + e0-            k1 = (lx * 8651) `quot` 28738-        in if lx >= 0 then k1 + 1 else k1-     else-	-- f :: Integer, log :: Float -> Float,-        --               ceiling :: Float -> Int-        ceiling ((log (fromInteger (f+1) :: Float) +-                 fromIntegral e * log (fromInteger b)) /-                   log (fromInteger base))---WAS:            fromInt e * log (fromInteger b))--    fixup n =-      if n >= 0 then-        if r + mUp <= expt base n * s then n else fixup (n+1)-      else-        if expt base (-n) * (r + mUp) <= s then n else fixup (n+1)-   in-   fixup k0--  gen ds rn sN mUpN mDnN =-   let-    (dn, rn') = (rn * base) `quotRem` sN-    mUpN' = mUpN * base-    mDnN' = mDnN * base-   in-   case (rn' < mDnN', rn' + mUpN' > sN) of-    (True,  False) -> dn : ds-    (False, True)  -> dn+1 : ds-    (True,  True)  -> if rn' * 2 < sN then dn : ds else dn+1 : ds-    (False, False) -> gen (dn:ds) rn' sN mUpN' mDnN'--  rds =-   if k >= 0 then-      gen [] r (s * expt base k) mUp mDn-   else-     let bk = expt base (-k) in-     gen [] (r * bk) s (mUp * bk) (mDn * bk)- in- (map fromIntegral (reverse rds), k)--\end{code}---%*********************************************************-%*                                                      *-\subsection{Converting from a Rational to a RealFloat-%*                                                      *-%*********************************************************--[In response to a request for documentation of how fromRational works,-Joe Fasel writes:] A quite reasonable request!  This code was added to-the Prelude just before the 1.2 release, when Lennart, working with an-early version of hbi, noticed that (read . show) was not the identity-for floating-point numbers.  (There was a one-bit error about half the-time.)  The original version of the conversion function was in fact-simply a floating-point divide, as you suggest above. The new version-is, I grant you, somewhat denser.--Unfortunately, Joe's code doesn't work!  Here's an example:--main = putStr (shows (1.82173691287639817263897126389712638972163e-300::Double) "\n")--This program prints-        0.0000000000000000-instead of-        1.8217369128763981e-300--Here's Joe's code:--\begin{pseudocode}-fromRat :: (RealFloat a) => Rational -> a-fromRat x = x'-        where x' = f e----              If the exponent of the nearest floating-point number to x---              is e, then the significand is the integer nearest xb^(-e),---              where b is the floating-point radix.  We start with a good---              guess for e, and if it is correct, the exponent of the---              floating-point number we construct will again be e.  If---              not, one more iteration is needed.--              f e   = if e' == e then y else f e'-                      where y      = encodeFloat (round (x * (1 % b)^^e)) e-                            (_,e') = decodeFloat y-              b     = floatRadix x'----              We obtain a trial exponent by doing a floating-point---              division of x's numerator by its denominator.  The---              result of this division may not itself be the ultimate---              result, because of an accumulation of three rounding---              errors.--              (s,e) = decodeFloat (fromInteger (numerator x) `asTypeOf` x'-                                        / fromInteger (denominator x))-\end{pseudocode}--Now, here's Lennart's code (which works)--\begin{code}--- | Converts a 'Rational' value into any type in class 'RealFloat'.-{-# RULES-"fromRat/Float"     fromRat = (fromRational :: Rational -> Float)-"fromRat/Double"    fromRat = (fromRational :: Rational -> Double)-  #-}--{-# NOINLINE [1] fromRat #-}-fromRat :: (RealFloat a) => Rational -> a---- Deal with special cases first, delegating the real work to fromRat'-fromRat (n :% 0) | n > 0     =  1/0        -- +Infinity-                 | n < 0     = -1/0        -- -Infinity-                 | otherwise =  0/0        -- NaN--fromRat (n :% d) | n > 0     = fromRat' (n :% d)-                 | n < 0     = - fromRat' ((-n) :% d)-                 | otherwise = encodeFloat 0 0             -- Zero---- Conversion process:--- Scale the rational number by the RealFloat base until--- it lies in the range of the mantissa (as used by decodeFloat/encodeFloat).--- Then round the rational to an Integer and encode it with the exponent--- that we got from the scaling.--- To speed up the scaling process we compute the log2 of the number to get--- a first guess of the exponent.--fromRat' :: (RealFloat a) => Rational -> a--- Invariant: argument is strictly positive-fromRat' x = r-  where b = floatRadix r-        p = floatDigits r-        (minExp0, _) = floatRange r-        minExp = minExp0 - p            -- the real minimum exponent-        xMax   = toRational (expt b p)-        p0 = (integerLogBase b (numerator x) - integerLogBase b (denominator x) - p) `max` minExp-        -- if x = n/d and ln = integerLogBase b n, ld = integerLogBase b d,-        -- then b^(ln-ld-1) < x < b^(ln-ld+1)-        f = if p0 < 0 then 1 :% expt b (-p0) else expt b p0 :% 1-        x0 = x / f-        -- if ln - ld >= minExp0, then b^(p-1) < x0 < b^(p+1), so there's at most-        -- one scaling step needed, otherwise, x0 < b^p and no scaling is needed-        (x', p') = if x0 >= xMax then (x0 / toRational b, p0+1) else (x0, p0)-        r = encodeFloat (round x') p'---- Exponentiation with a cache for the most common numbers.-minExpt, maxExpt :: Int-minExpt = 0-maxExpt = 1100--expt :: Integer -> Int -> Integer-expt base n =-    if base == 2 && n >= minExpt && n <= maxExpt then-        expts!n-    else-        if base == 10 && n <= maxExpt10 then-            expts10!n-        else-            base^n--expts :: Array Int Integer-expts = array (minExpt,maxExpt) [(n,2^n) | n <- [minExpt .. maxExpt]]--maxExpt10 :: Int-maxExpt10 = 324--expts10 :: Array Int Integer-expts10 = array (minExpt,maxExpt10) [(n,10^n) | n <- [minExpt .. maxExpt10]]---- Compute the (floor of the) log of i in base b.--- Simplest way would be just divide i by b until it's smaller then b, but that would--- be very slow!  We are just slightly more clever, except for base 2, where--- we take advantage of the representation of Integers.--- The general case could be improved by a lookup table for--- approximating the result by integerLog2 i / integerLog2 b.-integerLogBase :: Integer -> Integer -> Int-integerLogBase b i-   | i < b     = 0-   | b == 2    = I# (integerLog2# i)-   | otherwise = I# (integerLogBase# b i)--\end{code}--Unfortunately, the old conversion code was awfully slow due to-a) a slow integer logarithm-b) repeated calculation of gcd's--For the case of Rational's coming from a Float or Double via toRational,-we can exploit the fact that the denominator is a power of two, which for-these brings a huge speedup since we need only shift and add instead-of division.--The below is an adaption of fromRat' for the conversion to-Float or Double exploiting the known floatRadix and avoiding-divisions as much as possible.--\begin{code}-{-# SPECIALISE fromRat'' :: Int -> Int -> Integer -> Integer -> Float,-                            Int -> Int -> Integer -> Integer -> Double #-}-fromRat'' :: RealFloat a => Int -> Int -> Integer -> Integer -> a--- Invariant: n and d strictly positive-fromRat'' minEx@(I# me#) mantDigs@(I# md#) n d =-    case integerLog2IsPowerOf2# d of-      (# ld#, pw# #)-        | isTrue# (pw# ==# 0#) ->-          case integerLog2# n of-            ln# | isTrue# (ln# >=# (ld# +# me# -# 1#)) ->-                  -- this means n/d >= 2^(minEx-1), i.e. we are guaranteed to get-                  -- a normalised number, round to mantDigs bits-                  if isTrue# (ln# <# md#)-                    then encodeFloat n (I# (negateInt# ld#))-                    else let n'  = n `shiftR` (I# (ln# +# 1# -# md#))-                             n'' = case roundingMode# n (ln# -# md#) of-                                    0# -> n'-                                    2# -> n' + 1-                                    _  -> case fromInteger n' .&. (1 :: Int) of-                                            0 -> n'-                                            _ -> n' + 1-                         in encodeFloat n'' (I# (ln# -# ld# +# 1# -# md#))-                | otherwise ->-                  -- n/d < 2^(minEx-1), a denorm or rounded to 2^(minEx-1)-                  -- the exponent for encoding is always minEx-mantDigs-                  -- so we must shift right by (minEx-mantDigs) - (-ld)-                  case ld# +# (me# -# md#) of-                    ld'# | isTrue# (ld'# <=# 0#) -> -- we would shift left, so we don't shift-                           encodeFloat n (I# ((me# -# md#) -# ld'#))-                         | isTrue# (ld'# <=# ln#) ->-                           let n' = n `shiftR` (I# ld'#)-                           in case roundingMode# n (ld'# -# 1#) of-                                0# -> encodeFloat n' (minEx - mantDigs)-                                1# -> if fromInteger n' .&. (1 :: Int) == 0-                                        then encodeFloat n' (minEx-mantDigs)-                                        else encodeFloat (n' + 1) (minEx-mantDigs)-                                _  -> encodeFloat (n' + 1) (minEx-mantDigs)-                         | isTrue# (ld'# ># (ln# +# 1#)) -> encodeFloat 0 0 -- result of shift < 0.5-                         | otherwise ->  -- first bit of n shifted to 0.5 place-                           case integerLog2IsPowerOf2# n of-                            (# _, 0# #) -> encodeFloat 0 0  -- round to even-                            (# _, _ #)  -> encodeFloat 1 (minEx - mantDigs)-        | otherwise ->-          let ln = I# (integerLog2# n)-              ld = I# ld#-              -- 2^(ln-ld-1) < n/d < 2^(ln-ld+1)-              p0 = max minEx (ln - ld)-              (n', d')-                | p0 < mantDigs = (n `shiftL` (mantDigs - p0), d)-                | p0 == mantDigs = (n, d)-                | otherwise     = (n, d `shiftL` (p0 - mantDigs))-              -- if ln-ld < minEx, then n'/d' < 2^mantDigs, else-              -- 2^(mantDigs-1) < n'/d' < 2^(mantDigs+1) and we-              -- may need one scaling step-              scale p a b-                | (b `shiftL` mantDigs) <= a = (p+1, a, b `shiftL` 1)-                | otherwise = (p, a, b)-              (p', n'', d'') = scale (p0-mantDigs) n' d'-              -- n''/d'' < 2^mantDigs and p' == minEx-mantDigs or n''/d'' >= 2^(mantDigs-1)-              rdq = case n'' `quotRem` d'' of-                     (q,r) -> case compare (r `shiftL` 1) d'' of-                                LT -> q-                                EQ -> if fromInteger q .&. (1 :: Int) == 0-                                        then q else q+1-                                GT -> q+1-          in  encodeFloat rdq p'-\end{code}---%*********************************************************-%*                                                      *-\subsection{Floating point numeric primops}-%*                                                      *-%*********************************************************--Definitions of the boxed PrimOps; these will be-used in the case of partial applications, etc.--\begin{code}-plusFloat, minusFloat, timesFloat, divideFloat :: Float -> Float -> Float-plusFloat   (F# x) (F# y) = F# (plusFloat# x y)-minusFloat  (F# x) (F# y) = F# (minusFloat# x y)-timesFloat  (F# x) (F# y) = F# (timesFloat# x y)-divideFloat (F# x) (F# y) = F# (divideFloat# x y)--negateFloat :: Float -> Float-negateFloat (F# x)        = F# (negateFloat# x)--gtFloat, geFloat, eqFloat, neFloat, ltFloat, leFloat :: Float -> Float -> Bool-gtFloat     (F# x) (F# y) = isTrue# (gtFloat# x y)-geFloat     (F# x) (F# y) = isTrue# (geFloat# x y)-eqFloat     (F# x) (F# y) = isTrue# (eqFloat# x y)-neFloat     (F# x) (F# y) = isTrue# (neFloat# x y)-ltFloat     (F# x) (F# y) = isTrue# (ltFloat# x y)-leFloat     (F# x) (F# y) = isTrue# (leFloat# x y)--expFloat, logFloat, sqrtFloat :: Float -> Float-sinFloat, cosFloat, tanFloat  :: Float -> Float-asinFloat, acosFloat, atanFloat  :: Float -> Float-sinhFloat, coshFloat, tanhFloat  :: Float -> Float-expFloat    (F# x) = F# (expFloat# x)-logFloat    (F# x) = F# (logFloat# x)-sqrtFloat   (F# x) = F# (sqrtFloat# x)-sinFloat    (F# x) = F# (sinFloat# x)-cosFloat    (F# x) = F# (cosFloat# x)-tanFloat    (F# x) = F# (tanFloat# x)-asinFloat   (F# x) = F# (asinFloat# x)-acosFloat   (F# x) = F# (acosFloat# x)-atanFloat   (F# x) = F# (atanFloat# x)-sinhFloat   (F# x) = F# (sinhFloat# x)-coshFloat   (F# x) = F# (coshFloat# x)-tanhFloat   (F# x) = F# (tanhFloat# x)--powerFloat :: Float -> Float -> Float-powerFloat  (F# x) (F# y) = F# (powerFloat# x y)---- definitions of the boxed PrimOps; these will be--- used in the case of partial applications, etc.--plusDouble, minusDouble, timesDouble, divideDouble :: Double -> Double -> Double-plusDouble   (D# x) (D# y) = D# (x +## y)-minusDouble  (D# x) (D# y) = D# (x -## y)-timesDouble  (D# x) (D# y) = D# (x *## y)-divideDouble (D# x) (D# y) = D# (x /## y)--negateDouble :: Double -> Double-negateDouble (D# x)        = D# (negateDouble# x)--gtDouble, geDouble, eqDouble, neDouble, leDouble, ltDouble :: Double -> Double -> Bool-gtDouble    (D# x) (D# y) = isTrue# (x >##  y)-geDouble    (D# x) (D# y) = isTrue# (x >=## y)-eqDouble    (D# x) (D# y) = isTrue# (x ==## y)-neDouble    (D# x) (D# y) = isTrue# (x /=## y)-ltDouble    (D# x) (D# y) = isTrue# (x <##  y)-leDouble    (D# x) (D# y) = isTrue# (x <=## y)--double2Float :: Double -> Float-double2Float (D# x) = F# (double2Float# x)--float2Double :: Float -> Double-float2Double (F# x) = D# (float2Double# x)--expDouble, logDouble, sqrtDouble :: Double -> Double-sinDouble, cosDouble, tanDouble  :: Double -> Double-asinDouble, acosDouble, atanDouble  :: Double -> Double-sinhDouble, coshDouble, tanhDouble  :: Double -> Double-expDouble    (D# x) = D# (expDouble# x)-logDouble    (D# x) = D# (logDouble# x)-sqrtDouble   (D# x) = D# (sqrtDouble# x)-sinDouble    (D# x) = D# (sinDouble# x)-cosDouble    (D# x) = D# (cosDouble# x)-tanDouble    (D# x) = D# (tanDouble# x)-asinDouble   (D# x) = D# (asinDouble# x)-acosDouble   (D# x) = D# (acosDouble# x)-atanDouble   (D# x) = D# (atanDouble# x)-sinhDouble   (D# x) = D# (sinhDouble# x)-coshDouble   (D# x) = D# (coshDouble# x)-tanhDouble   (D# x) = D# (tanhDouble# x)--powerDouble :: Double -> Double -> Double-powerDouble  (D# x) (D# y) = D# (x **## y)-\end{code}--\begin{code}-foreign import ccall unsafe "isFloatNaN" isFloatNaN :: Float -> Int-foreign import ccall unsafe "isFloatInfinite" isFloatInfinite :: Float -> Int-foreign import ccall unsafe "isFloatDenormalized" isFloatDenormalized :: Float -> Int-foreign import ccall unsafe "isFloatNegativeZero" isFloatNegativeZero :: Float -> Int-foreign import ccall unsafe "isFloatFinite" isFloatFinite :: Float -> Int--foreign import ccall unsafe "isDoubleNaN" isDoubleNaN :: Double -> Int-foreign import ccall unsafe "isDoubleInfinite" isDoubleInfinite :: Double -> Int-foreign import ccall unsafe "isDoubleDenormalized" isDoubleDenormalized :: Double -> Int-foreign import ccall unsafe "isDoubleNegativeZero" isDoubleNegativeZero :: Double -> Int-foreign import ccall unsafe "isDoubleFinite" isDoubleFinite :: Double -> Int-\end{code}--%*********************************************************-%*                                                      *-\subsection{Coercion rules}-%*                                                      *-%*********************************************************--\begin{code}--word2Double :: Word -> Double-word2Double (W# w) = D# (word2Double# w)--word2Float :: Word -> Float-word2Float (W# w) = F# (word2Float# w)--{-# RULES-"fromIntegral/Int->Float"   fromIntegral = int2Float-"fromIntegral/Int->Double"  fromIntegral = int2Double-"fromIntegral/Word->Float"  fromIntegral = word2Float-"fromIntegral/Word->Double" fromIntegral = word2Double-"realToFrac/Float->Float"   realToFrac   = id :: Float -> Float-"realToFrac/Float->Double"  realToFrac   = float2Double-"realToFrac/Double->Float"  realToFrac   = double2Float-"realToFrac/Double->Double" realToFrac   = id :: Double -> Double-"realToFrac/Int->Double"    realToFrac   = int2Double	-- See Note [realToFrac int-to-float]-"realToFrac/Int->Float"     realToFrac   = int2Float	-- 	..ditto-    #-}-\end{code}--Note [realToFrac int-to-float]-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-Don found that the RULES for realToFrac/Int->Double and simliarly-Float made a huge difference to some stream-fusion programs.  Here's-an example--      import Data.Array.Vector--      n = 40000000--      main = do-            let c = replicateU n (2::Double)-                a = mapU realToFrac (enumFromToU 0 (n-1) ) :: UArr Double-            print (sumU (zipWithU (*) c a))--Without the RULE we get this loop body:--      case $wtoRational sc_sY4 of ww_aM7 { (# ww1_aM9, ww2_aMa #) ->-      case $wfromRat ww1_aM9 ww2_aMa of tpl_X1P { D# ipv_sW3 ->-      Main.$s$wfold-        (+# sc_sY4 1)-        (+# wild_X1i 1)-        (+## sc2_sY6 (*## 2.0 ipv_sW3))--And with the rule:--     Main.$s$wfold-        (+# sc_sXT 1)-        (+# wild_X1h 1)-        (+## sc2_sXV (*## 2.0 (int2Double# sc_sXT)))--The running time of the program goes from 120 seconds to 0.198 seconds-with the native backend, and 0.143 seconds with the C backend.--A few more details in Trac #2251, and the patch message-"Add RULES for realToFrac from Int".--%*********************************************************-%*                                                      *-\subsection{Utils}-%*                                                      *-%*********************************************************--\begin{code}-showSignedFloat :: (RealFloat a)-  => (a -> ShowS)       -- ^ a function that can show unsigned values-  -> Int                -- ^ the precedence of the enclosing context-  -> a                  -- ^ the value to show-  -> ShowS-showSignedFloat showPos p x-   | x < 0 || isNegativeZero x-       = showParen (p > 6) (showChar '-' . showPos (-x))-   | otherwise = showPos x-\end{code}--We need to prevent over/underflow of the exponent in encodeFloat when-called from scaleFloat, hence we clamp the scaling parameter.-We must have a large enough range to cover the maximum difference of-exponents returned by decodeFloat.-\begin{code}-clamp :: Int -> Int -> Int-clamp bd k = max (-bd) (min bd k)-\end{code}
GHC/Foreign.hs view
@@ -6,7 +6,7 @@ -- Module      :  GHC.Foreign -- Copyright   :  (c) The University of Glasgow, 2008-2011 -- License     :  see libraries/base/LICENSE--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  internal -- Portability :  non-portable@@ -17,22 +17,22 @@  module GHC.Foreign (     -- * C strings with a configurable encoding-    +     -- conversion of C strings into Haskell strings     --     peekCString,     peekCStringLen,-    +     -- conversion of Haskell strings into C strings     --     newCString,     newCStringLen,-    +     -- conversion of Haskell strings into C strings using temporary storage     --     withCString,     withCStringLen,-    +     charIsRepresentable,   ) where @@ -44,7 +44,6 @@ import Data.Word  -- Imports for the locale-encoding version of marshallers-import Control.Monad  import Data.Tuple (fst) import Data.Maybe
GHC/ForeignPtr.hs view
@@ -5,20 +5,20 @@            , UnboxedTuples   #-} {-# OPTIONS_HADDOCK hide #-}-{-# LANGUAGE DeriveDataTypeable, StandaloneDeriving #-}+{-# LANGUAGE AutoDeriveTypeable, StandaloneDeriving #-}  ----------------------------------------------------------------------------- -- | -- Module      :  GHC.ForeignPtr -- Copyright   :  (c) The University of Glasgow, 1992-2003 -- License     :  see libraries/base/LICENSE--- +-- -- Maintainer  :  cvs-ghc@haskell.org -- Stability   :  internal -- Portability :  non-portable (GHC extensions) -- -- GHC's implementation of the 'ForeignPtr' data type.--- +-- -----------------------------------------------------------------------------  module GHC.ForeignPtr@@ -44,8 +44,8 @@         finalizeForeignPtr   ) where -import Control.Monad    ( sequence_ ) import Foreign.Storable+import Data.Foldable    ( sequence_ ) import Data.Typeable  import GHC.Show@@ -105,7 +105,7 @@ -- |A finalizer is represented as a pointer to a foreign function that, at -- finalisation time, gets as an argument a plain pointer variant of the -- foreign pointer that the finalizer is associated with.--- +-- -- Note that the foreign function /must/ use the @ccall@ calling convention. -- type FinalizerPtr a        = FunPtr (Ptr a -> IO ())@@ -140,7 +140,7 @@ -- 'mallocForeignPtr' is equivalent to -- -- >    do { p <- malloc; newForeignPtr finalizerFree p }--- +-- -- although it may be implemented differently internally: you may not -- assume that the memory returned by 'mallocForeignPtr' has been -- allocated with 'Foreign.Marshal.Alloc.malloc'.@@ -151,7 +151,7 @@ -- free the memory.  Use of 'mallocForeignPtr' and associated -- functions is strongly recommended in preference to 'newForeignPtr' -- with a finalizer.--- +-- mallocForeignPtr = doMalloc undefined   where doMalloc :: Storable b => b -> IO (ForeignPtr b)         doMalloc a@@ -171,7 +171,7 @@ mallocForeignPtrBytes :: Int -> IO (ForeignPtr a) mallocForeignPtrBytes size | size < 0 =   error "mallocForeignPtrBytes: size must be >= 0"-mallocForeignPtrBytes (I# size) = do +mallocForeignPtrBytes (I# size) = do   r <- newIORef NoFinalizers   IO $ \s ->      case newPinnedByteArray# size s      of { (# s', mbarr# #) ->@@ -205,7 +205,7 @@ -- only inside Haskell (such as those created for packed strings). -- Attempts to add a finalizer to a ForeignPtr created this way, or to -- finalize such a pointer, will throw an exception.--- +-- mallocPlainForeignPtr :: Storable a => IO (ForeignPtr a) mallocPlainForeignPtr = doMalloc undefined   where doMalloc :: Storable b => b -> IO (ForeignPtr b)@@ -284,7 +284,7 @@ -- are finalized objects, so a finalizer should not refer to a 'Handle' -- (including @stdout@, @stdin@ or @stderr@). ---addForeignPtrConcFinalizer (ForeignPtr _ c) finalizer = +addForeignPtrConcFinalizer (ForeignPtr _ c) finalizer =   addForeignPtrConcFinalizer_ c finalizer  addForeignPtrConcFinalizer_ :: ForeignPtrContents -> IO () -> IO ()@@ -299,7 +299,7 @@ addForeignPtrConcFinalizer_ f@(MallocPtr fo r) finalizer = do   noFinalizers <- insertHaskellFinalizer r finalizer   if noFinalizers-     then  IO $ \s -> +     then  IO $ \s ->                case mkWeak# fo () (do foreignPtrFinalizer r; touch f) s of                   (# s1, _ #) -> (# s1, () #)      else return ()@@ -378,7 +378,7 @@ -- actions. In particular 'Foreign.ForeignPtr.withForeignPtr' -- does a 'touchForeignPtr' after it -- executes the user action.--- +-- -- Note that this function should not be used to express dependencies -- between finalizers on 'ForeignPtr's.  For example, if the finalizer -- for a 'ForeignPtr' @F1@ calls 'touchForeignPtr' on a second
GHC/GHCi.hs view
@@ -21,7 +21,7 @@         GHCiSandboxIO(..), NoIO()     ) where -import GHC.Base (IO(), Monad, (>>=), return, id, (.))+import GHC.Base (IO(), Monad, Functor(fmap), Applicative(..), (>>=), return, id, (.), ap)  -- | A monad that can execute GHCi statements by lifting them out of -- m into the IO monad. (e.g state monads)@@ -33,6 +33,13 @@  -- | A monad that doesn't allow any IO. newtype NoIO a = NoIO { noio :: IO a }++instance Functor NoIO where+  fmap f (NoIO a) = NoIO (fmap f a)++instance Applicative NoIO where+  pure  = return+  (<*>) = ap  instance Monad NoIO where     return a  = NoIO (return a)
GHC/Generics.hs view
@@ -13,15 +13,15 @@ -- Module      :  GHC.Generics -- Copyright   :  (c) Universiteit Utrecht 2010-2011, University of Oxford 2012-2013 -- License     :  see libraries/base/LICENSE--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  internal -- Portability :  non-portable ----- /Since: 4.6.0.0/--- +-- @since 4.6.0.0+-- -- If you're using @GHC.Generics@, you should consider using the--- <http://hackage.haskell.org/package/generic-deriving> package, which +-- <http://hackage.haskell.org/package/generic-deriving> package, which -- contains many useful generic functions.  module GHC.Generics  (@@ -263,7 +263,7 @@ -- data    'V1'        p                       -- lifted version of Empty -- data    'U1'        p = 'U1'                  -- lifted version of () -- data    (':+:') f g p = 'L1' (f p) | 'R1' (g p) -- lifted version of 'Either'--- data    (':*:') f g p = (f p) ':*:' (g p)     -- lifted version of (,) +-- data    (':*:') f g p = (f p) ':*:' (g p)     -- lifted version of (,) -- newtype 'K1'    i c p = 'K1' { 'unK1' :: c }    -- a container for a c -- newtype 'M1'  i t f p = 'M1' { 'unM1' :: f p }  -- a wrapper -- @
GHC/IO.hs view
@@ -13,7 +13,7 @@ -- Module      :  GHC.IO -- Copyright   :  (c) The University of Glasgow 1994-2002 -- License     :  see libraries/base/LICENSE--- +-- -- Maintainer  :  cvs-ghc@haskell.org -- Stability   :  internal -- Portability :  non-portable (GHC Extensions)@@ -34,7 +34,7 @@         FilePath,          catchException, catchAny, throwIO,-        mask, mask_, uninterruptibleMask, uninterruptibleMask_, +        mask, mask_, uninterruptibleMask, uninterruptibleMask_,         MaskingState(..), getMaskingState,         unsafeUnmask,         onException, bracket, finally, evaluate@@ -44,7 +44,6 @@ import GHC.ST import GHC.Exception import GHC.Show-import Data.Maybe  import {-# SOURCE #-} GHC.IO.Exception ( userError ) @@ -62,7 +61,7 @@ Compiler  - types of various primitives in PrimOp.lhs  RTS       - forceIO (StgMiscClosures.hc)-          - catchzh_fast, (un)?blockAsyncExceptionszh_fast, raisezh_fast +          - catchzh_fast, (un)?blockAsyncExceptionszh_fast, raisezh_fast             (Exceptions.hc)           - raiseAsync (Schedule.c) @@ -130,8 +129,8 @@         two side effects that were meant to be separate.  A good example         is using multiple global variables (like @test@ in the example below). -  * Make sure that the either you switch off let-floating (@-fno-full-laziness@), or that the -        call to 'unsafePerformIO' cannot float outside a lambda.  For example, +  * Make sure that the either you switch off let-floating (@-fno-full-laziness@), or that the+        call to 'unsafePerformIO' cannot float outside a lambda.  For example,         if you say:         @            f x = unsafePerformIO (newIORef [])@@ -148,7 +147,7 @@  >     test :: IORef [a] >     test = unsafePerformIO $ newIORef []->     +> >     main = do >             writeIORef test [42] >             bang <- readIORef test@@ -164,7 +163,7 @@ unsafePerformIO :: IO a -> a unsafePerformIO m = unsafeDupablePerformIO (noDuplicate >> m) -{-| +{-| This version of 'unsafePerformIO' is more efficient because it omits the check that the IO is only being performed by a single thread.  Hence, when you use 'unsafeDupablePerformIO',@@ -175,32 +174,40 @@ in the middle without an exception being raised. Therefore, functions like 'bracket' cannot be used safely within 'unsafeDupablePerformIO'. -/Since: 4.4.0.0/+@since 4.4.0.0 -} {-# NOINLINE unsafeDupablePerformIO #-}+    -- See Note [unsafeDupablePerformIO is NOINLINE] unsafeDupablePerformIO  :: IO a -> a unsafeDupablePerformIO (IO m) = lazy (case m realWorld# of (# _, r #) -> r)+     -- See Note [unsafeDupablePerformIO has a lazy RHS] +-- Note [unsafeDupablePerformIO is NOINLINE]+-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- Why do we NOINLINE unsafeDupablePerformIO?  See the comment with -- GHC.ST.runST.  Essentially the issue is that the IO computation -- inside unsafePerformIO must be atomic: it must either all run, or -- not at all.  If we let the compiler see the application of the IO -- to realWorld#, it might float out part of the IO. +-- Note [unsafeDupablePerformIO has a lazy RHS]+-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- Why is there a call to 'lazy' in unsafeDupablePerformIO? -- If we don't have it, the demand analyser discovers the following strictness -- for unsafeDupablePerformIO:  C(U(AV)) -- But then consider---      unsafeDupablePerformIO (\s -> let r = f x in +--      unsafeDupablePerformIO (\s -> let r = f x in --                             case writeIORef v r s of (# s1, _ #) ->---                             (# s1, r #)+--                             (# s1, r #) ) -- The strictness analyser will find that the binding for r is strict,--- (because of uPIO's strictness sig), and so it'll evaluate it before --- doing the writeIORef.  This actually makes tests/lib/should_run/memo002--- get a deadlock!  +-- (because of uPIO's strictness sig), and so it'll evaluate it before+-- doing the writeIORef.  This actually makes libraries/base/tests/memo002+-- get a deadlock, where we specifically wanted to write a lazy thunk+-- into the ref cell. -- -- Solution: don't expose the strictness of unsafeDupablePerformIO, --           by hiding it with 'lazy'+-- But see discussion in Trac #9390 (comment:33)  {-| 'unsafeInterleaveIO' allows 'IO' computation to be deferred lazily.@@ -238,7 +245,7 @@                 in                 (# s, r #)) -{-| +{-| Ensures that the suspensions under evaluation by the current thread are unique; that is, the current thread is not evaluating anything that is also under evaluation by another thread that has also executed@@ -341,7 +348,7 @@ -- exception is received. data MaskingState   = Unmasked -- ^ asynchronous exceptions are unmasked (the normal state)-  | MaskedInterruptible +  | MaskedInterruptible       -- ^ the state during 'mask': asynchronous exceptions are masked, but blocking operations may still be interrupted   | MaskedUninterruptible       -- ^ the state during 'uninterruptibleMask': asynchronous exceptions are masked, and blocking operations may not be interrupted@@ -349,7 +356,7 @@  -- | Returns the 'MaskingState' for the current thread. getMaskingState :: IO MaskingState-getMaskingState  = IO $ \s -> +getMaskingState  = IO $ \s ->   case getMaskingState# s of      (# s', i #) -> (# s', case i of                              0# -> Unmasked@@ -395,13 +402,14 @@ -- state if the masked thread /blocks/ in certain ways; see -- "Control.Exception#interruptible". ----- Threads created by 'Control.Concurrent.forkIO' inherit the masked--- state from the parent; that is, to start a thread in blocked mode,+-- Threads created by 'Control.Concurrent.forkIO' inherit the+-- 'MaskingState' from the parent; that is, to start a thread in the+-- 'MaskedInterruptible' state, -- use @mask_ $ forkIO ...@.  This is particularly useful if you need -- to establish an exception handler in the forked thread before any -- asynchronous exceptions are received.  To create a a new thread in -- an unmasked state use 'Control.Concurrent.forkIOUnmasked'.--- +-- mask  :: ((forall a. IO a -> IO a) -> IO b) -> IO b  -- | Like 'mask', but does not pass a @restore@ action to the argument.
GHC/IO/Buffer.hs view
@@ -7,7 +7,7 @@ -- Module      :  GHC.IO.Buffer -- Copyright   :  (c) The University of Glasgow 2008 -- License     :  see libraries/base/LICENSE--- +-- -- Maintainer  :  cvs-ghc@haskell.org -- Stability   :  internal -- Portability :  non-portable (GHC Extensions)@@ -179,11 +179,11 @@ -- of the file. data Buffer e   = Buffer {-	bufRaw   :: !(RawBuffer e),+        bufRaw   :: !(RawBuffer e),         bufState :: BufferState,-	bufSize  :: !Int,          -- in elements, not bytes-	bufL     :: !Int,          -- offset of first item in the buffer-	bufR     :: !Int           -- offset of last item + 1+        bufSize  :: !Int,          -- in elements, not bytes+        bufL     :: !Int,          -- offset of first item in the buffer+        bufR     :: !Int           -- offset of last item + 1   }  #ifdef CHARBUF_UTF16@@ -237,7 +237,7 @@ bufferAdd i buf@Buffer{ bufR=w } = buf{ bufR=w+i }  emptyBuffer :: RawBuffer e -> Int -> BufferState -> Buffer e-emptyBuffer raw sz state = +emptyBuffer raw sz state =   Buffer{ bufRaw=raw, bufState=state, bufR=0, bufL=0, bufSize=sz }  newByteBuffer :: Int -> BufferState -> IO (Buffer Word8)@@ -270,7 +270,7 @@ --   * r <= w --   * if r == w, and the buffer is for reading, then r == 0 && w == 0 --   * a write buffer is never full.  If an operation---     fills up the buffer, it will always flush it before +--     fills up the buffer, it will always flush it before --     returning. --   * a read buffer may be full as a result of hLookAhead.  In normal --     operation, a read buffer always has at least one character of space.@@ -278,10 +278,10 @@ checkBuffer :: Buffer a -> IO () checkBuffer buf@Buffer{ bufState = state, bufL=r, bufR=w, bufSize=size } = do      check buf (-      	size > 0-      	&& r <= w-      	&& w <= size-      	&& ( r /= w || state == WriteBuffer || (r == 0 && w == 0) )+        size > 0+        && r <= w+        && w <= size+        && ( r /= w || state == WriteBuffer || (r == 0 && w == 0) )         && ( state /= WriteBuffer || w < size ) -- write buffer is never full       ) 
GHC/IO/BufferedIO.hs view
@@ -7,7 +7,7 @@ -- Module      :  GHC.IO.BufferedIO -- Copyright   :  (c) The University of Glasgow 2008 -- License     :  see libraries/base/LICENSE--- +-- -- Maintainer  :  cvs-ghc@haskell.org -- Stability   :  internal -- Portability :  non-portable (GHC Extensions)@@ -25,7 +25,6 @@ import GHC.Ptr import Data.Word import GHC.Num-import Data.Maybe import GHC.IO.Device as IODevice import GHC.IO.Device as RawIO import GHC.IO.Buffer@@ -61,7 +60,7 @@   -- There is no corresponding operation for read buffers, because before   -- reading the client will always call 'fillReadBuffer'.   emptyWriteBuffer  :: dev -> Buffer Word8 -> IO (Buffer Word8)-  emptyWriteBuffer _dev buf +  emptyWriteBuffer _dev buf     = return buf{ bufL=0, bufR=0, bufState = WriteBuffer }    -- | Flush all the data from the supplied write buffer out to the device.
GHC/IO/Device.hs view
@@ -6,7 +6,7 @@ -- Module      :  GHC.IO.Device -- Copyright   :  (c) The University of Glasgow, 1994-2008 -- License     :  see libraries/base/LICENSE--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  internal -- Portability :  non-portable@@ -20,7 +20,7 @@         IODevice(..),         IODeviceType(..),         SeekMode(..)-    ) where  +    ) where  import GHC.Base import GHC.Word@@ -29,7 +29,6 @@ import GHC.Read import GHC.Show import GHC.Ptr-import Data.Maybe import GHC.Num import GHC.IO import {-# SOURCE #-} GHC.IO.Exception ( unsupportedOperation )@@ -63,7 +62,7 @@   -- to read (if @write@ is 'False') or space to write new data (if   -- @write@ is 'True').  @msecs@ specifies how long to wait, in   -- milliseconds.-  -- +  --   ready :: a -> Bool -> Int -> IO Bool    -- | closes the device.  Further operations on the device should@@ -91,7 +90,7 @@   getSize _ = ioe_unsupportedOperation    -- | change the size of the data.-  setSize :: a -> Integer -> IO () +  setSize :: a -> Integer -> IO ()   setSize _ _ = ioe_unsupportedOperation    -- | for terminal devices, changes whether characters are echoed on
GHC/IO/Encoding.hs view
@@ -7,7 +7,7 @@ -- Module      :  GHC.IO.Encoding -- Copyright   :  (c) The University of Glasgow, 2008-2009 -- License     :  see libraries/base/LICENSE--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  internal -- Portability :  non-portable@@ -21,7 +21,7 @@         latin1, latin1_encode, latin1_decode,         utf8, utf8_bom,         utf16, utf16le, utf16be,-        utf32, utf32le, utf32be, +        utf32, utf32le, utf32be,         initLocaleEncoding,         getLocaleEncoding, getFileSystemEncoding, getForeignEncoding,         setLocaleEncoding, setFileSystemEncoding, setForeignEncoding,@@ -44,12 +44,11 @@ import qualified GHC.IO.Encoding.UTF8   as UTF8 import qualified GHC.IO.Encoding.UTF16  as UTF16 import qualified GHC.IO.Encoding.UTF32  as UTF32+import GHC.List import GHC.Word  import Data.IORef import Data.Char (toUpper)-import Data.List-import Data.Maybe import System.IO.Unsafe (unsafePerformIO)  -- -----------------------------------------------------------------------------@@ -104,7 +103,7 @@  -- | The Unicode encoding of the current locale ----- /Since: 4.5.0.0/+-- @since 4.5.0.0 getLocaleEncoding :: IO TextEncoding  -- | The Unicode encoding of the current locale, but allowing arbitrary@@ -117,17 +116,17 @@ -- the use of code pages is deprecated: Strings should be retrieved -- via the "wide" W-family of UTF-16 APIs instead ----- /Since: 4.5.0.0/+-- @since 4.5.0.0 getFileSystemEncoding :: IO TextEncoding  -- | The Unicode encoding of the current locale, but where undecodable -- bytes are replaced with their closest visual match. Used for -- the 'CString' marshalling functions in "Foreign.C.String" ----- /Since: 4.5.0.0/+-- @since 4.5.0.0 getForeignEncoding :: IO TextEncoding --- | /Since: 4.5.0.0/+-- | @since 4.5.0.0 setLocaleEncoding, setFileSystemEncoding, setForeignEncoding :: TextEncoding -> IO ()  (getLocaleEncoding, setLocaleEncoding)         = mkGlobal initLocaleEncoding@@ -139,7 +138,7 @@     x_ref <- newIORef x     return (readIORef x_ref, writeIORef x_ref) --- | /Since: 4.5.0.0/+-- | @since 4.5.0.0 initLocaleEncoding, initFileSystemEncoding, initForeignEncoding :: TextEncoding  #if !defined(mingw32_HOST_OS)@@ -170,11 +169,11 @@ -- discards information, so encode followed by decode is not the -- identity. ----- /Since: 4.4.0.0/+-- @since 4.4.0.0 char8 :: TextEncoding char8 = Latin1.latin1 --- | Look up the named Unicode encoding.  May fail with +-- | Look up the named Unicode encoding.  May fail with -- --  * 'isDoesNotExistError' if the encoding is unknown --@@ -189,7 +188,7 @@ -- There is additional notation (borrowed from GNU iconv) for specifying -- how illegal characters are handled: -----  * a suffix of @\/\/IGNORE@, e.g. @UTF-8\/\/IGNORE@, will cause +--  * a suffix of @\/\/IGNORE@, e.g. @UTF-8\/\/IGNORE@, will cause --    all illegal sequences on input to be ignored, and on output --    will drop all code points that have no representation in the --    target encoding.@@ -259,6 +258,6 @@ latin1_decode input output = fmap (\(_why,input',output') -> (input',output')) $ Latin1.latin1_decode input output --latin1_decode = unsafePerformIO $ do mkTextDecoder Iconv.latin1 >>= return.encode -unknownEncodingErr :: String -> IO a    +unknownEncodingErr :: String -> IO a unknownEncodingErr e = ioException (IOError Nothing NoSuchThing "mkTextEncoding"                                             ("unknown encoding:" ++ e)  Nothing Nothing)
GHC/IO/Encoding/CodePage.hs view
@@ -23,7 +23,7 @@ import GHC.IO.Buffer import Data.Bits import Data.Maybe-import Data.List (lookup)+import Data.OldList (lookup)  import qualified GHC.IO.Encoding.CodePage.API as API import GHC.IO.Encoding.CodePage.Table
GHC/IO/Encoding/CodePage/API.hs view
@@ -1,5 +1,8 @@-{-# LANGUAGE CPP, NoImplicitPrelude, NondecreasingIndentation, RecordWildCards, ScopedTypeVariables #-}+{-# LANGUAGE Trustworthy #-}+{-# LANGUAGE CPP, NoImplicitPrelude, NondecreasingIndentation,+             RecordWildCards, ScopedTypeVariables #-} {-# OPTIONS_GHC -fno-warn-name-shadowing #-}+ module GHC.IO.Encoding.CodePage.API (     mkCodePageEncoding   ) where@@ -8,7 +11,6 @@ import Foreign.Ptr import Foreign.Marshal import Foreign.Storable-import Control.Monad import Data.Bits import Data.Either import Data.Word@@ -71,13 +73,13 @@       ptr <- return $ castPtr $ advancePtr ptr 1       b <- peekArray mAX_DEFAULTCHAR ptr       c <- peekArray mAX_LEADBYTES   (advancePtr ptr mAX_DEFAULTCHAR)-      return $ CPINFO a b c  +      return $ CPINFO a b c     poke ptr val = do       ptr <- return $ castPtr ptr       poke ptr (maxCharSize val)       ptr <- return $ castPtr $ advancePtr ptr 1       pokeArray' "CPINFO.defaultChar" mAX_DEFAULTCHAR ptr                              (defaultChar val)-      pokeArray' "CPINFO.leadByte"    mAX_LEADBYTES   (advancePtr ptr mAX_DEFAULTCHAR) (leadByte val) +      pokeArray' "CPINFO.leadByte"    mAX_LEADBYTES   (advancePtr ptr mAX_DEFAULTCHAR) (leadByte val)  pokeArray' :: Storable a => String -> Int -> Ptr a -> [a] -> IO () pokeArray' msg sz ptr xs | length xs == sz = pokeArray ptr xs@@ -119,10 +121,10 @@ -- -- This is useful for supporting DBCS text encoding on the console without having to statically link -- in huge code tables into all of our executables, or just as a fallback mechanism if a new code page--- is introduced that we don't know how to deal with ourselves yet.  +-- is introduced that we don't know how to deal with ourselves yet. mkCodePageEncoding :: CodingFailureMode -> Word32 -> TextEncoding mkCodePageEncoding cfm cp-  = TextEncoding { +  = TextEncoding {         textEncodingName = "CP" ++ show cp,         mkTextDecoder = newCP (recoverDecode cfm) cpDecode cp,         mkTextEncoder = newCP (recoverEncode cfm) cpEncode cp@@ -135,8 +137,8 @@ newCP rec fn cp = do   -- Fail early if the code page doesn't exist, to match the behaviour of the IConv TextEncoding   max_char_size <- alloca $ \cpinfo_ptr -> do-    success <- c_GetCPInfo cp cpinfo_ptr -    unless success $ throwGetLastError ("GetCPInfo " ++ show cp)+    success <- c_GetCPInfo cp cpinfo_ptr+    when (not success) $ throwGetLastError ("GetCPInfo " ++ show cp)     fmap (fromIntegral . maxCharSize) $ peek cpinfo_ptr    debugIO $ "GetCPInfo " ++ show cp ++ " = " ++ show max_char_size@@ -269,7 +271,7 @@     let sz =       (bufferElems ibuf * 2)     -- UTF-32 always uses 4 bytes. UTF-16 uses at most 4 bytes.              `min` (bufferAvailable obuf * 2) -- In the best case, each pair of UTF-16 points fits into only 1 byte     mbuf <- newBuffer (2 * sz) sz WriteBuffer-    +     -- Convert as much UTF-32 as possible to UTF-16. NB: this can't fail due to output underflow     -- since we sized the output buffer correctly. However, it could fail due to an illegal character     -- in the input if it encounters a lone surrogate. In this case, our recovery will be applied as normal.@@ -296,7 +298,7 @@         -- UTF-32 characters required to get the consumed count of UTF-16 characters:         --         -- When dealing with data from the BMP (the common case), consuming N UTF-16 characters will be the same as consuming N-        -- UTF-32 characters. We start our search there so that most binary searches will terminate in a single iteration. +        -- UTF-32 characters. We start our search there so that most binary searches will terminate in a single iteration.         -- Furthermore, the absolute minimum number of UTF-32 characters this can correspond to is 1/2 the UTF-16 byte count         -- (this will be realised when the input data is entirely not in the BMP).         utf32_count <- bSearch "cpEncode" utf16_native_encode ibuf mbuf target_utf16_count (target_utf16_count `div` 2) target_utf16_count target_utf16_count@@ -347,7 +349,7 @@       -- have just been unlucky enough to set md so that ibuf straddles a byte boundary.       -- In this case we have to be really careful, because we don't want to report that       -- "md" elements is the right number when in actual fact we could have had md-1 input-      -- elements and still produced the same number of bufferElems in mbuf. +      -- elements and still produced the same number of bufferElems in mbuf.       --       -- In fact, we have to worry about this possibility even if we get InputUnderflow       -- since that will report InputUnderflow rather than InvalidSequence if the buffer@@ -359,7 +361,7 @@       -- Luckily if we have InvalidSequence/OutputUnderflow and we do not appear to have reached       -- the target, what we should do is the same as normal because the fraction of ibuf that our       -- first "code" coded succesfully must be invalid-sequence-free, and ibuf will always-      -- have been decoded as far as the first invalid sequence in it. +      -- have been decoded as far as the first invalid sequence in it.       case bufferElems mbuf `compare` target_to_elems of         -- Coding n "from" chars from the input yields exactly as many "to" chars         -- as were consumed by the recode. All is peachy:
GHC/IO/Encoding/Failure.hs view
@@ -6,7 +6,7 @@ -- Module      :  GHC.IO.Encoding.Failure -- Copyright   :  (c) The University of Glasgow, 2008-2011 -- License     :  see libraries/base/LICENSE--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  internal -- Portability :  non-portable@@ -34,9 +34,6 @@  --import System.Posix.Internals -import Data.Maybe-- -- | The 'CodingFailureMode' is used to construct 'TextEncoding's, and -- specifies how they handle illegal sequences. data CodingFailureMode@@ -183,7 +180,7 @@           -- reperesenting all ASCII characters.           _ir' <- writeCharBuf iraw ir '?'           return (input, output)-        +         -- This implementation does not work because e.g. UTF-16         -- requires 2 bytes to encode a simple ASCII value         --writeWord8Buf oraw ow unrepresentableByte
GHC/IO/Encoding/Iconv.hs view
@@ -10,7 +10,7 @@ -- Module      :  GHC.IO.Encoding.Iconv -- Copyright   :  (c) The University of Glasgow, 2008-2009 -- License     :  see libraries/base/LICENSE--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  internal -- Portability :  non-portable@@ -33,7 +33,7 @@ import GHC.Base () -- For build ordering #else -import Foreign.Safe+import Foreign import Foreign.C import Data.Maybe import GHC.Base@@ -78,7 +78,7 @@  foreign import ccall unsafe "hs_iconv"     hs_iconv :: IConv -> Ptr CString -> Ptr CSize -> Ptr CString -> Ptr CSize-	  -> IO CSize+          -> IO CSize  foreign import ccall unsafe "localeEncoding"     c_localeEncoding :: IO CString@@ -101,10 +101,10 @@  mkIconvEncoding :: CodingFailureMode -> String -> IO TextEncoding mkIconvEncoding cfm charset = do-  return (TextEncoding { +  return (TextEncoding {                 textEncodingName = charset,-		mkTextDecoder = newIConv raw_charset (haskellChar ++ suffix) (recoverDecode cfm) iconvDecode,-		mkTextEncoder = newIConv haskellChar charset                 (recoverEncode cfm) iconvEncode})+                mkTextDecoder = newIConv raw_charset (haskellChar ++ suffix) (recoverDecode cfm) iconvDecode,+                mkTextEncoder = newIConv haskellChar charset                 (recoverEncode cfm) iconvEncode})   where     -- An annoying feature of GNU iconv is that the //PREFIXES only take     -- effect when they appear on the tocode parameter to iconv_open:@@ -135,7 +135,7 @@ iconvEncode :: IConv -> EncodeBuffer iconvEncode iconv_t ibuf obuf = iconvRecode iconv_t ibuf char_shift obuf 0 -iconvRecode :: IConv -> Buffer a -> Int -> Buffer b -> Int +iconvRecode :: IConv -> Buffer a -> Int -> Buffer b -> Int             -> IO (CodingProgress, Buffer a, Buffer b) iconvRecode iconv_t   input@Buffer{  bufRaw=iraw, bufL=ir, bufR=iw, bufSize=_  }  iscale@@ -153,20 +153,20 @@       res <- hs_iconv iconv_t p_inbuf p_inleft p_outbuf p_outleft       new_inleft  <- peek p_inleft       new_outleft <- peek p_outleft-      let -	  new_inleft'  = fromIntegral new_inleft `shiftR` iscale-	  new_outleft' = fromIntegral new_outleft `shiftR` oscale-	  new_input  +      let+          new_inleft'  = fromIntegral new_inleft `shiftR` iscale+          new_outleft' = fromIntegral new_outleft `shiftR` oscale+          new_input             | new_inleft == 0  = input { bufL = 0, bufR = 0 }-	    | otherwise        = input { bufL = iw - new_inleft' }-	  new_output = output{ bufR = os - new_outleft' }+            | otherwise        = input { bufL = iw - new_inleft' }+          new_output = output{ bufR = os - new_outleft' }       iconv_trace ("iconv res=" ++ show res)       iconv_trace ("iconvRecode after,  input=" ++ show (summaryBuffer new_input))       iconv_trace ("iconvRecode after,  output=" ++ show (summaryBuffer new_output))       if (res /= -1)-	then do -- all input translated-	   return (InputUnderflow, new_input, new_output)-	else do+        then do -- all input translated+           return (InputUnderflow, new_input, new_output)+        else do       errno <- getErrno       case errno of         e | e == e2BIG  -> return (OutputUnderflow, new_input, new_output)
GHC/IO/Encoding/Latin1.hs view
@@ -45,7 +45,7 @@ latin1 :: TextEncoding latin1 = mkLatin1 ErrorOnCodingFailure --- | /Since: 4.4.0.0/+-- | @since 4.4.0.0 mkLatin1 :: CodingFailureMode -> TextEncoding mkLatin1 cfm = TextEncoding { textEncodingName = "ISO8859-1",                               mkTextDecoder = latin1_DF cfm,@@ -74,7 +74,7 @@ latin1_checked :: TextEncoding latin1_checked = mkLatin1_checked ErrorOnCodingFailure --- | /Since: 4.4.0.0/+-- | @since 4.4.0.0 mkLatin1_checked :: CodingFailureMode -> TextEncoding mkLatin1_checked cfm = TextEncoding { textEncodingName = "ISO8859-1(checked)",                                       mkTextDecoder = latin1_DF cfm,
GHC/IO/Encoding/Types.hs view
@@ -67,7 +67,7 @@    -- Currently, some implementations of @recover@ may mutate the input buffer.    -- In particular, this feature is used to implement transliteration.    ---   -- /Since: 4.4.0.0/+   -- @since 4.4.0.0      close  :: IO (),    -- ^ Resources associated with the encoding may now be released.@@ -121,7 +121,7 @@   -- | Returns the value of 'textEncodingName'   show te = textEncodingName te --- | /Since: 4.4.0.0/+-- | @since 4.4.0.0 data CodingProgress = InputUnderflow  -- ^ Stopped because the input contains insufficient available elements,                                       -- or all of the input sequence has been sucessfully translated.                     | OutputUnderflow -- ^ Stopped because the output contains insufficient free elements
GHC/IO/Encoding/UTF16.hs view
@@ -11,7 +11,7 @@ -- Module      :  GHC.IO.Encoding.UTF16 -- Copyright   :  (c) The University of Glasgow, 2009 -- License     :  see libraries/base/LICENSE--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  internal -- Portability :  non-portable@@ -47,7 +47,6 @@ import GHC.IO.Encoding.Types import GHC.Word import Data.Bits-import Data.Maybe import GHC.IORef  -- -----------------------------------------------------------------------------@@ -56,7 +55,7 @@ utf16  :: TextEncoding utf16 = mkUTF16 ErrorOnCodingFailure --- | /Since: 4.4.0.0/+-- | @since 4.4.0.0 mkUTF16 :: CodingFailureMode -> TextEncoding mkUTF16 cfm =  TextEncoding { textEncodingName = "UTF-16",                               mkTextDecoder = utf16_DF cfm,@@ -142,7 +141,7 @@ utf16be :: TextEncoding utf16be = mkUTF16be ErrorOnCodingFailure --- | /Since: 4.4.0.0/+-- | @since 4.4.0.0 mkUTF16be :: CodingFailureMode -> TextEncoding mkUTF16be cfm = TextEncoding { textEncodingName = "UTF-16BE",                                mkTextDecoder = utf16be_DF cfm,@@ -171,7 +170,7 @@ utf16le :: TextEncoding utf16le = mkUTF16le ErrorOnCodingFailure --- | /Since: 4.4.0.0/+-- | @since 4.4.0.0 mkUTF16le :: CodingFailureMode -> TextEncoding mkUTF16le cfm = TextEncoding { textEncodingName = "UTF16-LE",                                mkTextDecoder = utf16le_DF cfm,@@ -199,10 +198,10 @@   utf16be_decode :: DecodeBuffer-utf16be_decode +utf16be_decode   input@Buffer{  bufRaw=iraw, bufL=ir0, bufR=iw,  bufSize=_  }   output@Buffer{ bufRaw=oraw, bufL=_,   bufR=ow0, bufSize=os }- = let + = let        loop !ir !ow          | ow >= os     = done OutputUnderflow ir ow          | ir >= iw     = done InputUnderflow ir ow@@ -233,10 +232,10 @@     loop ir0 ow0  utf16le_decode :: DecodeBuffer-utf16le_decode +utf16le_decode   input@Buffer{  bufRaw=iraw, bufL=ir0, bufR=iw,  bufSize=_  }   output@Buffer{ bufRaw=oraw, bufL=_,   bufR=ow0, bufSize=os }- = let + = let        loop !ir !ow          | ow >= os     = done OutputUnderflow ir ow          | ir >= iw     = done InputUnderflow ir ow@@ -270,7 +269,7 @@ utf16be_encode   input@Buffer{  bufRaw=iraw, bufL=ir0, bufR=iw,  bufSize=_  }   output@Buffer{ bufRaw=oraw, bufL=_,   bufR=ow0, bufSize=os }- = let + = let       done why !ir !ow = return (why,                                  if ir == iw then input{ bufL=0, bufR=0 }                                              else input{ bufL=ir },@@ -287,7 +286,7 @@                     loop ir' (ow+2)                | otherwise -> do                     if os - ow < 4 then done OutputUnderflow ir ow else do-                    let +                    let                          n1 = x - 0x10000                          c1 = fromIntegral (n1 `shiftR` 18 + 0xD8)                          c2 = fromIntegral (n1 `shiftR` 10)@@ -324,7 +323,7 @@                     loop ir' (ow+2)                | otherwise ->                     if os - ow < 4 then done OutputUnderflow ir ow else do-                    let +                    let                          n1 = x - 0x10000                          c1 = fromIntegral (n1 `shiftR` 18 + 0xD8)                          c2 = fromIntegral (n1 `shiftR` 10)
GHC/IO/Encoding/UTF32.hs view
@@ -11,7 +11,7 @@ -- Module      :  GHC.IO.Encoding.UTF32 -- Copyright   :  (c) The University of Glasgow, 2009 -- License     :  see libraries/base/LICENSE--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  internal -- Portability :  non-portable@@ -47,7 +47,6 @@ import GHC.IO.Encoding.Types import GHC.Word import Data.Bits-import Data.Maybe import GHC.IORef  -- -----------------------------------------------------------------------------@@ -56,7 +55,7 @@ utf32  :: TextEncoding utf32 = mkUTF32 ErrorOnCodingFailure --- | /Since: 4.4.0.0/+-- | @since 4.4.0.0 mkUTF32 :: CodingFailureMode -> TextEncoding mkUTF32 cfm = TextEncoding { textEncodingName = "UTF-32",                              mkTextDecoder = utf32_DF cfm,@@ -145,7 +144,7 @@ utf32be :: TextEncoding utf32be = mkUTF32be ErrorOnCodingFailure --- | /Since: 4.4.0.0/+-- | @since 4.4.0.0 mkUTF32be :: CodingFailureMode -> TextEncoding mkUTF32be cfm = TextEncoding { textEncodingName = "UTF-32BE",                                mkTextDecoder = utf32be_DF cfm,@@ -175,7 +174,7 @@ utf32le :: TextEncoding utf32le = mkUTF32le ErrorOnCodingFailure --- | /Since: 4.4.0.0/+-- | @since 4.4.0.0 mkUTF32le :: CodingFailureMode -> TextEncoding mkUTF32le cfm = TextEncoding { textEncodingName = "UTF-32LE",                                mkTextDecoder = utf32le_DF cfm,@@ -203,10 +202,10 @@   utf32be_decode :: DecodeBuffer-utf32be_decode +utf32be_decode   input@Buffer{  bufRaw=iraw, bufL=ir0, bufR=iw,  bufSize=_  }   output@Buffer{ bufRaw=oraw, bufL=_,   bufR=ow0, bufSize=os }- = let + = let        loop !ir !ow          | ow >= os    = done OutputUnderflow ir ow          | iw - ir < 4 = done InputUnderflow  ir ow@@ -231,10 +230,10 @@     loop ir0 ow0  utf32le_decode :: DecodeBuffer-utf32le_decode +utf32le_decode   input@Buffer{  bufRaw=iraw, bufL=ir0, bufR=iw,  bufSize=_  }   output@Buffer{ bufRaw=oraw, bufL=_,   bufR=ow0, bufSize=os }- = let + = let        loop !ir !ow          | ow >= os    = done OutputUnderflow ir ow          | iw - ir < 4 = done InputUnderflow  ir ow@@ -262,7 +261,7 @@ utf32be_encode   input@Buffer{  bufRaw=iraw, bufL=ir0, bufR=iw,  bufSize=_  }   output@Buffer{ bufRaw=oraw, bufL=_,   bufR=ow0, bufSize=os }- = let + = let       done why !ir !ow = return (why,                                  if ir == iw then input{ bufL=0, bufR=0 }                                              else input{ bufL=ir },@@ -321,8 +320,8 @@ {-# INLINE chr4 #-}  ord4 :: Char -> (Word8,Word8,Word8,Word8)-ord4 c = (fromIntegral (x `shiftR` 24), -          fromIntegral (x `shiftR` 16), +ord4 c = (fromIntegral (x `shiftR` 24),+          fromIntegral (x `shiftR` 16),           fromIntegral (x `shiftR` 8),           fromIntegral x)   where
GHC/IO/Encoding/UTF8.hs view
@@ -43,7 +43,7 @@ utf8 :: TextEncoding utf8 = mkUTF8 ErrorOnCodingFailure --- | /Since: 4.4.0.0/+-- | @since 4.4.0.0 mkUTF8 :: CodingFailureMode -> TextEncoding mkUTF8 cfm = TextEncoding { textEncodingName = "UTF-8",                             mkTextDecoder = utf8_DF cfm,
GHC/IO/Exception.hs view
@@ -1,5 +1,5 @@ {-# LANGUAGE Trustworthy #-}-{-# LANGUAGE NoImplicitPrelude, DeriveDataTypeable, MagicHash,+{-# LANGUAGE NoImplicitPrelude, AutoDeriveTypeable, MagicHash,              ExistentialQuantification #-} {-# OPTIONS_GHC -funbox-strict-fields #-} {-# OPTIONS_HADDOCK hide #-}@@ -22,6 +22,7 @@   BlockedIndefinitelyOnMVar(..), blockedIndefinitelyOnMVar,   BlockedIndefinitelyOnSTM(..), blockedIndefinitelyOnSTM,   Deadlock(..),+  AllocationLimitExceeded(..), allocationLimitExceeded,   AssertionFailed(..),    SomeAsyncException(..),@@ -48,7 +49,6 @@ import GHC.Show import GHC.Read import GHC.Exception-import Data.Maybe import GHC.IO.Handle.Types import Foreign.C.Types @@ -99,6 +99,27 @@  ----- +-- |This thread has exceeded its allocation limit.  See+-- 'GHC.Conc.setAllocationCounter' and+-- 'GHC.Conc.enableAllocationLimit'.+--+-- @since 4.8.0.0+data AllocationLimitExceeded = AllocationLimitExceeded+    deriving Typeable++instance Exception AllocationLimitExceeded where+  toException = asyncExceptionToException+  fromException = asyncExceptionFromException++instance Show AllocationLimitExceeded where+    showsPrec _ AllocationLimitExceeded =+      showString "allocation limit exceeded"++allocationLimitExceeded :: SomeException -- for the RTS+allocationLimitExceeded = toException AllocationLimitExceeded++-----+ -- |'assert' was applied to 'False'. data AssertionFailed = AssertionFailed String     deriving Typeable@@ -112,7 +133,7 @@  -- |Superclass for asynchronous exceptions. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 data SomeAsyncException = forall e . Exception e => SomeAsyncException e   deriving Typeable @@ -121,11 +142,11 @@  instance Exception SomeAsyncException --- |/Since: 4.7.0.0/+-- |@since 4.7.0.0 asyncExceptionToException :: Exception e => e -> SomeException asyncExceptionToException = toException . SomeAsyncException --- |/Since: 4.7.0.0/+-- |@since 4.7.0.0 asyncExceptionFromException :: Exception e => SomeException -> Maybe e asyncExceptionFromException x = do     SomeAsyncException a <- fromException x@@ -175,7 +196,8 @@  instance Exception ArrayException -stackOverflow, heapOverflow :: SomeException -- for the RTS+-- for the RTS+stackOverflow, heapOverflow :: SomeException stackOverflow = toException StackOverflow heapOverflow  = toException HeapOverflow 
GHC/IO/FD.hs view
@@ -2,7 +2,7 @@ {-# LANGUAGE CPP            , NoImplicitPrelude            , BangPatterns-           , DeriveDataTypeable+           , AutoDeriveTypeable   #-} {-# OPTIONS_GHC -fno-warn-identities #-} -- Whether there are identities depends on the platform@@ -35,8 +35,6 @@ import GHC.Real import GHC.Show import GHC.Enum-import Data.Maybe-import Control.Monad import Data.Typeable  import GHC.IO@@ -161,7 +159,7 @@ openFile filepath iomode non_blocking =   withFilePath filepath $ \ f -> -    let +    let       oflags1 = case iomode of                   ReadMode      -> read_flags                   WriteMode     -> write_flags@@ -190,7 +188,7 @@                                  else c_safe_open f oflags 0o666)      (fD,fd_type) <- mkFD fd iomode Nothing{-no stat-}-                            False{-not a socket-} +                            False{-not a socket-}                             non_blocking             `catchAny` \e -> do _ <- c_close fd                                 throwIO e@@ -207,7 +205,7 @@     append_flags, nonblock_flags :: CInt std_flags    = o_NOCTTY output_flags = std_flags    .|. o_CREAT-read_flags   = std_flags    .|. o_RDONLY +read_flags   = std_flags    .|. o_RDONLY write_flags  = output_flags .|. o_WRONLY rw_flags     = output_flags .|. o_RDWR append_flags = write_flags  .|. o_APPEND@@ -234,7 +232,7 @@      let _ = (is_socket, is_nonblock) -- warning suppression -    (fd_type,dev,ino) <- +    (fd_type,dev,ino) <-         case mb_stat of           Nothing   -> fdStat fd           Just stat -> return stat@@ -244,7 +242,7 @@                    _ -> True      case fd_type of-        Directory -> +        Directory ->            ioException (IOError Nothing InappropriateType "openFile"                            "is a directory" Nothing Nothing) @@ -261,7 +259,7 @@         _other_type -> return ()  #ifdef mingw32_HOST_OS-    _ <- setmode fd True -- unconditionally set binary mode+    when (not is_socket) $ setmode fd True >> return () #endif      return (FD{ fdFD = fd,@@ -364,7 +362,7 @@ getSize :: FD -> IO Integer getSize fd = fdFileSize (fdFD fd) -setSize :: FD -> Integer -> IO () +setSize :: FD -> Integer -> IO () setSize fd size = do   throwErrnoIf_ (/=0) "GHC.IO.FD.setSize"  $      c_ftruncate (fdFD fd) (fromIntegral size)@@ -385,7 +383,7 @@   return fd{ fdFD = fdFD fdto } -- original FD, with the new fdFD  setNonBlockingMode :: FD -> Bool -> IO FD-setNonBlockingMode fd set = do +setNonBlockingMode fd set = do   setNonBlockingFD (fdFD fd) set #if defined(mingw32_HOST_OS)   return fd@@ -414,12 +412,13 @@ isTerminal :: FD -> IO Bool isTerminal fd = #if defined(mingw32_HOST_OS)-    is_console (fdFD fd) >>= return.toBool+    if fdIsSocket fd then return False+                     else is_console (fdFD fd) >>= return.toBool #else     c_isatty (fdFD fd) >>= return.toBool #endif -setEcho :: FD -> Bool -> IO () +setEcho :: FD -> Bool -> IO () setEcho fd on = System.Posix.Internals.setEcho (fdFD fd) on  getEcho :: FD -> IO Bool@@ -438,7 +437,7 @@  fdReadNonBlocking :: FD -> Ptr Word8 -> Int -> IO (Maybe Int) fdReadNonBlocking fd ptr bytes = do-  r <- readRawBufferPtrNoBlock "GHC.IO.FD.fdReadNonBlocking" fd ptr +  r <- readRawBufferPtrNoBlock "GHC.IO.FD.fdReadNonBlocking" fd ptr            0 (fromIntegral bytes)   case fromIntegral r of     (-1) -> return (Nothing)@@ -449,7 +448,7 @@ fdWrite fd ptr bytes = do   res <- writeRawBufferPtr "GHC.IO.FD.fdWrite" fd ptr 0 (fromIntegral bytes)   let res' = fromIntegral res-  if res' < bytes +  if res' < bytes      then fdWrite fd (ptr `plusPtr` res') (bytes - res')      else return () @@ -482,7 +481,7 @@ cases are wrong here.  The cases that are wrong:    * reading/writing to a blocking FD in non-threaded mode.-    In threaded mode, we just make a safe call to read().  +    In threaded mode, we just make a safe call to read().     In non-threaded mode we call select() before attempting to read,     but that leaves a small race window where the data can be read     from the file descriptor before we issue our blocking read().@@ -502,9 +501,9 @@ readRawBufferPtr :: String -> FD -> Ptr Word8 -> Int -> CSize -> IO Int readRawBufferPtr loc !fd buf off len   | isNonBlocking fd = unsafe_read -- unsafe is ok, it can't block-  | otherwise    = do r <- throwErrnoIfMinus1 loc +  | otherwise    = do r <- throwErrnoIfMinus1 loc                                 (unsafe_fdReady (fdFD fd) 0 0 0)-                      if r /= 0 +                      if r /= 0                         then read                         else do threadWaitRead (fromIntegral (fdFD fd)); read   where@@ -536,7 +535,7 @@ writeRawBufferPtr loc !fd buf off len   | isNonBlocking fd = unsafe_write -- unsafe is ok, it can't block   | otherwise   = do r <- unsafe_fdReady (fdFD fd) 1 0 0-                     if r /= 0 +                     if r /= 0                         then write                         else do threadWaitWrite (fromIntegral (fdFD fd)); write   where@@ -590,10 +589,10 @@  asyncReadRawBufferPtr :: String -> FD -> Ptr Word8 -> Int -> CSize -> IO CInt asyncReadRawBufferPtr loc !fd buf off len = do-    (l, rc) <- asyncRead (fromIntegral (fdFD fd)) (fdIsSocket_ fd) +    (l, rc) <- asyncRead (fromIntegral (fdFD fd)) (fdIsSocket_ fd)                         (fromIntegral len) (buf `plusPtr` off)     if l == (-1)-      then +      then         ioError (errnoToIOError loc (Errno (fromIntegral rc)) Nothing Nothing)       else return (fromIntegral l) @@ -602,7 +601,7 @@     (l, rc) <- asyncWrite (fromIntegral (fdFD fd)) (fdIsSocket_ fd)                   (fromIntegral len) (buf `plusPtr` off)     if l == (-1)-      then +      then         ioError (errnoToIOError loc (Errno (fromIntegral rc)) Nothing Nothing)       else return (fromIntegral l) @@ -616,7 +615,7 @@            else c_safe_read (fdFD fd) (buf `plusPtr` off) len  blockingWriteRawBufferPtr :: String -> FD -> Ptr Word8-> Int -> CSize -> IO CInt-blockingWriteRawBufferPtr loc fd buf off len +blockingWriteRawBufferPtr loc fd buf off len   = fmap fromIntegral $ throwErrnoIfMinus1Retry loc $         if fdIsSocket fd            then c_safe_send  (fdFD fd) (buf `plusPtr` off) len 0@@ -649,7 +648,7 @@  #ifndef mingw32_HOST_OS throwErrnoIfMinus1RetryOnBlock  :: String -> IO CSsize -> IO CSsize -> IO CSsize-throwErrnoIfMinus1RetryOnBlock loc f on_block  = +throwErrnoIfMinus1RetryOnBlock loc f on_block  =   do     res <- f     if (res :: CSsize) == -1
GHC/IO/Handle.hs view
@@ -11,7 +11,7 @@ -- Module      :  GHC.IO.Handle -- Copyright   :  (c) The University of Glasgow, 1994-2009 -- License     :  see libraries/base/LICENSE--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  provisional -- Portability :  non-portable@@ -23,21 +23,21 @@ module GHC.IO.Handle (    Handle,    BufferMode(..),- +    mkFileHandle, mkDuplexHandle,- +    hFileSize, hSetFileSize, hIsEOF, hLookAhead,    hSetBuffering, hSetBinaryMode, hSetEncoding, hGetEncoding,    hFlush, hFlushAll, hDuplicate, hDuplicateTo,- +    hClose, hClose_help,- +    HandlePosition, HandlePosn(..), hGetPosn, hSetPosn,    SeekMode(..), hSeek, hTell,- +    hIsOpen, hIsClosed, hIsReadable, hIsWritable, hGetBuffering, hIsSeekable,    hSetEcho, hGetEcho, hIsTerminalDevice,- +    hSetNewlineMode, Newline(..), NewlineMode(..), nativeNewline,    noNewlineTranslation, universalNewlineMode, nativeNewlineMode, @@ -68,7 +68,6 @@ import GHC.Real import Data.Maybe import Data.Typeable-import Control.Monad  -- --------------------------------------------------------------------------- -- Closing a handle@@ -76,14 +75,14 @@ -- | Computation 'hClose' @hdl@ makes handle @hdl@ closed.  Before the -- computation finishes, if @hdl@ is writable its buffer is flushed as -- for 'hFlush'.--- Performing 'hClose' on a handle that has already been closed has no effect; +-- Performing 'hClose' on a handle that has already been closed has no effect; -- doing so is not an error.  All other operations on a closed handle will fail. -- If 'hClose' fails for any reason, any further operations (apart from -- 'hClose') on the handle will still fail as if @hdl@ had been successfully -- closed.  hClose :: Handle -> IO ()-hClose h@(FileHandle _ m)     = do +hClose h@(FileHandle _ m)     = do   mb_exc <- hClose' h m   hClose_maybethrow mb_exc h hClose h@(DuplexHandle _ r w) = do@@ -95,7 +94,7 @@ hClose_maybethrow (Just e) h = hClose_rethrow e h  hClose_rethrow :: SomeException -> Handle -> IO ()-hClose_rethrow e h = +hClose_rethrow e h =   case fromException e of     Just ioe -> ioError (augmentIOError ioe "hClose" h)     Nothing  -> throwIO e@@ -112,7 +111,7 @@ hFileSize :: Handle -> IO Integer hFileSize handle =     withHandle_ "hFileSize" handle $ \ handle_@Handle__{haDevice=dev} -> do-    case haType handle_ of +    case haType handle_ of       ClosedHandle              -> ioe_closedHandle       SemiClosedHandle          -> ioe_closedHandle       _ -> do flushWriteBuffer handle_@@ -128,7 +127,7 @@ hSetFileSize :: Handle -> Integer -> IO () hSetFileSize handle size =     withHandle_ "hSetFileSize" handle $ \ handle_@Handle__{haDevice=dev} -> do-    case haType handle_ of +    case haType handle_ of       ClosedHandle              -> ioe_closedHandle       SemiClosedHandle          -> ioe_closedHandle       _ -> do flushWriteBuffer handle_@@ -257,8 +256,8 @@     openTextEncoding (Just encoding) haType $ \ mb_encoder mb_decoder -> do     bbuf <- readIORef haByteBuffer     ref <- newIORef (error "last_decode")-    return (Handle__{ haLastDecode = ref, -                      haDecoder = mb_decoder, +    return (Handle__{ haLastDecode = ref,+                      haDecoder = mb_decoder,                       haEncoder = mb_encoder,                       haCodec   = Just encoding, .. }) @@ -289,7 +288,7 @@ --    It is unspecified whether the characters in the buffer are discarded --    or retained under these circumstances. -hFlush :: Handle -> IO () +hFlush :: Handle -> IO () hFlush handle = wantWritableHandle "hFlush" handle flushWriteBuffer  -- | The action 'hFlushAll' @hdl@ flushes all buffered data in @hdl@,@@ -309,7 +308,7 @@ --  * 'isIllegalOperation' if @hdl@ has buffered read data, and is not --    seekable. -hFlushAll :: Handle -> IO () +hFlushAll :: Handle -> IO () hFlushAll handle = withHandle_ "hFlushAll" handle flushBuffer  -- -----------------------------------------------------------------------------@@ -321,7 +320,7 @@     (HandlePosn h1 p1) == (HandlePosn h2 p2) = p1==p2 && h1==h2  instance Show HandlePosn where-   showsPrec p (HandlePosn h pos) = +   showsPrec p (HandlePosn h pos) =         showsPrec p h . showString " at position " . shows pos    -- HandlePosition is the Haskell equivalent of POSIX' off_t.@@ -346,13 +345,13 @@ -- --  * 'isPermissionError' if a system resource limit would be exceeded. -hSetPosn :: HandlePosn -> IO () +hSetPosn :: HandlePosn -> IO () hSetPosn (HandlePosn h i) = hSeek h AbsoluteSeek i  -- --------------------------------------------------------------------------- -- hSeek -{- Note: +{- Note:  - when seeking using `SeekFromEnd', positive offsets (>=0) means    seeking at or past EOF. @@ -382,7 +381,7 @@ -- --  * 'isPermissionError' if a system resource limit would be exceeded. -hSeek :: Handle -> SeekMode -> Integer -> IO () +hSeek :: Handle -> SeekMode -> Integer -> IO () hSeek handle mode offset =     wantSeekableHandle "hSeek" handle $ \ handle_@Handle__{..} -> do     debugIO ("hSeek " ++ show (mode,offset))@@ -394,10 +393,10 @@         else do      let r = bufL buf; w = bufR buf-    if mode == RelativeSeek && isNothing haDecoder && +    if mode == RelativeSeek && isNothing haDecoder &&        offset >= 0 && offset < fromIntegral (w - r)         then writeIORef haCharBuffer buf{ bufL = r + fromIntegral offset }-        else do +        else do      flushCharReadBuffer handle_     flushByteReadBuffer handle_@@ -408,13 +407,13 @@ -- handle @hdl@, as the number of bytes from the beginning of -- the file.  The value returned may be subsequently passed to -- 'hSeek' to reposition the handle to the current position.--- +-- -- This operation may fail with: -- --  * 'isIllegalOperationError' if the Handle is not seekable. -- hTell :: Handle -> IO Integer-hTell handle = +hTell handle =     wantSeekableHandle "hGetPosn" handle $ \ handle_@Handle__{..} -> do        posn <- IODevice.tell haDevice@@ -446,7 +445,7 @@ hIsOpen :: Handle -> IO Bool hIsOpen handle =     withHandle_ "hIsOpen" handle $ \ handle_ -> do-    case haType handle_ of +    case haType handle_ of       ClosedHandle         -> return False       SemiClosedHandle     -> return False       _                    -> return True@@ -454,7 +453,7 @@ hIsClosed :: Handle -> IO Bool hIsClosed handle =     withHandle_ "hIsClosed" handle $ \ handle_ -> do-    case haType handle_ of +    case haType handle_ of       ClosedHandle         -> return True       _                    -> return False @@ -472,7 +471,7 @@ hIsReadable (DuplexHandle _ _ _) = return True hIsReadable handle =     withHandle_ "hIsReadable" handle $ \ handle_ -> do-    case haType handle_ of +    case haType handle_ of       ClosedHandle         -> ioe_closedHandle       SemiClosedHandle     -> ioe_closedHandle       htype                -> return (isReadableHandleType htype)@@ -481,7 +480,7 @@ hIsWritable (DuplexHandle _ _ _) = return True hIsWritable handle =     withHandle_ "hIsWritable" handle $ \ handle_ -> do-    case haType handle_ of +    case haType handle_ of       ClosedHandle         -> ioe_closedHandle       SemiClosedHandle     -> ioe_closedHandle       htype                -> return (isWritableHandleType htype)@@ -490,11 +489,11 @@ -- for @hdl@.  hGetBuffering :: Handle -> IO BufferMode-hGetBuffering handle = +hGetBuffering handle =     withHandle_ "hGetBuffering" handle $ \ handle_ -> do-    case haType handle_ of +    case haType handle_ of       ClosedHandle         -> ioe_closedHandle-      _ -> +      _ ->            -- We're being non-standard here, and allow the buffering            -- of a semi-closed handle to be queried.   -- sof 6/98           return (haBufferMode handle_)  -- could be stricter..@@ -502,7 +501,7 @@ hIsSeekable :: Handle -> IO Bool hIsSeekable handle =     withHandle_ "hIsSeekable" handle $ \ handle_@Handle__{..} -> do-    case haType of +    case haType of       ClosedHandle         -> ioe_closedHandle       SemiClosedHandle     -> ioe_closedHandle       AppendHandle         -> return False@@ -520,7 +519,7 @@      then return ()      else       withHandle_ "hSetEcho" handle $ \ Handle__{..} -> do-      case haType of +      case haType of          ClosedHandle -> ioe_closedHandle          _            -> IODevice.setEcho haDevice on @@ -533,7 +532,7 @@      then return False      else        withHandle_ "hGetEcho" handle $ \ Handle__{..} -> do-       case haType of +       case haType of          ClosedHandle -> ioe_closedHandle          _            -> IODevice.getEcho haDevice @@ -542,7 +541,7 @@ hIsTerminalDevice :: Handle -> IO Bool hIsTerminalDevice handle = do     withHandle_ "hIsTerminalDevice" handle $ \ Handle__{..} -> do-     case haType of +     case haType of        ClosedHandle -> ioe_closedHandle        _            -> IODevice.isTerminal haDevice @@ -558,7 +557,7 @@ hSetBinaryMode :: Handle -> Bool -> IO () hSetBinaryMode handle bin =   withAllHandles__ "hSetBinaryMode" handle $ \ h_@Handle__{..} ->-    do +    do          flushCharBuffer h_          closeTextCodecs h_ @@ -575,12 +574,12 @@          ref <- newIORef (error "codec_state", bbuf)           return Handle__{ haLastDecode = ref,-                          haEncoder  = mb_encoder, +                          haEncoder  = mb_encoder,                           haDecoder  = mb_decoder,                           haCodec    = mb_te,                           haInputNL  = inputNL nl,                           haOutputNL = outputNL nl, .. }-  + -- ----------------------------------------------------------------------------- -- hSetNewlineMode @@ -606,10 +605,10 @@   withHandle_' "hDuplicate" h m $ \h_ ->       dupHandle path h Nothing h_ (Just handleFinalizer) hDuplicate h@(DuplexHandle path r w) = do-  write_side@(FileHandle _ write_m) <- +  write_side@(FileHandle _ write_m) <-      withHandle_' "hDuplicate" h w $ \h_ ->         dupHandle path h Nothing h_ (Just handleFinalizer)-  read_side@(FileHandle _ read_m) <- +  read_side@(FileHandle _ read_m) <-     withHandle_' "hDuplicate" h r $ \h_ ->         dupHandle path h (Just write_m) h_  Nothing   return (DuplexHandle path read_m write_m)@@ -627,7 +626,7 @@     Nothing -> do        new_dev <- IODevice.dup haDevice        dupHandle_ new_dev filepath other_side h_ mb_finalizer-    Just r  -> +    Just r  ->        withHandle_' "dupHandle" h r $ \Handle__{haDevice=dev} -> do          dupHandle_ dev filepath other_side h_ mb_finalizer @@ -648,7 +647,7 @@ -- Replacing a Handle  {- |-Makes the second handle a duplicate of the first handle.  The second +Makes the second handle a duplicate of the first handle.  The second handle will be closed first, if it is not already.  This can be used to retarget the standard Handles, for example:@@ -672,29 +671,29 @@    _ <- hClose_help r2_    withHandle_' "hDuplicateTo" h1 r1 $ \r1_ -> do      dupHandleTo path h1 (Just w1) r2_ r1_ Nothing-hDuplicateTo h1 _ = +hDuplicateTo h1 _ =   ioe_dupHandlesNotCompatible h1   ioe_dupHandlesNotCompatible :: Handle -> IO a ioe_dupHandlesNotCompatible h =-   ioException (IOError (Just h) IllegalOperation "hDuplicateTo" +   ioException (IOError (Just h) IllegalOperation "hDuplicateTo"                 "handles are incompatible" Nothing Nothing) -dupHandleTo :: FilePath +dupHandleTo :: FilePath             -> Handle             -> Maybe (MVar Handle__)             -> Handle__             -> Handle__             -> Maybe HandleFinalizer             -> IO Handle__-dupHandleTo filepath h other_side +dupHandleTo filepath h other_side             hto_@Handle__{haDevice=devTo,..}             h_@Handle__{haDevice=dev} mb_finalizer = do   flushBuffer h_   case cast devTo of     Nothing   -> ioe_dupHandlesNotCompatible h-    Just dev' -> do +    Just dev' -> do       _ <- IODevice.dup2 dev dev'       FileHandle _ m <- dupHandle_ dev' filepath other_side h_ mb_finalizer       takeMVar m@@ -710,15 +709,15 @@ hShow h@(DuplexHandle path _ _) = showHandle' path True h  showHandle' :: String -> Bool -> Handle -> IO String-showHandle' filepath is_duplex h = +showHandle' filepath is_duplex h =   withHandle_ "showHandle" h $ \hdl_ ->     let      showType | is_duplex = showString "duplex (read-write)"               | otherwise = shows (haType hdl_)     in-    return -      (( showChar '{' . -        showHdl (haType hdl_) +    return+      (( showChar '{' .+        showHdl (haType hdl_)             (showString "loc=" . showString filepath . showChar ',' .              showString "type=" . showType . showChar ',' .              showString "buffering=" . showBufMode (unsafePerformIO (readIORef (haCharBuffer hdl_))) (haBufferMode hdl_) . showString "}" )@@ -726,7 +725,7 @@    where      showHdl :: HandleType -> ShowS -> ShowS-    showHdl ht cont = +    showHdl ht cont =        case ht of         ClosedHandle  -> shows ht . showString "}"         _ -> cont@@ -739,6 +738,6 @@         BlockBuffering (Just n) -> showString "block " . showParen True (shows n)         BlockBuffering Nothing  -> showString "block " . showParen True (shows def)       where-       def :: Int +       def :: Int        def = bufSize buf 
GHC/IO/Handle/FD.hs view
@@ -157,7 +157,7 @@ -- non-blocking mode then the open will fail if there are no writers, -- whereas a blocking open will block until a writer appears. ----- /Since: 4.4.0.0/+-- @since 4.4.0.0 openFileBlocking :: FilePath -> IOMode -> IO Handle openFileBlocking fp im =   catchException
GHC/IO/Handle/Internals.hs view
@@ -14,7 +14,7 @@ -- Module      :  GHC.IO.Handle.Internals -- Copyright   :  (c) The University of Glasgow, 1994-2001 -- License     :  see libraries/base/LICENSE--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  internal -- Portability :  non-portable@@ -28,7 +28,7 @@ module GHC.IO.Handle.Internals (   withHandle, withHandle', withHandle_,   withHandle__', withHandle_', withAllHandles__,-  wantWritableHandle, wantReadableHandle, wantReadableHandle_, +  wantWritableHandle, wantReadableHandle, wantReadableHandle_,   wantSeekableHandle,    mkHandle, mkFileHandle, mkDuplexHandle,@@ -73,9 +73,8 @@ import GHC.IORef import GHC.MVar import Data.Typeable-import Control.Monad import Data.Maybe-import Foreign.Safe+import Foreign import System.Posix.Internals hiding (FD)  import Foreign.C@@ -440,8 +439,8 @@   ioref  <- newIORef buffer   is_tty <- IODevice.isTerminal dev -  let buffer_mode -         | is_tty    = LineBuffering +  let buffer_mode+         | is_tty    = LineBuffering          | otherwise = BlockBuffering Nothing    return (ioref, buffer_mode)@@ -571,10 +570,10 @@        -- restore the codec state       setState decoder codec_state-    +       (bbuf1,cbuf1) <- (streamEncode decoder) bbuf0                                cbuf0{ bufL=0, bufR=0, bufSize = bufL cbuf0 }-    +       debugIO ("finished, bbuf=" ++ summaryBuffer bbuf1 ++                " cbuf=" ++ summaryBuffer cbuf1) @@ -623,7 +622,7 @@    bbufref <- newIORef bbuf    last_decode <- newIORef (error "codec_state", bbuf) -   (cbufref,bmode) <- +   (cbufref,bmode) <-          if buffered then getCharBuffer dev buf_state                      else mkUnBuffer buf_state @@ -646,7 +645,7 @@  -- | makes a new 'Handle' mkFileHandle :: (IODevice dev, BufferedIO dev, Typeable dev)-             => dev -- ^ the underlying IO device, which must support +             => dev -- ^ the underlying IO device, which must support                     -- 'IODevice', 'BufferedIO' and 'Typeable'              -> FilePath                     -- ^ a string describing the 'Handle', e.g. the file@@ -670,13 +669,13 @@                -> FilePath -> Maybe TextEncoding -> NewlineMode -> IO Handle mkDuplexHandle dev filepath mb_codec tr_newlines = do -  write_side@(FileHandle _ write_m) <- +  write_side@(FileHandle _ write_m) <-        mkHandle dev filepath WriteHandle True mb_codec                         tr_newlines                         (Just handleFinalizer)                         Nothing -- no othersie -  read_side@(FileHandle _ read_m) <- +  read_side@(FileHandle _ read_m) <-       mkHandle dev filepath ReadHandle True mb_codec                         tr_newlines                         Nothing -- no finalizer@@ -710,7 +709,7 @@     mb_encoder <- if isWritableHandleType ha_type then do                      encoder <- mkTextEncoder                      return (Just encoder)-                  else +                  else                      return Nothing     cont mb_encoder mb_decoder @@ -730,7 +729,7 @@ -- use. hClose_help :: Handle__ -> IO (Handle__, Maybe SomeException) hClose_help handle_ =-  case haType handle_ of +  case haType handle_ of       ClosedHandle -> return (handle_,Nothing)       _ -> do mb_exc1 <- trymaybe $ flushWriteBuffer handle_ -- interruptible                     -- it is important that hClose doesn't fail and@@ -749,10 +748,10 @@     -- close the file descriptor, but not when this is the read     -- side of a duplex handle.     -- If an exception is raised by the close(), we want to continue-    -- to close the handle and release the lock if it has one, then +    -- to close the handle and release the lock if it has one, then     -- we return the exception to the caller of hClose_help which can     -- raise it if necessary.-    maybe_exception <- +    maybe_exception <-       case haOtherSide of         Nothing -> trymaybe $ IODevice.close haDevice         Just _  -> return Nothing@@ -761,7 +760,7 @@     writeIORef haBuffers BufferListNil     writeIORef haCharBuffer noCharBuffer     writeIORef haByteBuffer noByteBuffer-  +     -- release our encoder/decoder     closeTextCodecs h_ @@ -785,13 +784,13 @@ hLookAhead_ :: Handle__ -> IO Char hLookAhead_ handle_@Handle__{..} = do     buf <- readIORef haCharBuffer-  +     -- fill up the read buffer if necessary     new_buf <- if isEmptyBuffer buf                   then readTextDevice handle_ buf                   else return buf     writeIORef haCharBuffer new_buf-  +     peekCharBuf (bufRaw buf) (bufL buf)  -- ---------------------------------------------------------------------------@@ -809,7 +808,7 @@ -- Text input/output  -- Read characters into the provided buffer.  Return when any--- characters are available; raise an exception if the end of +-- characters are available; raise an exception if the end of -- file is reached. -- -- In uses of readTextDevice within base, the input buffer is either:@@ -826,7 +825,7 @@   --   bbuf0 <- readIORef haByteBuffer -  debugIO ("readTextDevice: cbuf=" ++ summaryBuffer cbuf ++ +  debugIO ("readTextDevice: cbuf=" ++ summaryBuffer cbuf ++         " bbuf=" ++ summaryBuffer bbuf0)    bbuf1 <- if not (isEmptyBuffer bbuf0)@@ -838,7 +837,7 @@    debugIO ("readTextDevice after reading: bbuf=" ++ summaryBuffer bbuf1) -  (bbuf2,cbuf') <- +  (bbuf2,cbuf') <-       case haDecoder of           Nothing      -> do                writeIORef haLastDecode (error "codec_state", bbuf1)@@ -848,7 +847,7 @@                writeIORef haLastDecode (state, bbuf1)                (streamEncode decoder) bbuf1 cbuf -  debugIO ("readTextDevice after decoding: cbuf=" ++ summaryBuffer cbuf' ++ +  debugIO ("readTextDevice after decoding: cbuf=" ++ summaryBuffer cbuf' ++         " bbuf=" ++ summaryBuffer bbuf2)    -- We can't return from readTextDevice without reading at least a single extra character,@@ -872,7 +871,7 @@   -- readTextDevice only calls us if we got some bytes but not some characters.   -- This can't occur if haDecoder is Nothing because latin1_decode accepts all bytes.   let Just decoder = haDecoder-  +   (r,bbuf2) <- Buffered.fillReadBuffer haDevice bbuf1   if r == 0    then do@@ -894,15 +893,15 @@       else return cbuf1    else do     debugIO ("readTextDevice' after reading: bbuf=" ++ summaryBuffer bbuf2)-  +     (bbuf3,cbuf1) <- do        state <- getState decoder        writeIORef haLastDecode (state, bbuf2)        (streamEncode decoder) bbuf2 cbuf0-  -    debugIO ("readTextDevice' after decoding: cbuf=" ++ summaryBuffer cbuf1 ++ ++    debugIO ("readTextDevice' after decoding: cbuf=" ++ summaryBuffer cbuf1 ++           " bbuf=" ++ summaryBuffer bbuf3)-  +     writeIORef haByteBuffer bbuf3     if bufR cbuf0 == bufR cbuf1        then readTextDevice' h_ bbuf3 cbuf1
GHC/IO/Handle/Text.hs view
@@ -15,7 +15,7 @@ -- Module      :  GHC.IO.Text -- Copyright   :  (c) The University of Glasgow, 1992-2008 -- License     :  see libraries/base/LICENSE--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  internal -- Portability :  non-portable@@ -24,7 +24,7 @@ -- ----------------------------------------------------------------------------- -module GHC.IO.Handle.Text ( +module GHC.IO.Handle.Text (         hWaitForInput, hGetChar, hGetLine, hGetContents, hPutChar, hPutStr,         commitBuffer',       -- hack, see below         hGetBuf, hGetBufSome, hGetBufNonBlocking, hPutBuf, hPutBufNonBlocking,@@ -49,7 +49,6 @@ import Data.Typeable import System.IO.Error import Data.Maybe-import Control.Monad  import GHC.IORef import GHC.Base@@ -96,7 +95,7 @@    if not (isEmptyBuffer cbuf) then return True else do -  if msecs < 0 +  if msecs < 0         then do cbuf' <- readTextDevice handle_ cbuf                 writeIORef haCharBuffer cbuf'                 return True@@ -235,7 +234,7 @@                      -- we reached EOF.  There might be a lone \r left                      -- in the buffer, so check for that and                      -- append it to the line if necessary.-                     -- +                     --                      let pre = if not (isEmptyBuffer buf1) then "\r" else ""                      writeIORef haCharBuffer buf1{ bufL=0, bufR=0 }                      let str = concat (reverse (pre:xs:xss))@@ -263,8 +262,8 @@ unpack :: RawCharBuffer -> Int -> Int -> [Char] -> IO [Char] unpack !buf !r !w acc0  | r == w    = return acc0- | otherwise = -  withRawBuffer buf $ \pbuf -> + | otherwise =+  withRawBuffer buf $ \pbuf ->     let         unpackRB acc !i          | i < r  = return acc@@ -311,7 +310,7 @@      in do      c <- peekElemOff pbuf (w-1)      if (c == '\r')-        then do +        then do                 -- If the last char is a '\r', we need to know whether or                 -- not it is followed by a '\n', so leave it in the buffer                 -- for now and just unpack the rest.@@ -376,7 +375,7 @@ --  * 'isEOFError' if the end of file has been reached.  hGetContents :: Handle -> IO String-hGetContents handle = +hGetContents handle =    wantReadableHandle "hGetContents" handle $ \handle_ -> do       xs <- lazyRead handle       return (handle_{ haType=SemiClosedHandle}, xs )@@ -386,14 +385,17 @@ -- they have to check whether the handle has indeed been closed.  lazyRead :: Handle -> IO String-lazyRead handle = +lazyRead handle =    unsafeInterleaveIO $         withHandle "hGetContents" handle $ \ handle_ -> do         case haType handle_ of-          ClosedHandle     -> return (handle_, "")           SemiClosedHandle -> lazyReadBuffered handle handle_-          _ -> ioException +          ClosedHandle+            -> ioException                   (IOError (Just handle) IllegalOperation "hGetContents"+                        "delayed read on closed handle" Nothing Nothing)+          _ -> ioException+                  (IOError (Just handle) IllegalOperation "hGetContents"                         "illegal handle type" Nothing Nothing)  lazyReadBuffered :: Handle -> Handle__ -> IO (Handle__, [Char])@@ -557,7 +559,7 @@ hPutChars handle (c:cs) = hPutChar handle c >> hPutChars handle cs  getSpareBuffer :: Handle__ -> IO (BufferMode, CharBuffer)-getSpareBuffer Handle__{haCharBuffer=ref, +getSpareBuffer Handle__{haCharBuffer=ref,                         haBuffers=spare_ref,                         haBufferMode=mode}  = do@@ -592,7 +594,7 @@         shoveString 0 (c:cs) rest      | c == '\n'  =  do         n' <- if nl == CRLF-                 then do +                 then do                     n1 <- writeCharBuf raw n  '\r'                     writeCharBuf raw n1 '\n'                  else do@@ -612,7 +614,7 @@  -- ----------------------------------------------------------------------------- -- commitBuffer handle buf sz count flush release--- +-- -- Write the contents of the buffer 'buf' ('sz' bytes long, containing -- 'count' bytes of data) to handle (handle must be block or line buffered). @@ -624,7 +626,7 @@         -> Bool                         -- release the buffer?         -> IO () -commitBuffer hdl !raw !sz !count flush release = +commitBuffer hdl !raw !sz !count flush release =   wantWritableHandle "commitBuffer" hdl $ \h_@Handle__{..} -> do       debugIO ("commitBuffer: sz=" ++ show sz ++ ", count=" ++ show count             ++ ", flush=" ++ show flush ++ ", release=" ++ show release)@@ -713,8 +715,8 @@ hPutBuf' handle ptr count can_block   | count == 0 = return 0   | count <  0 = illegalBufferSize handle "hPutBuf" count-  | otherwise = -    wantWritableHandle "hPutBuf" handle $ +  | otherwise =+    wantWritableHandle "hPutBuf" handle $       \ h_@Handle__{..} -> do           debugIO ("hPutBuf count=" ++ show count) @@ -748,7 +750,7 @@                 old_buf' <- Buffered.flushWriteBuffer haDevice old_buf                         -- TODO: we should do a non-blocking flush here                 writeIORef haByteBuffer old_buf'-                -- if we can fit in the buffer, then just loop  +                -- if we can fit in the buffer, then just loop                 if count < size                    then bufWrite h_ ptr count can_block                    else if can_block@@ -762,7 +764,7 @@   | otherwise = error "Todo: hPutBuf"  writeChunkNonBlocking :: Handle__ -> Ptr Word8 -> Int -> IO Int-writeChunkNonBlocking h_@Handle__{..} ptr bytes +writeChunkNonBlocking h_@Handle__{..} ptr bytes   | Just fd <- cast haDevice  =  RawIO.writeNonBlocking (fd::FD) ptr bytes   | otherwise = error "Todo: hPutBuf" @@ -788,7 +790,7 @@ hGetBuf h ptr count   | count == 0 = return 0   | count <  0 = illegalBufferSize h "hGetBuf" count-  | otherwise = +  | otherwise =       wantReadableHandle_ "hGetBuf" h $ \ h_@Handle__{..} -> do          flushCharReadBuffer h_          buf@Buffer{ bufRaw=raw, bufR=w, bufL=r, bufSize=sz }@@ -804,16 +806,16 @@ bufReadNonEmpty :: Handle__ -> Buffer Word8 -> Ptr Word8 -> Int -> Int -> IO Int bufReadNonEmpty h_@Handle__{..}                 buf@Buffer{ bufRaw=raw, bufR=w, bufL=r, bufSize=sz }-                ptr !so_far !count +                ptr !so_far !count  = do         let avail = w - r         if (count < avail)-           then do +           then do                 copyFromRawBuffer ptr raw r count                 writeIORef haByteBuffer buf{ bufL = r + count }                 return (so_far + count)            else do-  +         copyFromRawBuffer ptr raw r avail         let buf' = buf{ bufR=0, bufL=0 }         writeIORef haByteBuffer buf'@@ -821,7 +823,7 @@             so_far' = so_far + avail             ptr' = ptr `plusPtr` avail -        if remaining == 0 +        if remaining == 0            then return so_far'            else bufReadEmpty h_ buf' ptr' so_far' remaining @@ -833,7 +835,7 @@  | count > sz, Just fd <- cast haDevice = loop fd 0 count  | otherwise = do      (r,buf') <- Buffered.fillReadBuffer haDevice buf-     if r == 0 +     if r == 0         then return so_far         else do writeIORef haByteBuffer buf'                 bufReadNonEmpty h_ buf' ptr so_far count@@ -915,7 +917,7 @@ hGetBufNonBlocking h ptr count   | count == 0 = return 0   | count <  0 = illegalBufferSize h "hGetBufNonBlocking" count-  | otherwise = +  | otherwise =       wantReadableHandle_ "hGetBufNonBlocking" h $ \ h_@Handle__{..} -> do          flushCharReadBuffer h_          buf@Buffer{ bufRaw=raw, bufR=w, bufL=r, bufSize=sz }@@ -957,7 +959,7 @@   = do         let avail = w - r         if (count < avail)-           then do +           then do                 copyFromRawBuffer ptr raw r count                 writeIORef haByteBuffer buf{ bufL = r + count }                 return (so_far + count)
GHC/IO/Handle/Types.hs view
@@ -2,7 +2,7 @@ {-# LANGUAGE CPP            , NoImplicitPrelude            , ExistentialQuantification-           , DeriveDataTypeable+           , AutoDeriveTypeable   #-} {-# OPTIONS_GHC -funbox-strict-fields #-} {-# OPTIONS_HADDOCK hide #-}@@ -12,7 +12,7 @@ -- Module      :  GHC.IO.Handle.Types -- Copyright   :  (c) The University of Glasgow, 1994-2009 -- License     :  see libraries/base/LICENSE--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  internal -- Portability :  non-portable@@ -42,7 +42,6 @@ import GHC.IO.BufferedIO import GHC.IO.Encoding.Types import GHC.IORef-import Data.Maybe import GHC.Show import GHC.Read import GHC.Word@@ -55,13 +54,13 @@ -- --------------------------------------------------------------------------- -- Handle type ---  A Handle is represented by (a reference to) a record +--  A Handle is represented by (a reference to) a record --  containing the state of the I/O port/device. We record --  the following pieces of info:  --    * type (read,write,closed etc.) --    * the underlying file descriptor---    * buffering mode +--    * buffering mode --    * buffer, and spare buffers --    * user-friendly name (usually the --      FilePath used when IO.openFile was called)@@ -73,7 +72,7 @@ -- represented by values of type @Handle@.  Each value of this type is a -- /handle/: a record used by the Haskell run-time system to /manage/ I\/O -- with file system objects.  A handle has at least the following properties:--- +-- --  * whether it manages input or output or both; -- --  * whether it is /open/, /closed/ or /semi-closed/;@@ -97,7 +96,7 @@ -- equal according to '==' only to itself; no attempt -- is made to compare the internal state of different handles for equality. -data Handle +data Handle   = FileHandle                          -- A normal handle to a file         FilePath                        -- the file (used for error messages                                         -- only)@@ -119,7 +118,7 @@ instance Eq Handle where  (FileHandle _ h1)     == (FileHandle _ h2)     = h1 == h2  (DuplexHandle _ h1 _) == (DuplexHandle _ h2 _) = h1 == h2- _ == _ = False + _ == _ = False  data Handle__   = forall dev enc_state dec_state . (IODevice dev, BufferedIO dev, Typeable dev) =>@@ -136,7 +135,7 @@       haCodec       :: Maybe TextEncoding,       haInputNL     :: Newline,       haOutputNL    :: Newline,-      haOtherSide   :: Maybe (MVar Handle__) -- ptr to the write side of a +      haOtherSide   :: Maybe (MVar Handle__) -- ptr to the write side of a                                              -- duplex handle.     }     deriving Typeable@@ -145,7 +144,7 @@ -- a new one for each hPutStr.  These buffers are *guaranteed* to be the -- same size as the main buffer. data BufferList e-  = BufferListNil +  = BufferListNil   | BufferListCons (RawBuffer e) (BufferList e)  --  Internally, we classify handles as being one@@ -203,13 +202,13 @@ -- --------------------------------------------------------------------------- -- Buffering modes --- | Three kinds of buffering are supported: line-buffering, +-- | Three kinds of buffering are supported: line-buffering, -- block-buffering or no-buffering.  These modes have the following -- effects. For output, items are written out, or /flushed/, -- from the internal buffer according to the buffer mode: -- --  * /line-buffering/: the entire output buffer is flushed---    whenever a newline is output, the buffer overflows, +--    whenever a newline is output, the buffer overflows, --    a 'System.IO.hFlush' is issued, or the handle is closed. -- --  * /block-buffering/: the entire buffer is written out whenever it@@ -240,10 +239,10 @@ -- The default buffering mode when a handle is opened is -- implementation-dependent and may depend on the file system object -- which is attached to that handle.--- For most implementations, physical files will normally be block-buffered +-- For most implementations, physical files will normally be block-buffered -- and terminals will normally be line-buffered. -data BufferMode  +data BufferMode  = NoBuffering  -- ^ buffering is disabled if possible.  | LineBuffering                 -- ^ line-buffering should be enabled if possible.@@ -257,7 +256,7 @@ [note Buffering Implementation]  Each Handle has two buffers: a byte buffer (haByteBuffer) and a Char-buffer (haCharBuffer).  +buffer (haCharBuffer).  [note Buffered Reading] @@ -360,7 +359,7 @@ -- are assumed to represent newlines with the '\n' character; the -- newline mode specifies how to translate '\n' on output, and what to -- translate into '\n' on input.-data NewlineMode +data NewlineMode   = NewlineMode { inputNL :: Newline,                     -- ^ the representation of newlines on input                   outputNL :: Newline@@ -381,25 +380,25 @@ -- represetnation on output.  This mode can be used on any platform, and -- works with text files using any newline convention.  The downside is -- that @readFile >>= writeFile@ might yield a different file.--- --- > universalNewlineMode  = NewlineMode { inputNL  = CRLF, +--+-- > universalNewlineMode  = NewlineMode { inputNL  = CRLF, -- >                                       outputNL = nativeNewline } -- universalNewlineMode :: NewlineMode-universalNewlineMode  = NewlineMode { inputNL  = CRLF, +universalNewlineMode  = NewlineMode { inputNL  = CRLF,                                       outputNL = nativeNewline }  -- | Use the native newline representation on both input and output--- +-- -- > nativeNewlineMode  = NewlineMode { inputNL  = nativeNewline -- >                                    outputNL = nativeNewline } -- nativeNewlineMode    :: NewlineMode-nativeNewlineMode     = NewlineMode { inputNL  = nativeNewline, +nativeNewlineMode     = NewlineMode { inputNL  = nativeNewline,                                       outputNL = nativeNewline }  -- | Do no newline translation at all.--- +-- -- > noNewlineTranslation  = NewlineMode { inputNL  = LF, outputNL = LF } -- noNewlineTranslation :: NewlineMode@@ -422,7 +421,7 @@       AppendHandle      -> showString "writable (append)"       ReadWriteHandle   -> showString "read-writable" -instance Show Handle where +instance Show Handle where   showsPrec _ (FileHandle   file _)   = showHandle file   showsPrec _ (DuplexHandle file _ _) = showHandle file 
GHC/IOArray.hs view
@@ -1,5 +1,5 @@ {-# LANGUAGE Unsafe #-}-{-# LANGUAGE NoImplicitPrelude, DeriveDataTypeable #-}+{-# LANGUAGE NoImplicitPrelude, AutoDeriveTypeable, RoleAnnotations #-} {-# OPTIONS_GHC -funbox-strict-fields #-} {-# OPTIONS_HADDOCK hide #-} @@ -40,6 +40,9 @@ --  newtype IOArray i e = IOArray (STArray RealWorld i e) deriving( Typeable )++-- index type should have a nominal role due to Ix class. See also #9220.+type role IOArray nominal representational  -- explicit instance because Haddock can't figure out a derived one instance Eq (IOArray i e) where
GHC/IORef.hs view
@@ -1,5 +1,5 @@ {-# LANGUAGE Unsafe #-}-{-# LANGUAGE NoImplicitPrelude, MagicHash, DeriveDataTypeable #-}+{-# LANGUAGE NoImplicitPrelude, MagicHash, AutoDeriveTypeable #-} {-# OPTIONS_GHC -funbox-strict-fields #-} {-# OPTIONS_HADDOCK hide #-} 
GHC/IP.hs view
@@ -1,10 +1,11 @@+{-# LANGUAGE Safe #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE KindSignatures #-} {-# LANGUAGE DataKinds #-}-{-# OPTIONS_GHC -XNoImplicitPrelude #-}+{-# LANGUAGE NoImplicitPrelude #-} --- | /Since: 4.6.0.0/+-- | @since 4.6.0.0 module GHC.IP (IP(..)) where  import GHC.TypeLits
GHC/Int.hs view
@@ -1,6 +1,6 @@ {-# LANGUAGE Trustworthy #-} {-# LANGUAGE CPP, NoImplicitPrelude, BangPatterns, MagicHash, UnboxedTuples,-             StandaloneDeriving, DeriveDataTypeable, NegativeLiterals #-}+             StandaloneDeriving, AutoDeriveTypeable, NegativeLiterals #-} {-# OPTIONS_HADDOCK hide #-}  -----------------------------------------------------------------------------@@ -39,7 +39,6 @@ import GHC.Arr import GHC.Word hiding (uncheckedShiftL64#, uncheckedShiftRL64#) import GHC.Show-import GHC.Float ()     -- for RealFrac methods import Data.Typeable  @@ -139,7 +138,7 @@     (I8# x#) .&.   (I8# y#)   = I8# (word2Int# (int2Word# x# `and#` int2Word# y#))     (I8# x#) .|.   (I8# y#)   = I8# (word2Int# (int2Word# x# `or#`  int2Word# y#))     (I8# x#) `xor` (I8# y#)   = I8# (word2Int# (int2Word# x# `xor#` int2Word# y#))-    complement (I8# x#)       = I8# (word2Int# (int2Word# x# `xor#` int2Word# (-1#)))+    complement (I8# x#)       = I8# (word2Int# (not# (int2Word# x#)))     (I8# x#) `shift` (I# i#)         | isTrue# (i# >=# 0#) = I8# (narrow8Int# (x# `iShiftL#` i#))         | otherwise           = I8# (x# `iShiftRA#` negateInt# i#)@@ -165,6 +164,8 @@  instance FiniteBits Int8 where     finiteBitSize _ = 8+    countLeadingZeros  (I8# x#) = I# (word2Int# (clz8# (int2Word# x#)))+    countTrailingZeros (I8# x#) = I# (word2Int# (ctz8# (int2Word# x#)))  {-# RULES "fromIntegral/Int8->Int8" fromIntegral = id :: Int8 -> Int8@@ -298,7 +299,7 @@     (I16# x#) .&.   (I16# y#)  = I16# (word2Int# (int2Word# x# `and#` int2Word# y#))     (I16# x#) .|.   (I16# y#)  = I16# (word2Int# (int2Word# x# `or#`  int2Word# y#))     (I16# x#) `xor` (I16# y#)  = I16# (word2Int# (int2Word# x# `xor#` int2Word# y#))-    complement (I16# x#)       = I16# (word2Int# (int2Word# x# `xor#` int2Word# (-1#)))+    complement (I16# x#)       = I16# (word2Int# (not# (int2Word# x#)))     (I16# x#) `shift` (I# i#)         | isTrue# (i# >=# 0#)  = I16# (narrow16Int# (x# `iShiftL#` i#))         | otherwise            = I16# (x# `iShiftRA#` negateInt# i#)@@ -324,6 +325,8 @@  instance FiniteBits Int16 where     finiteBitSize _ = 16+    countLeadingZeros  (I16# x#) = I# (word2Int# (clz16# (int2Word# x#)))+    countTrailingZeros (I16# x#) = I# (word2Int# (ctz16# (int2Word# x#)))  {-# RULES "fromIntegral/Word8->Int16"  fromIntegral = \(W8# x#) -> I16# (word2Int# x#)@@ -462,7 +465,7 @@     (I32# x#) .&.   (I32# y#)  = I32# (word2Int# (int2Word# x# `and#` int2Word# y#))     (I32# x#) .|.   (I32# y#)  = I32# (word2Int# (int2Word# x# `or#`  int2Word# y#))     (I32# x#) `xor` (I32# y#)  = I32# (word2Int# (int2Word# x# `xor#` int2Word# y#))-    complement (I32# x#)       = I32# (word2Int# (int2Word# x# `xor#` int2Word# (-1#)))+    complement (I32# x#)       = I32# (word2Int# (not# (int2Word# x#)))     (I32# x#) `shift` (I# i#)         | isTrue# (i# >=# 0#)  = I32# (narrow32Int# (x# `iShiftL#` i#))         | otherwise            = I32# (x# `iShiftRA#` negateInt# i#)@@ -489,6 +492,8 @@  instance FiniteBits Int32 where     finiteBitSize _ = 32+    countLeadingZeros  (I32# x#) = I# (word2Int# (clz32# (int2Word# x#)))+    countTrailingZeros (I32# x#) = I# (word2Int# (ctz32# (int2Word# x#)))  {-# RULES "fromIntegral/Word8->Int32"  fromIntegral = \(W8# x#) -> I32# (word2Int# x#)@@ -698,12 +703,12 @@ iShiftL64#, iShiftRA64# :: Int64# -> Int# -> Int64#  a `iShiftL64#` b  | isTrue# (b >=# 64#) = intToInt64# 0#-		  | otherwise           = a `uncheckedIShiftL64#` b+                  | otherwise           = a `uncheckedIShiftL64#` b  a `iShiftRA64#` b | isTrue# (b >=# 64#) = if isTrue# (a `ltInt64#` (intToInt64# 0#))-				          then intToInt64# (-1#)-					  else intToInt64# 0#-		  | otherwise = a `uncheckedIShiftRA64#` b+                                          then intToInt64# (-1#)+                                          else intToInt64# 0#+                  | otherwise = a `uncheckedIShiftRA64#` b  {-# RULES "fromIntegral/Int->Int64"    fromIntegral = \(I#   x#) -> I64# (intToInt64# x#)@@ -871,6 +876,13 @@  instance FiniteBits Int64 where     finiteBitSize _ = 64+#if WORD_SIZE_IN_BITS < 64+    countLeadingZeros  (I64# x#) = I# (word2Int# (clz64# (int64ToWord64# x#)))+    countTrailingZeros (I64# x#) = I# (word2Int# (ctz64# (int64ToWord64# x#)))+#else+    countLeadingZeros  (I64# x#) = I# (word2Int# (clz64# (int2Word# x#)))+    countTrailingZeros (I64# x#) = I# (word2Int# (ctz64# (int2Word# x#)))+#endif  instance Real Int64 where     toRational x = toInteger x % 1@@ -885,10 +897,9 @@     inRange (m,n) i     = m <= i && i <= n  -{--Note [Order of tests]--Suppose we had a definition like:+{- Note [Order of tests]+~~~~~~~~~~~~~~~~~~~~~~~~~+(See Trac #3065, #5161.) Suppose we had a definition like:      quot x y      | y == 0                     = divZeroError
+ GHC/List.hs view
@@ -0,0 +1,1005 @@+{-# LANGUAGE Trustworthy #-}+{-# LANGUAGE CPP, NoImplicitPrelude, ScopedTypeVariables, MagicHash #-}+{-# LANGUAGE BangPatterns #-}+{-# OPTIONS_HADDOCK hide #-}++-----------------------------------------------------------------------------+-- |+-- Module      :  GHC.List+-- Copyright   :  (c) The University of Glasgow 1994-2002+-- License     :  see libraries/base/LICENSE+--+-- Maintainer  :  cvs-ghc@haskell.org+-- Stability   :  internal+-- Portability :  non-portable (GHC Extensions)+--+-- The List data type and its operations+--+-----------------------------------------------------------------------------++module GHC.List (+   -- [] (..),          -- built-in syntax; can't be used in export list++   map, (++), filter, concat,+   head, last, tail, init, uncons, null, length, (!!),+   foldl, foldl', foldl1, foldl1', scanl, scanl1, scanl', foldr, foldr1,+   scanr, scanr1, iterate, repeat, replicate, cycle,+   take, drop, sum, product, maximum, minimum, splitAt, takeWhile, dropWhile,+   span, break, reverse, and, or,+   any, all, elem, notElem, lookup,+   concatMap,+   zip, zip3, zipWith, zipWith3, unzip, unzip3,+   errorEmptyList,++ ) where++import Data.Maybe+import GHC.Base+import GHC.Num (Num(..))+import GHC.Integer (Integer)++infixl 9  !!+infix  4 `elem`, `notElem`++--------------------------------------------------------------+-- List-manipulation functions+--------------------------------------------------------------++-- | Extract the first element of a list, which must be non-empty.+head                    :: [a] -> a+head (x:_)              =  x+head []                 =  badHead+{-# NOINLINE [1] head #-}++badHead :: a+badHead = errorEmptyList "head"++-- This rule is useful in cases like+--      head [y | (x,y) <- ps, x==t]+{-# RULES+"head/build"    forall (g::forall b.(a->b->b)->b->b) .+                head (build g) = g (\x _ -> x) badHead+"head/augment"  forall xs (g::forall b. (a->b->b) -> b -> b) .+                head (augment g xs) = g (\x _ -> x) (head xs)+ #-}++-- | Decompose a list into its head and tail. If the list is empty,+-- returns 'Nothing'. If the list is non-empty, returns @'Just' (x, xs)@,+-- where @x@ is the head of the list and @xs@ its tail.+--+-- @since 4.8.0.0+uncons                  :: [a] -> Maybe (a, [a])+uncons []               = Nothing+uncons (x:xs)           = Just (x, xs)++-- | Extract the elements after the head of a list, which must be non-empty.+tail                    :: [a] -> [a]+tail (_:xs)             =  xs+tail []                 =  errorEmptyList "tail"++-- | Extract the last element of a list, which must be finite and non-empty.+last                    :: [a] -> a+#ifdef USE_REPORT_PRELUDE+last [x]                =  x+last (_:xs)             =  last xs+last []                 =  errorEmptyList "last"+#else+-- use foldl to allow fusion+last = foldl (\_ x -> x) (errorEmptyList "last")+#endif++-- | Return all the elements of a list except the last one.+-- The list must be non-empty.+init                    :: [a] -> [a]+#ifdef USE_REPORT_PRELUDE+init [x]                =  []+init (x:xs)             =  x : init xs+init []                 =  errorEmptyList "init"+#else+-- eliminate repeated cases+init []                 =  errorEmptyList "init"+init (x:xs)             =  init' x xs+  where init' _ []     = []+        init' y (z:zs) = y : init' z zs+#endif++-- | Test whether a list is empty.+null                    :: [a] -> Bool+null []                 =  True+null (_:_)              =  False++-- | /O(n)/. 'length' returns the length of a finite list as an 'Int'.+-- It is an instance of the more general 'Data.List.genericLength',+-- the result type of which may be any kind of number.+{-# NOINLINE [1] length #-}+length                  :: [a] -> Int+length xs               = lenAcc xs 0++lenAcc          :: [a] -> Int -> Int+lenAcc []     n = n+lenAcc (_:ys) n = lenAcc ys (n+1)++{-# RULES+"length" [~1] forall xs . length xs = foldr lengthFB idLength xs 0+"lengthList" [1] foldr lengthFB idLength = lenAcc+ #-}++-- The lambda form turns out to be necessary to make this inline+-- when we need it to and give good performance.+{-# INLINE [0] lengthFB #-}+lengthFB :: x -> (Int -> Int) -> Int -> Int+lengthFB _ r = \ !a -> r (a + 1)++{-# INLINE [0] idLength #-}+idLength :: Int -> Int+idLength = id++-- | 'filter', applied to a predicate and a list, returns the list of+-- those elements that satisfy the predicate; i.e.,+--+-- > filter p xs = [ x | x <- xs, p x]++{-# NOINLINE [1] filter #-}+filter :: (a -> Bool) -> [a] -> [a]+filter _pred []    = []+filter pred (x:xs)+  | pred x         = x : filter pred xs+  | otherwise      = filter pred xs++{-# NOINLINE [0] filterFB #-}+filterFB :: (a -> b -> b) -> (a -> Bool) -> a -> b -> b+filterFB c p x r | p x       = x `c` r+                 | otherwise = r++{-# RULES+"filter"     [~1] forall p xs.  filter p xs = build (\c n -> foldr (filterFB c p) n xs)+"filterList" [1]  forall p.     foldr (filterFB (:) p) [] = filter p+"filterFB"        forall c p q. filterFB (filterFB c p) q = filterFB c (\x -> q x && p x)+ #-}++-- Note the filterFB rule, which has p and q the "wrong way round" in the RHS.+--     filterFB (filterFB c p) q a b+--   = if q a then filterFB c p a b else b+--   = if q a then (if p a then c a b else b) else b+--   = if q a && p a then c a b else b+--   = filterFB c (\x -> q x && p x) a b+-- I originally wrote (\x -> p x && q x), which is wrong, and actually+-- gave rise to a live bug report.  SLPJ.+++-- | 'foldl', applied to a binary operator, a starting value (typically+-- the left-identity of the operator), and a list, reduces the list+-- using the binary operator, from left to right:+--+-- > foldl f z [x1, x2, ..., xn] == (...((z `f` x1) `f` x2) `f`...) `f` xn+--+-- The list must be finite.++-- We write foldl as a non-recursive thing, so that it+-- can be inlined, and then (often) strictness-analysed,+-- and hence the classic space leak on foldl (+) 0 xs++foldl :: forall a b. (b -> a -> b) -> b -> [a] -> b+{-# INLINE foldl #-}+foldl k z0 xs =+  foldr (\(v::a) (fn::b->b) -> oneShot (\(z::b) -> fn (k z v))) (id :: b -> b) xs z0+  -- See Note [Left folds via right fold]++{-+Note [Left folds via right fold]++Implementing foldl et. al. via foldr is only a good idea if the compiler can+optimize the resulting code (eta-expand the recursive "go"). See #7994.+We hope that one of the two measure kick in:++   * Call Arity (-fcall-arity, enabled by default) eta-expands it if it can see+     all calls and determine that the arity is large.+   * The oneShot annotation gives a hint to the regular arity analysis that+     it may assume that the lambda is called at most once.+     See [One-shot lambdas] in CoreArity and especially [Eta expanding thunks]+     in CoreArity.++The oneShot annotations used in this module are correct, as we only use them in+argumets to foldr, where we know how the arguments are called.+-}++-- ----------------------------------------------------------------------------++-- | A strict version of 'foldl'.+foldl'           :: forall a b . (b -> a -> b) -> b -> [a] -> b+{-# INLINE foldl' #-}+foldl' k z0 xs =+  foldr (\(v::a) (fn::b->b) -> oneShot (\(z::b) -> z `seq` fn (k z v))) (id :: b -> b) xs z0+  -- See Note [Left folds via right fold]++-- | 'foldl1' is a variant of 'foldl' that has no starting value argument,+-- and thus must be applied to non-empty lists.+foldl1                  :: (a -> a -> a) -> [a] -> a+foldl1 f (x:xs)         =  foldl f x xs+foldl1 _ []             =  errorEmptyList "foldl1"++-- | A strict version of 'foldl1'+foldl1'                  :: (a -> a -> a) -> [a] -> a+foldl1' f (x:xs)         =  foldl' f x xs+foldl1' _ []             =  errorEmptyList "foldl1'"++-- -----------------------------------------------------------------------------+-- List sum and product++-- | The 'sum' function computes the sum of a finite list of numbers.+sum                     :: (Num a) => [a] -> a+{-# INLINE sum #-}+sum                     =  foldl (+) 0++-- | The 'product' function computes the product of a finite list of numbers.+product                 :: (Num a) => [a] -> a+{-# INLINE product #-}+product                 =  foldl (*) 1++-- | 'scanl' is similar to 'foldl', but returns a list of successive+-- reduced values from the left:+--+-- > scanl f z [x1, x2, ...] == [z, z `f` x1, (z `f` x1) `f` x2, ...]+--+-- Note that+--+-- > last (scanl f z xs) == foldl f z xs.++-- This peculiar arrangement is necessary to prevent scanl being rewritten in+-- its own right-hand side.+{-# NOINLINE [1] scanl #-}+scanl                   :: (b -> a -> b) -> b -> [a] -> [b]+scanl                   = scanlGo+  where+    scanlGo           :: (b -> a -> b) -> b -> [a] -> [b]+    scanlGo f q ls    = q : (case ls of+                               []   -> []+                               x:xs -> scanlGo f (f q x) xs)++-- Note [scanl rewrite rules]+{-# RULES+"scanl"  [~1] forall f a bs . scanl f a bs =+  build (\c n -> a `c` foldr (scanlFB f c) (constScanl n) bs a)+"scanlList" [1] forall f (a::a) bs .+    foldr (scanlFB f (:)) (constScanl []) bs a = tail (scanl f a bs)+ #-}++{-# INLINE [0] scanlFB #-}+scanlFB :: (b -> a -> b) -> (b -> c -> c) -> a -> (b -> c) -> b -> c+scanlFB f c = \b g -> oneShot (\x -> let b' = f x b in b' `c` g b')+  -- See Note [Left folds via right fold]++{-# INLINE [0] constScanl #-}+constScanl :: a -> b -> a+constScanl = const+++-- | 'scanl1' is a variant of 'scanl' that has no starting value argument:+--+-- > scanl1 f [x1, x2, ...] == [x1, x1 `f` x2, ...]++scanl1                  :: (a -> a -> a) -> [a] -> [a]+scanl1 f (x:xs)         =  scanl f x xs+scanl1 _ []             =  []++-- | A strictly accumulating version of 'scanl'+{-# NOINLINE [1] scanl' #-}+scanl'           :: (b -> a -> b) -> b -> [a] -> [b]+-- This peculiar form is needed to prevent scanl' from being rewritten+-- in its own right hand side.+scanl' = scanlGo'+  where+    scanlGo'           :: (b -> a -> b) -> b -> [a] -> [b]+    scanlGo' f !q ls    = q : (case ls of+                            []   -> []+                            x:xs -> scanlGo' f (f q x) xs)++-- Note [scanl rewrite rules]+{-# RULES+"scanl'"  [~1] forall f a bs . scanl' f a bs =+  build (\c n -> a `c` foldr (scanlFB' f c) (flipSeqScanl' n) bs a)+"scanlList'" [1] forall f a bs .+    foldr (scanlFB' f (:)) (flipSeqScanl' []) bs a = tail (scanl' f a bs)+ #-}++{-# INLINE [0] scanlFB' #-}+scanlFB' :: (b -> a -> b) -> (b -> c -> c) -> a -> (b -> c) -> b -> c+scanlFB' f c = \b g -> oneShot (\x -> let !b' = f x b in b' `c` g b')+  -- See Note [Left folds via right fold]++{-# INLINE [0] flipSeqScanl' #-}+flipSeqScanl' :: a -> b -> a+flipSeqScanl' a !_b = a++{-+Note [scanl rewrite rules]+~~~~~~~~~~~~~~~~~~~~~~~~~~++In most cases, when we rewrite a form to one that can fuse, we try to rewrite it+back to the original form if it does not fuse. For scanl, we do something a+little different. In particular, we rewrite++scanl f a bs++to++build (\c n -> a `c` foldr (scanlFB f c) (constScanl n) bs a)++When build is inlined, this becomes++a : foldr (scanlFB f (:)) (constScanl []) bs a++To rewrite this form back to scanl, we would need a rule that looked like++forall f a bs. a : foldr (scanlFB f (:)) (constScanl []) bs a = scanl f a bs++The problem with this rule is that it has (:) at its head. This would have the+effect of changing the way the inliner looks at (:), not only here but+everywhere.  In most cases, this makes no difference, but in some cases it+causes it to come to a different decision about whether to inline something.+Based on nofib benchmarks, this is bad for performance. Therefore, we instead+match on everything past the :, which is just the tail of scanl.+-}++-- foldr, foldr1, scanr, and scanr1 are the right-to-left duals of the+-- above functions.++-- | 'foldr1' is a variant of 'foldr' that has no starting value argument,+-- and thus must be applied to non-empty lists.++foldr1                  :: (a -> a -> a) -> [a] -> a+foldr1 _ [x]            =  x+foldr1 f (x:xs)         =  f x (foldr1 f xs)+foldr1 _ []             =  errorEmptyList "foldr1"++-- | 'scanr' is the right-to-left dual of 'scanl'.+-- Note that+--+-- > head (scanr f z xs) == foldr f z xs.+{-# NOINLINE [1] scanr #-}+scanr                   :: (a -> b -> b) -> b -> [a] -> [b]+scanr _ q0 []           =  [q0]+scanr f q0 (x:xs)       =  f x q : qs+                           where qs@(q:_) = scanr f q0 xs++{-# INLINE [0] strictUncurryScanr #-}+strictUncurryScanr :: (a -> b -> c) -> (a, b) -> c+strictUncurryScanr f pair = case pair of+                              (x, y) -> f x y++{-# INLINE [0] scanrFB #-}+scanrFB :: (a -> b -> b) -> (b -> c -> c) -> a -> (b, c) -> (b, c)+scanrFB f c = \x (r, est) -> (f x r, r `c` est)++{-# RULES+"scanr" [~1] forall f q0 ls . scanr f q0 ls =+  build (\c n -> strictUncurryScanr c (foldr (scanrFB f c) (q0,n) ls))+"scanrList" [1] forall f q0 ls .+               strictUncurryScanr (:) (foldr (scanrFB f (:)) (q0,[]) ls) =+                 scanr f q0 ls+ #-}++-- | 'scanr1' is a variant of 'scanr' that has no starting value argument.+scanr1                  :: (a -> a -> a) -> [a] -> [a]+scanr1 _ []             =  []+scanr1 _ [x]            =  [x]+scanr1 f (x:xs)         =  f x q : qs+                           where qs@(q:_) = scanr1 f xs++-- | 'maximum' returns the maximum value from a list,+-- which must be non-empty, finite, and of an ordered type.+-- It is a special case of 'Data.List.maximumBy', which allows the+-- programmer to supply their own comparison function.+maximum                 :: (Ord a) => [a] -> a+{-# INLINE [1] maximum #-}+maximum []              =  errorEmptyList "maximum"+maximum xs              =  foldl1 max xs++{-# RULES+  "maximumInt"     maximum = (strictMaximum :: [Int]     -> Int);+  "maximumInteger" maximum = (strictMaximum :: [Integer] -> Integer)+ #-}++-- We can't make the overloaded version of maximum strict without+-- changing its semantics (max might not be strict), but we can for+-- the version specialised to 'Int'.+strictMaximum           :: (Ord a) => [a] -> a+strictMaximum []        =  errorEmptyList "maximum"+strictMaximum xs        =  foldl1' max xs++-- | 'minimum' returns the minimum value from a list,+-- which must be non-empty, finite, and of an ordered type.+-- It is a special case of 'Data.List.minimumBy', which allows the+-- programmer to supply their own comparison function.+minimum                 :: (Ord a) => [a] -> a+{-# INLINE [1] minimum #-}+minimum []              =  errorEmptyList "minimum"+minimum xs              =  foldl1 min xs++{-# RULES+  "minimumInt"     minimum = (strictMinimum :: [Int]     -> Int);+  "minimumInteger" minimum = (strictMinimum :: [Integer] -> Integer)+ #-}++strictMinimum           :: (Ord a) => [a] -> a+strictMinimum []        =  errorEmptyList "minimum"+strictMinimum xs        =  foldl1' min xs+++-- | 'iterate' @f x@ returns an infinite list of repeated applications+-- of @f@ to @x@:+--+-- > iterate f x == [x, f x, f (f x), ...]++{-# NOINLINE [1] iterate #-}+iterate :: (a -> a) -> a -> [a]+iterate f x =  x : iterate f (f x)++{-# NOINLINE [0] iterateFB #-}+iterateFB :: (a -> b -> b) -> (a -> a) -> a -> b+iterateFB c f x0 = go x0+  where go x = x `c` go (f x)++{-# RULES+"iterate"    [~1] forall f x.   iterate f x = build (\c _n -> iterateFB c f x)+"iterateFB"  [1]                iterateFB (:) = iterate+ #-}+++-- | 'repeat' @x@ is an infinite list, with @x@ the value of every element.+repeat :: a -> [a]+{-# INLINE [0] repeat #-}+-- The pragma just gives the rules more chance to fire+repeat x = xs where xs = x : xs++{-# INLINE [0] repeatFB #-}     -- ditto+repeatFB :: (a -> b -> b) -> a -> b+repeatFB c x = xs where xs = x `c` xs+++{-# RULES+"repeat"    [~1] forall x. repeat x = build (\c _n -> repeatFB c x)+"repeatFB"  [1]  repeatFB (:)       = repeat+ #-}++-- | 'replicate' @n x@ is a list of length @n@ with @x@ the value of+-- every element.+-- It is an instance of the more general 'Data.List.genericReplicate',+-- in which @n@ may be of any integral type.+{-# INLINE replicate #-}+replicate               :: Int -> a -> [a]+replicate n x           =  take n (repeat x)++-- | 'cycle' ties a finite list into a circular one, or equivalently,+-- the infinite repetition of the original list.  It is the identity+-- on infinite lists.++cycle                   :: [a] -> [a]+cycle []                = errorEmptyList "cycle"+cycle xs                = xs' where xs' = xs ++ xs'++-- | 'takeWhile', applied to a predicate @p@ and a list @xs@, returns the+-- longest prefix (possibly empty) of @xs@ of elements that satisfy @p@:+--+-- > takeWhile (< 3) [1,2,3,4,1,2,3,4] == [1,2]+-- > takeWhile (< 9) [1,2,3] == [1,2,3]+-- > takeWhile (< 0) [1,2,3] == []+--++{-# NOINLINE [1] takeWhile #-}+takeWhile               :: (a -> Bool) -> [a] -> [a]+takeWhile _ []          =  []+takeWhile p (x:xs)+            | p x       =  x : takeWhile p xs+            | otherwise =  []++{-# INLINE [0] takeWhileFB #-}+takeWhileFB :: (a -> Bool) -> (a -> b -> b) -> b -> a -> b -> b+takeWhileFB p c n = \x r -> if p x then x `c` r else n++-- The takeWhileFB rule is similar to the filterFB rule. It works like this:+-- takeWhileFB q (takeWhileFB p c n) n =+-- \x r -> if q x then (takeWhileFB p c n) x r else n =+-- \x r -> if q x then (\x' r' -> if p x' then x' `c` r' else n) x r else n =+-- \x r -> if q x then (if p x then x `c` r else n) else n =+-- \x r -> if q x && p x then x `c` r else n =+-- takeWhileFB (\x -> q x && p x) c n+{-# RULES+"takeWhile"     [~1] forall p xs. takeWhile p xs =+                                build (\c n -> foldr (takeWhileFB p c n) n xs)+"takeWhileList" [1]  forall p.    foldr (takeWhileFB p (:) []) [] = takeWhile p+"takeWhileFB"        forall c n p q. takeWhileFB q (takeWhileFB p c n) n =+                        takeWhileFB (\x -> q x && p x) c n+ #-}++-- | 'dropWhile' @p xs@ returns the suffix remaining after 'takeWhile' @p xs@:+--+-- > dropWhile (< 3) [1,2,3,4,5,1,2,3] == [3,4,5,1,2,3]+-- > dropWhile (< 9) [1,2,3] == []+-- > dropWhile (< 0) [1,2,3] == [1,2,3]+--++dropWhile               :: (a -> Bool) -> [a] -> [a]+dropWhile _ []          =  []+dropWhile p xs@(x:xs')+            | p x       =  dropWhile p xs'+            | otherwise =  xs++-- | 'take' @n@, applied to a list @xs@, returns the prefix of @xs@+-- of length @n@, or @xs@ itself if @n > 'length' xs@:+--+-- > take 5 "Hello World!" == "Hello"+-- > take 3 [1,2,3,4,5] == [1,2,3]+-- > take 3 [1,2] == [1,2]+-- > take 3 [] == []+-- > take (-1) [1,2] == []+-- > take 0 [1,2] == []+--+-- It is an instance of the more general 'Data.List.genericTake',+-- in which @n@ may be of any integral type.+take                   :: Int -> [a] -> [a]+#ifdef USE_REPORT_PRELUDE+take n _      | n <= 0 =  []+take _ []              =  []+take n (x:xs)          =  x : take (n-1) xs+#else++{- We always want to inline this to take advantage of a known length argument+sign. Note, however, that it's important for the RULES to grab take, rather+than trying to INLINE take immediately and then letting the RULES grab+unsafeTake. Presumably the latter approach doesn't grab it early enough; it led+to an allocation regression in nofib/fft2. -}+{-# INLINE [1] take #-}+take n xs | 0 < n     = unsafeTake n xs+          | otherwise = []++-- A version of take that takes the whole list if it's given an argument less+-- than 1.+{-# NOINLINE [1] unsafeTake #-}+unsafeTake :: Int -> [a] -> [a]+unsafeTake !_  []     = []+unsafeTake 1   (x: _) = [x]+unsafeTake m   (x:xs) = x : unsafeTake (m - 1) xs++{-# RULES+"take"     [~1] forall n xs . take n xs =+  build (\c nil -> if 0 < n+                   then foldr (takeFB c nil) (flipSeqTake nil) xs n+                   else nil)+"unsafeTakeList"  [1] forall n xs . foldr (takeFB (:) []) (flipSeqTake []) xs n+                                        = unsafeTake n xs+ #-}++{-# INLINE [0] flipSeqTake #-}+-- Just flip seq, specialized to Int, but not inlined too early.+-- It's important to force the numeric argument here, even though+-- it's not used. Otherwise, take n [] doesn't force n. This is+-- bad for strictness analysis and unboxing, and leads to increased+-- allocation in T7257.+flipSeqTake :: a -> Int -> a+flipSeqTake x !_n = x++{-# INLINE [0] takeFB #-}+takeFB :: (a -> b -> b) -> b -> a -> (Int -> b) -> Int -> b+-- The \m accounts for the fact that takeFB is used in a higher-order+-- way by takeFoldr, so it's better to inline.  A good example is+--     take n (repeat x)+-- for which we get excellent code... but only if we inline takeFB+-- when given four arguments+takeFB c n x xs+  = \ m -> case m of+            1 -> x `c` n+            _ -> x `c` xs (m - 1)+#endif++-- | 'drop' @n xs@ returns the suffix of @xs@+-- after the first @n@ elements, or @[]@ if @n > 'length' xs@:+--+-- > drop 6 "Hello World!" == "World!"+-- > drop 3 [1,2,3,4,5] == [4,5]+-- > drop 3 [1,2] == []+-- > drop 3 [] == []+-- > drop (-1) [1,2] == [1,2]+-- > drop 0 [1,2] == [1,2]+--+-- It is an instance of the more general 'Data.List.genericDrop',+-- in which @n@ may be of any integral type.+drop                   :: Int -> [a] -> [a]+#ifdef USE_REPORT_PRELUDE+drop n xs     | n <= 0 =  xs+drop _ []              =  []+drop n (_:xs)          =  drop (n-1) xs+#else /* hack away */+{-# INLINE drop #-}+drop n ls+  | n <= 0     = ls+  | otherwise  = unsafeDrop n ls+  where+    -- A version of drop that drops the whole list if given an argument+    -- less than 1+    unsafeDrop :: Int -> [a] -> [a]+    unsafeDrop !_ []     = []+    unsafeDrop 1  (_:xs) = xs+    unsafeDrop m  (_:xs) = unsafeDrop (m - 1) xs+#endif++-- | 'splitAt' @n xs@ returns a tuple where first element is @xs@ prefix of+-- length @n@ and second element is the remainder of the list:+--+-- > splitAt 6 "Hello World!" == ("Hello ","World!")+-- > splitAt 3 [1,2,3,4,5] == ([1,2,3],[4,5])+-- > splitAt 1 [1,2,3] == ([1],[2,3])+-- > splitAt 3 [1,2,3] == ([1,2,3],[])+-- > splitAt 4 [1,2,3] == ([1,2,3],[])+-- > splitAt 0 [1,2,3] == ([],[1,2,3])+-- > splitAt (-1) [1,2,3] == ([],[1,2,3])+--+-- It is equivalent to @('take' n xs, 'drop' n xs)@ when @n@ is not @_|_@+-- (@splitAt _|_ xs = _|_@).+-- 'splitAt' is an instance of the more general 'Data.List.genericSplitAt',+-- in which @n@ may be of any integral type.+splitAt                :: Int -> [a] -> ([a],[a])++#ifdef USE_REPORT_PRELUDE+splitAt n xs           =  (take n xs, drop n xs)+#else+splitAt n ls+  | n <= 0 = ([], ls)+  | otherwise          = splitAt' n ls+    where+        splitAt' :: Int -> [a] -> ([a], [a])+        splitAt' _  []     = ([], [])+        splitAt' 1  (x:xs) = ([x], xs)+        splitAt' m  (x:xs) = (x:xs', xs'')+          where+            (xs', xs'') = splitAt' (m - 1) xs+#endif /* USE_REPORT_PRELUDE */++-- | 'span', applied to a predicate @p@ and a list @xs@, returns a tuple where+-- first element is longest prefix (possibly empty) of @xs@ of elements that+-- satisfy @p@ and second element is the remainder of the list:+--+-- > span (< 3) [1,2,3,4,1,2,3,4] == ([1,2],[3,4,1,2,3,4])+-- > span (< 9) [1,2,3] == ([1,2,3],[])+-- > span (< 0) [1,2,3] == ([],[1,2,3])+--+-- 'span' @p xs@ is equivalent to @('takeWhile' p xs, 'dropWhile' p xs)@++span                    :: (a -> Bool) -> [a] -> ([a],[a])+span _ xs@[]            =  (xs, xs)+span p xs@(x:xs')+         | p x          =  let (ys,zs) = span p xs' in (x:ys,zs)+         | otherwise    =  ([],xs)++-- | 'break', applied to a predicate @p@ and a list @xs@, returns a tuple where+-- first element is longest prefix (possibly empty) of @xs@ of elements that+-- /do not satisfy/ @p@ and second element is the remainder of the list:+--+-- > break (> 3) [1,2,3,4,1,2,3,4] == ([1,2,3],[4,1,2,3,4])+-- > break (< 9) [1,2,3] == ([],[1,2,3])+-- > break (> 9) [1,2,3] == ([1,2,3],[])+--+-- 'break' @p@ is equivalent to @'span' ('not' . p)@.++break                   :: (a -> Bool) -> [a] -> ([a],[a])+#ifdef USE_REPORT_PRELUDE+break p                 =  span (not . p)+#else+-- HBC version (stolen)+break _ xs@[]           =  (xs, xs)+break p xs@(x:xs')+           | p x        =  ([],xs)+           | otherwise  =  let (ys,zs) = break p xs' in (x:ys,zs)+#endif++-- | 'reverse' @xs@ returns the elements of @xs@ in reverse order.+-- @xs@ must be finite.+reverse                 :: [a] -> [a]+#ifdef USE_REPORT_PRELUDE+reverse                 =  foldl (flip (:)) []+#else+reverse l =  rev l []+  where+    rev []     a = a+    rev (x:xs) a = rev xs (x:a)+#endif++-- | 'and' returns the conjunction of a Boolean list.  For the result to be+-- 'True', the list must be finite; 'False', however, results from a 'False'+-- value at a finite index of a finite or infinite list.+and                     :: [Bool] -> Bool+#ifdef USE_REPORT_PRELUDE+and                     =  foldr (&&) True+#else+and []          =  True+and (x:xs)      =  x && and xs+{-# NOINLINE [1] and #-}++{-# RULES+"and/build"     forall (g::forall b.(Bool->b->b)->b->b) .+                and (build g) = g (&&) True+ #-}+#endif++-- | 'or' returns the disjunction of a Boolean list.  For the result to be+-- 'False', the list must be finite; 'True', however, results from a 'True'+-- value at a finite index of a finite or infinite list.+or                      :: [Bool] -> Bool+#ifdef USE_REPORT_PRELUDE+or                      =  foldr (||) False+#else+or []           =  False+or (x:xs)       =  x || or xs+{-# NOINLINE [1] or #-}++{-# RULES+"or/build"      forall (g::forall b.(Bool->b->b)->b->b) .+                or (build g) = g (||) False+ #-}+#endif++-- | Applied to a predicate and a list, 'any' determines if any element+-- of the list satisfies the predicate.  For the result to be+-- 'False', the list must be finite; 'True', however, results from a 'True'+-- value for the predicate applied to an element at a finite index of a finite or infinite list.+any                     :: (a -> Bool) -> [a] -> Bool++#ifdef USE_REPORT_PRELUDE+any p                   =  or . map p+#else+any _ []        = False+any p (x:xs)    = p x || any p xs++{-# NOINLINE [1] any #-}++{-# RULES+"any/build"     forall p (g::forall b.(a->b->b)->b->b) .+                any p (build g) = g ((||) . p) False+ #-}+#endif++-- | Applied to a predicate and a list, 'all' determines if all elements+-- of the list satisfy the predicate. For the result to be+-- 'True', the list must be finite; 'False', however, results from a 'False'+-- value for the predicate applied to an element at a finite index of a finite or infinite list.+all                     :: (a -> Bool) -> [a] -> Bool+#ifdef USE_REPORT_PRELUDE+all p                   =  and . map p+#else+all _ []        =  True+all p (x:xs)    =  p x && all p xs++{-# NOINLINE [1] all #-}++{-# RULES+"all/build"     forall p (g::forall b.(a->b->b)->b->b) .+                all p (build g) = g ((&&) . p) True+ #-}+#endif++-- | 'elem' is the list membership predicate, usually written in infix form,+-- e.g., @x \`elem\` xs@.  For the result to be+-- 'False', the list must be finite; 'True', however, results from an element+-- equal to @x@ found at a finite index of a finite or infinite list.+elem                    :: (Eq a) => a -> [a] -> Bool+#ifdef USE_REPORT_PRELUDE+elem x                  =  any (== x)+#else+elem _ []       = False+elem x (y:ys)   = x==y || elem x ys+{-# NOINLINE [1] elem #-}+{-# RULES+"elem/build"    forall x (g :: forall b . Eq a => (a -> b -> b) -> b -> b)+   . elem x (build g) = g (\ y r -> (x == y) || r) False+ #-}+#endif++-- | 'notElem' is the negation of 'elem'.+notElem                 :: (Eq a) => a -> [a] -> Bool+#ifdef USE_REPORT_PRELUDE+notElem x               =  all (/= x)+#else+notElem _ []    =  True+notElem x (y:ys)=  x /= y && notElem x ys+{-# NOINLINE [1] notElem #-}+{-# RULES+"notElem/build" forall x (g :: forall b . Eq a => (a -> b -> b) -> b -> b)+   . notElem x (build g) = g (\ y r -> (x /= y) && r) True+ #-}+#endif++-- | 'lookup' @key assocs@ looks up a key in an association list.+lookup                  :: (Eq a) => a -> [(a,b)] -> Maybe b+lookup _key []          =  Nothing+lookup  key ((x,y):xys)+    | key == x          =  Just y+    | otherwise         =  lookup key xys++-- | Map a function over a list and concatenate the results.+concatMap               :: (a -> [b]) -> [a] -> [b]+concatMap f             =  foldr ((++) . f) []++{-# NOINLINE [1] concatMap #-}++{-# RULES+"concatMap" forall f xs . concatMap f xs =+    build (\c n -> foldr (\x b -> foldr c b (f x)) n xs)+ #-}+++-- | Concatenate a list of lists.+concat :: [[a]] -> [a]+concat = foldr (++) []++{-# NOINLINE [1] concat #-}++{-# RULES+  "concat" forall xs. concat xs =+     build (\c n -> foldr (\x y -> foldr c y x) n xs)+-- We don't bother to turn non-fusible applications of concat back into concat+ #-}++-- | List index (subscript) operator, starting from 0.+-- It is an instance of the more general 'Data.List.genericIndex',+-- which takes an index of any integral type.+(!!)                    :: [a] -> Int -> a+#ifdef USE_REPORT_PRELUDE+xs     !! n | n < 0 =  error "Prelude.!!: negative index"+[]     !! _         =  error "Prelude.!!: index too large"+(x:_)  !! 0         =  x+(_:xs) !! n         =  xs !! (n-1)+#else++-- We don't really want the errors to inline with (!!).+-- We may want to fuss around a bit with NOINLINE, and+-- if so we should be careful not to trip up known-bottom+-- optimizations.+tooLarge :: Int -> a+tooLarge _ = error (prel_list_str ++ "!!: index too large")++negIndex :: a+negIndex = error $ prel_list_str ++ "!!: negative index"++{-# INLINABLE (!!) #-}+xs !! n+  | n < 0     = negIndex+  | otherwise = foldr (\x r k -> case k of+                                   0 -> x+                                   _ -> r (k-1)) tooLarge xs n+#endif++--------------------------------------------------------------+-- The zip family+--------------------------------------------------------------++foldr2 :: (a -> b -> c -> c) -> c -> [a] -> [b] -> c+foldr2 k z = go+  where+        go []    _ys     = z+        go _xs   []      = z+        go (x:xs) (y:ys) = k x y (go xs ys)+{-# INLINE [0] foldr2 #-}++foldr2_left :: (a -> b -> c -> d) -> d -> a -> ([b] -> c) -> [b] -> d+foldr2_left _k  z _x _r []     = z+foldr2_left  k _z  x  r (y:ys) = k x y (r ys)++-- foldr2 k z xs ys = foldr (foldr2_left k z)  (\_ -> z) xs ys+{-# RULES+"foldr2/left"   forall k z ys (g::forall b.(a->b->b)->b->b) .+                  foldr2 k z (build g) ys = g (foldr2_left  k z) (\_ -> z) ys+ #-}+-- There used to be a foldr2/right rule, allowing foldr2 to fuse with a build+-- form on the right. However, this causes trouble if the right list ends in+-- a bottom that is only avoided by the left list ending at that spot. That is,+-- foldr2 f z [a,b,c] (d:e:f:_|_), where the right list is produced by a build+-- form, would cause the foldr2/right rule to introduce bottom. Example:+--+-- zip [1,2,3,4] (unfoldr (\s -> if s > 4 then undefined else Just (s,s+1)) 1)+--+-- should produce+--+-- [(1,1),(2,2),(3,3),(4,4)]+--+-- but with the foldr2/right rule it would instead produce+--+-- (1,1):(2,2):(3,3):(4,4):_|_++-- Zips for larger tuples are in the List module.++----------------------------------------------+-- | 'zip' takes two lists and returns a list of corresponding pairs.+-- If one input list is short, excess elements of the longer list are+-- discarded.+--+-- 'zip' is right-lazy:+--+-- > zip [] _|_ = []+{-# NOINLINE [1] zip #-}+zip :: [a] -> [b] -> [(a,b)]+zip []     _bs    = []+zip _as    []     = []+zip (a:as) (b:bs) = (a,b) : zip as bs++{-# INLINE [0] zipFB #-}+zipFB :: ((a, b) -> c -> d) -> a -> b -> c -> d+zipFB c = \x y r -> (x,y) `c` r++{-# RULES+"zip"      [~1] forall xs ys. zip xs ys = build (\c n -> foldr2 (zipFB c) n xs ys)+"zipList"  [1]  foldr2 (zipFB (:)) []   = zip+ #-}++----------------------------------------------+-- | 'zip3' takes three lists and returns a list of triples, analogous to+-- 'zip'.+zip3 :: [a] -> [b] -> [c] -> [(a,b,c)]+-- Specification+-- zip3 =  zipWith3 (,,)+zip3 (a:as) (b:bs) (c:cs) = (a,b,c) : zip3 as bs cs+zip3 _      _      _      = []+++-- The zipWith family generalises the zip family by zipping with the+-- function given as the first argument, instead of a tupling function.++----------------------------------------------+-- | 'zipWith' generalises 'zip' by zipping with the function given+-- as the first argument, instead of a tupling function.+-- For example, @'zipWith' (+)@ is applied to two lists to produce the+-- list of corresponding sums.+--+-- 'zipWith' is right-lazy:+--+-- > zipWith f [] _|_ = []+{-# NOINLINE [1] zipWith #-}+zipWith :: (a->b->c) -> [a]->[b]->[c]+zipWith _f []     _bs    = []+zipWith _f _as    []     = []+zipWith f  (a:as) (b:bs) = f a b : zipWith f as bs++-- zipWithFB must have arity 2 since it gets two arguments in the "zipWith"+-- rule; it might not get inlined otherwise+{-# INLINE [0] zipWithFB #-}+zipWithFB :: (a -> b -> c) -> (d -> e -> a) -> d -> e -> b -> c+zipWithFB c f = \x y r -> (x `f` y) `c` r++{-# RULES+"zipWith"       [~1] forall f xs ys.    zipWith f xs ys = build (\c n -> foldr2 (zipWithFB c f) n xs ys)+"zipWithList"   [1]  forall f.  foldr2 (zipWithFB (:) f) [] = zipWith f+  #-}++-- | The 'zipWith3' function takes a function which combines three+-- elements, as well as three lists and returns a list of their point-wise+-- combination, analogous to 'zipWith'.+zipWith3                :: (a->b->c->d) -> [a]->[b]->[c]->[d]+zipWith3 z (a:as) (b:bs) (c:cs)+                        =  z a b c : zipWith3 z as bs cs+zipWith3 _ _ _ _        =  []++-- | 'unzip' transforms a list of pairs into a list of first components+-- and a list of second components.+unzip    :: [(a,b)] -> ([a],[b])+{-# INLINE unzip #-}+unzip    =  foldr (\(a,b) ~(as,bs) -> (a:as,b:bs)) ([],[])++-- | The 'unzip3' function takes a list of triples and returns three+-- lists, analogous to 'unzip'.+unzip3   :: [(a,b,c)] -> ([a],[b],[c])+{-# INLINE unzip3 #-}+unzip3   =  foldr (\(a,b,c) ~(as,bs,cs) -> (a:as,b:bs,c:cs))+                  ([],[],[])++--------------------------------------------------------------+-- Error code+--------------------------------------------------------------++-- Common up near identical calls to `error' to reduce the number+-- constant strings created when compiled:++errorEmptyList :: String -> a+errorEmptyList fun =+  error (prel_list_str ++ fun ++ ": empty list")++prel_list_str :: String+prel_list_str = "Prelude."
− GHC/List.lhs
@@ -1,772 +0,0 @@-\begin{code}-{-# LANGUAGE Trustworthy #-}-{-# LANGUAGE CPP, NoImplicitPrelude, MagicHash #-}-{-# OPTIONS_HADDOCK hide #-}---------------------------------------------------------------------------------- |--- Module      :  GHC.List--- Copyright   :  (c) The University of Glasgow 1994-2002--- License     :  see libraries/base/LICENSE------ Maintainer  :  cvs-ghc@haskell.org--- Stability   :  internal--- Portability :  non-portable (GHC Extensions)------ The List data type and its operations-----------------------------------------------------------------------------------module GHC.List (-   -- [] (..),          -- built-in syntax; can't be used in export list--   map, (++), filter, concat,-   head, last, tail, init, null, length, (!!),-   foldl, scanl, scanl1, foldr, foldr1, scanr, scanr1,-   iterate, repeat, replicate, cycle,-   take, drop, splitAt, takeWhile, dropWhile, span, break,-   reverse, and, or,-   any, all, elem, notElem, lookup,-   concatMap,-   zip, zip3, zipWith, zipWith3, unzip, unzip3,-   errorEmptyList,--#ifndef USE_REPORT_PRELUDE-   -- non-standard, but hidden when creating the Prelude-   -- export list.-   takeUInt_append-#endif-- ) where--import Data.Maybe-import GHC.Base--infixl 9  !!-infix  4 `elem`, `notElem`-\end{code}--%*********************************************************-%*                                                      *-\subsection{List-manipulation functions}-%*                                                      *-%*********************************************************--\begin{code}--- | Extract the first element of a list, which must be non-empty.-head                    :: [a] -> a-head (x:_)              =  x-head []                 =  badHead-{-# NOINLINE [1] head #-}--badHead :: a-badHead = errorEmptyList "head"---- This rule is useful in cases like---      head [y | (x,y) <- ps, x==t]-{-# RULES-"head/build"    forall (g::forall b.(a->b->b)->b->b) .-                head (build g) = g (\x _ -> x) badHead-"head/augment"  forall xs (g::forall b. (a->b->b) -> b -> b) .-                head (augment g xs) = g (\x _ -> x) (head xs)- #-}---- | Extract the elements after the head of a list, which must be non-empty.-tail                    :: [a] -> [a]-tail (_:xs)             =  xs-tail []                 =  errorEmptyList "tail"---- | Extract the last element of a list, which must be finite and non-empty.-last                    :: [a] -> a-#ifdef USE_REPORT_PRELUDE-last [x]                =  x-last (_:xs)             =  last xs-last []                 =  errorEmptyList "last"-#else--- eliminate repeated cases-last []                 =  errorEmptyList "last"-last (x:xs)             =  last' x xs-  where last' y []     = y-        last' _ (y:ys) = last' y ys-#endif---- | Return all the elements of a list except the last one.--- The list must be non-empty.-init                    :: [a] -> [a]-#ifdef USE_REPORT_PRELUDE-init [x]                =  []-init (x:xs)             =  x : init xs-init []                 =  errorEmptyList "init"-#else--- eliminate repeated cases-init []                 =  errorEmptyList "init"-init (x:xs)             =  init' x xs-  where init' _ []     = []-        init' y (z:zs) = y : init' z zs-#endif---- | Test whether a list is empty.-null                    :: [a] -> Bool-null []                 =  True-null (_:_)              =  False---- | /O(n)/. 'length' returns the length of a finite list as an 'Int'.--- It is an instance of the more general 'Data.List.genericLength',--- the result type of which may be any kind of number.-{-# NOINLINE [1] length #-}-length                  :: [a] -> Int-length l                =  lenAcc l 0#--lenAcc :: [a] -> Int# -> Int-lenAcc []     a# = I# a#-lenAcc (_:xs) a# = lenAcc xs (a# +# 1#)--incLen :: a -> (Int# -> Int) -> Int# -> Int-incLen _ g x = g (x +# 1#)---- These rules make length into a good consumer--- Note that we use a higher-order-style use of foldr, so that--- the accumulating parameter can be evaluated strictly--- See Trac #876 for what goes wrong otherwise-{-# RULES-"length"     [~1] forall xs. length xs = foldr incLen I# xs 0#-"lengthList" [1]  foldr incLen I# = lenAcc- #-}---- | 'filter', applied to a predicate and a list, returns the list of--- those elements that satisfy the predicate; i.e.,------ > filter p xs = [ x | x <- xs, p x]--{-# NOINLINE [1] filter #-}-filter :: (a -> Bool) -> [a] -> [a]-filter _pred []    = []-filter pred (x:xs)-  | pred x         = x : filter pred xs-  | otherwise      = filter pred xs--{-# NOINLINE [0] filterFB #-}-filterFB :: (a -> b -> b) -> (a -> Bool) -> a -> b -> b-filterFB c p x r | p x       = x `c` r-                 | otherwise = r--{-# RULES-"filter"     [~1] forall p xs.  filter p xs = build (\c n -> foldr (filterFB c p) n xs)-"filterList" [1]  forall p.     foldr (filterFB (:) p) [] = filter p-"filterFB"        forall c p q. filterFB (filterFB c p) q = filterFB c (\x -> q x && p x)- #-}---- Note the filterFB rule, which has p and q the "wrong way round" in the RHS.---     filterFB (filterFB c p) q a b---   = if q a then filterFB c p a b else b---   = if q a then (if p a then c a b else b) else b---   = if q a && p a then c a b else b---   = filterFB c (\x -> q x && p x) a b--- I originally wrote (\x -> p x && q x), which is wrong, and actually--- gave rise to a live bug report.  SLPJ.----- | 'foldl', applied to a binary operator, a starting value (typically--- the left-identity of the operator), and a list, reduces the list--- using the binary operator, from left to right:------ > foldl f z [x1, x2, ..., xn] == (...((z `f` x1) `f` x2) `f`...) `f` xn------ The list must be finite.---- We write foldl as a non-recursive thing, so that it--- can be inlined, and then (often) strictness-analysed,--- and hence the classic space leak on foldl (+) 0 xs--foldl        :: (b -> a -> b) -> b -> [a] -> b-foldl f z0 xs0 = lgo z0 xs0-             where-                lgo z []     =  z-                lgo z (x:xs) = lgo (f z x) xs---- | 'scanl' is similar to 'foldl', but returns a list of successive--- reduced values from the left:------ > scanl f z [x1, x2, ...] == [z, z `f` x1, (z `f` x1) `f` x2, ...]------ Note that------ > last (scanl f z xs) == foldl f z xs.--scanl                   :: (b -> a -> b) -> b -> [a] -> [b]-scanl f q ls            =  q : (case ls of-                                []   -> []-                                x:xs -> scanl f (f q x) xs)---- | 'scanl1' is a variant of 'scanl' that has no starting value argument:------ > scanl1 f [x1, x2, ...] == [x1, x1 `f` x2, ...]--scanl1                  :: (a -> a -> a) -> [a] -> [a]-scanl1 f (x:xs)         =  scanl f x xs-scanl1 _ []             =  []---- foldr, foldr1, scanr, and scanr1 are the right-to-left duals of the--- above functions.---- | 'foldr1' is a variant of 'foldr' that has no starting value argument,--- and thus must be applied to non-empty lists.--foldr1                  :: (a -> a -> a) -> [a] -> a-foldr1 _ [x]            =  x-foldr1 f (x:xs)         =  f x (foldr1 f xs)-foldr1 _ []             =  errorEmptyList "foldr1"---- | 'scanr' is the right-to-left dual of 'scanl'.--- Note that------ > head (scanr f z xs) == foldr f z xs.--scanr                   :: (a -> b -> b) -> b -> [a] -> [b]-scanr _ q0 []           =  [q0]-scanr f q0 (x:xs)       =  f x q : qs-                           where qs@(q:_) = scanr f q0 xs---- | 'scanr1' is a variant of 'scanr' that has no starting value argument.--scanr1                  :: (a -> a -> a) -> [a] -> [a]-scanr1 _ []             =  []-scanr1 _ [x]            =  [x]-scanr1 f (x:xs)         =  f x q : qs-                           where qs@(q:_) = scanr1 f xs---- | 'iterate' @f x@ returns an infinite list of repeated applications--- of @f@ to @x@:------ > iterate f x == [x, f x, f (f x), ...]--{-# NOINLINE [1] iterate #-}-iterate :: (a -> a) -> a -> [a]-iterate f x =  x : iterate f (f x)--{-# NOINLINE [0] iterateFB #-}-iterateFB :: (a -> b -> b) -> (a -> a) -> a -> b-iterateFB c f x = x `c` iterateFB c f (f x)--{-# RULES-"iterate"    [~1] forall f x.   iterate f x = build (\c _n -> iterateFB c f x)-"iterateFB"  [1]                iterateFB (:) = iterate- #-}----- | 'repeat' @x@ is an infinite list, with @x@ the value of every element.-repeat :: a -> [a]-{-# INLINE [0] repeat #-}--- The pragma just gives the rules more chance to fire-repeat x = xs where xs = x : xs--{-# INLINE [0] repeatFB #-}     -- ditto-repeatFB :: (a -> b -> b) -> a -> b-repeatFB c x = xs where xs = x `c` xs---{-# RULES-"repeat"    [~1] forall x. repeat x = build (\c _n -> repeatFB c x)-"repeatFB"  [1]  repeatFB (:)       = repeat- #-}---- | 'replicate' @n x@ is a list of length @n@ with @x@ the value of--- every element.--- It is an instance of the more general 'Data.List.genericReplicate',--- in which @n@ may be of any integral type.-{-# INLINE replicate #-}-replicate               :: Int -> a -> [a]-replicate n x           =  take n (repeat x)---- | 'cycle' ties a finite list into a circular one, or equivalently,--- the infinite repetition of the original list.  It is the identity--- on infinite lists.--cycle                   :: [a] -> [a]-cycle []                = error "Prelude.cycle: empty list"-cycle xs                = xs' where xs' = xs ++ xs'---- | 'takeWhile', applied to a predicate @p@ and a list @xs@, returns the--- longest prefix (possibly empty) of @xs@ of elements that satisfy @p@:------ > takeWhile (< 3) [1,2,3,4,1,2,3,4] == [1,2]--- > takeWhile (< 9) [1,2,3] == [1,2,3]--- > takeWhile (< 0) [1,2,3] == []-----takeWhile               :: (a -> Bool) -> [a] -> [a]-takeWhile _ []          =  []-takeWhile p (x:xs)-            | p x       =  x : takeWhile p xs-            | otherwise =  []---- | 'dropWhile' @p xs@ returns the suffix remaining after 'takeWhile' @p xs@:------ > dropWhile (< 3) [1,2,3,4,5,1,2,3] == [3,4,5,1,2,3]--- > dropWhile (< 9) [1,2,3] == []--- > dropWhile (< 0) [1,2,3] == [1,2,3]-----dropWhile               :: (a -> Bool) -> [a] -> [a]-dropWhile _ []          =  []-dropWhile p xs@(x:xs')-            | p x       =  dropWhile p xs'-            | otherwise =  xs---- | 'take' @n@, applied to a list @xs@, returns the prefix of @xs@--- of length @n@, or @xs@ itself if @n > 'length' xs@:------ > take 5 "Hello World!" == "Hello"--- > take 3 [1,2,3,4,5] == [1,2,3]--- > take 3 [1,2] == [1,2]--- > take 3 [] == []--- > take (-1) [1,2] == []--- > take 0 [1,2] == []------ It is an instance of the more general 'Data.List.genericTake',--- in which @n@ may be of any integral type.-take                   :: Int -> [a] -> [a]---- | 'drop' @n xs@ returns the suffix of @xs@--- after the first @n@ elements, or @[]@ if @n > 'length' xs@:------ > drop 6 "Hello World!" == "World!"--- > drop 3 [1,2,3,4,5] == [4,5]--- > drop 3 [1,2] == []--- > drop 3 [] == []--- > drop (-1) [1,2] == [1,2]--- > drop 0 [1,2] == [1,2]------ It is an instance of the more general 'Data.List.genericDrop',--- in which @n@ may be of any integral type.-drop                   :: Int -> [a] -> [a]---- | 'splitAt' @n xs@ returns a tuple where first element is @xs@ prefix of--- length @n@ and second element is the remainder of the list:------ > splitAt 6 "Hello World!" == ("Hello ","World!")--- > splitAt 3 [1,2,3,4,5] == ([1,2,3],[4,5])--- > splitAt 1 [1,2,3] == ([1],[2,3])--- > splitAt 3 [1,2,3] == ([1,2,3],[])--- > splitAt 4 [1,2,3] == ([1,2,3],[])--- > splitAt 0 [1,2,3] == ([],[1,2,3])--- > splitAt (-1) [1,2,3] == ([],[1,2,3])------ It is equivalent to @('take' n xs, 'drop' n xs)@ when @n@ is not @_|_@--- (@splitAt _|_ xs = _|_@).--- 'splitAt' is an instance of the more general 'Data.List.genericSplitAt',--- in which @n@ may be of any integral type.-splitAt                :: Int -> [a] -> ([a],[a])--#ifdef USE_REPORT_PRELUDE-take n _      | n <= 0 =  []-take _ []              =  []-take n (x:xs)          =  x : take (n-1) xs--drop n xs     | n <= 0 =  xs-drop _ []              =  []-drop n (_:xs)          =  drop (n-1) xs--splitAt n xs           =  (take n xs, drop n xs)--#else /* hack away */-{-# RULES-"take"     [~1] forall n xs . take n xs = takeFoldr n xs-"takeList"  [1] forall n xs . foldr (takeFB (:) []) (takeConst []) xs n = takeUInt n xs- #-}--{-# INLINE takeFoldr #-}-takeFoldr :: Int -> [a] -> [a]-takeFoldr (I# n#) xs-  = build (\c nil -> if isTrue# (n# <=# 0#) then nil else-                     foldr (takeFB c nil) (takeConst nil) xs n#)--{-# NOINLINE [0] takeConst #-}--- just a version of const that doesn't get inlined too early, so we--- can spot it in rules.  Also we need a type sig due to the unboxed Int#.-takeConst :: a -> Int# -> a-takeConst x _ = x--{-# NOINLINE [0] takeFB #-}-takeFB :: (a -> b -> b) -> b -> a -> (Int# -> b) -> Int# -> b-takeFB c n x xs m | isTrue# (m <=# 1#) = x `c` n-                  | otherwise          = x `c` xs (m -# 1#)--{-# INLINE [0] take #-}-take (I# n#) xs = takeUInt n# xs---- The general code for take, below, checks n <= maxInt--- No need to check for maxInt overflow when specialised--- at type Int or Int# since the Int must be <= maxInt--takeUInt :: Int# -> [b] -> [b]-takeUInt n xs-  | isTrue# (n >=# 0#) = take_unsafe_UInt n xs-  | otherwise          = []--take_unsafe_UInt :: Int# -> [b] -> [b]-take_unsafe_UInt 0#  _  = []-take_unsafe_UInt m   ls =-  case ls of-    []     -> []-    (x:xs) -> x : take_unsafe_UInt (m -# 1#) xs--takeUInt_append :: Int# -> [b] -> [b] -> [b]-takeUInt_append n xs rs-  | isTrue# (n >=# 0#) = take_unsafe_UInt_append n xs rs-  | otherwise          = []--take_unsafe_UInt_append :: Int# -> [b] -> [b] -> [b]-take_unsafe_UInt_append 0#  _ rs  = rs-take_unsafe_UInt_append m  ls rs  =-  case ls of-    []     -> rs-    (x:xs) -> x : take_unsafe_UInt_append (m -# 1#) xs rs--drop (I# n#) ls-  | isTrue# (n# <# 0#) = ls-  | otherwise          = drop# n# ls-    where-        drop# :: Int# -> [a] -> [a]-        drop# 0# xs      = xs-        drop# _  xs@[]   = xs-        drop# m# (_:xs)  = drop# (m# -# 1#) xs--splitAt (I# n#) ls-  | isTrue# (n# <# 0#) = ([], ls)-  | otherwise          = splitAt# n# ls-    where-        splitAt# :: Int# -> [a] -> ([a], [a])-        splitAt# 0# xs     = ([], xs)-        splitAt# _  xs@[]  = (xs, xs)-        splitAt# m# (x:xs) = (x:xs', xs'')-          where-            (xs', xs'') = splitAt# (m# -# 1#) xs--#endif /* USE_REPORT_PRELUDE */---- | 'span', applied to a predicate @p@ and a list @xs@, returns a tuple where--- first element is longest prefix (possibly empty) of @xs@ of elements that--- satisfy @p@ and second element is the remainder of the list:------ > span (< 3) [1,2,3,4,1,2,3,4] == ([1,2],[3,4,1,2,3,4])--- > span (< 9) [1,2,3] == ([1,2,3],[])--- > span (< 0) [1,2,3] == ([],[1,2,3])------ 'span' @p xs@ is equivalent to @('takeWhile' p xs, 'dropWhile' p xs)@--span                    :: (a -> Bool) -> [a] -> ([a],[a])-span _ xs@[]            =  (xs, xs)-span p xs@(x:xs')-         | p x          =  let (ys,zs) = span p xs' in (x:ys,zs)-         | otherwise    =  ([],xs)---- | 'break', applied to a predicate @p@ and a list @xs@, returns a tuple where--- first element is longest prefix (possibly empty) of @xs@ of elements that--- /do not satisfy/ @p@ and second element is the remainder of the list:------ > break (> 3) [1,2,3,4,1,2,3,4] == ([1,2,3],[4,1,2,3,4])--- > break (< 9) [1,2,3] == ([],[1,2,3])--- > break (> 9) [1,2,3] == ([1,2,3],[])------ 'break' @p@ is equivalent to @'span' ('not' . p)@.--break                   :: (a -> Bool) -> [a] -> ([a],[a])-#ifdef USE_REPORT_PRELUDE-break p                 =  span (not . p)-#else--- HBC version (stolen)-break _ xs@[]           =  (xs, xs)-break p xs@(x:xs')-           | p x        =  ([],xs)-           | otherwise  =  let (ys,zs) = break p xs' in (x:ys,zs)-#endif---- | 'reverse' @xs@ returns the elements of @xs@ in reverse order.--- @xs@ must be finite.-reverse                 :: [a] -> [a]-#ifdef USE_REPORT_PRELUDE-reverse                 =  foldl (flip (:)) []-#else-reverse l =  rev l []-  where-    rev []     a = a-    rev (x:xs) a = rev xs (x:a)-#endif---- | 'and' returns the conjunction of a Boolean list.  For the result to be--- 'True', the list must be finite; 'False', however, results from a 'False'--- value at a finite index of a finite or infinite list.-and                     :: [Bool] -> Bool---- | 'or' returns the disjunction of a Boolean list.  For the result to be--- 'False', the list must be finite; 'True', however, results from a 'True'--- value at a finite index of a finite or infinite list.-or                      :: [Bool] -> Bool-#ifdef USE_REPORT_PRELUDE-and                     =  foldr (&&) True-or                      =  foldr (||) False-#else-and []          =  True-and (x:xs)      =  x && and xs-or []           =  False-or (x:xs)       =  x || or xs--{-# NOINLINE [1] and #-}-{-# NOINLINE [1] or #-}--{-# RULES-"and/build"     forall (g::forall b.(Bool->b->b)->b->b) .-                and (build g) = g (&&) True-"or/build"      forall (g::forall b.(Bool->b->b)->b->b) .-                or (build g) = g (||) False- #-}-#endif---- | Applied to a predicate and a list, 'any' determines if any element--- of the list satisfies the predicate.  For the result to be--- 'False', the list must be finite; 'True', however, results from a 'True'--- value for the predicate applied to an element at a finite index of a finite or infinite list.-any                     :: (a -> Bool) -> [a] -> Bool---- | Applied to a predicate and a list, 'all' determines if all elements--- of the list satisfy the predicate. For the result to be--- 'True', the list must be finite; 'False', however, results from a 'False'--- value for the predicate applied to an element at a finite index of a finite or infinite list.-all                     :: (a -> Bool) -> [a] -> Bool-#ifdef USE_REPORT_PRELUDE-any p                   =  or . map p-all p                   =  and . map p-#else-any _ []        = False-any p (x:xs)    = p x || any p xs--all _ []        =  True-all p (x:xs)    =  p x && all p xs--{-# NOINLINE [1] any #-}-{-# NOINLINE [1] all #-}--{-# RULES-"any/build"     forall p (g::forall b.(a->b->b)->b->b) .-                any p (build g) = g ((||) . p) False-"all/build"     forall p (g::forall b.(a->b->b)->b->b) .-                all p (build g) = g ((&&) . p) True- #-}-#endif---- | 'elem' is the list membership predicate, usually written in infix form,--- e.g., @x \`elem\` xs@.  For the result to be--- 'False', the list must be finite; 'True', however, results from an element equal to @x@ found at a finite index of a finite or infinite list.-elem                    :: (Eq a) => a -> [a] -> Bool---- | 'notElem' is the negation of 'elem'.-notElem                 :: (Eq a) => a -> [a] -> Bool-#ifdef USE_REPORT_PRELUDE-elem x                  =  any (== x)-notElem x               =  all (/= x)-#else-elem _ []       = False-elem x (y:ys)   = x==y || elem x ys--notElem _ []    =  True-notElem x (y:ys)=  x /= y && notElem x ys-#endif---- | 'lookup' @key assocs@ looks up a key in an association list.-lookup                  :: (Eq a) => a -> [(a,b)] -> Maybe b-lookup _key []          =  Nothing-lookup  key ((x,y):xys)-    | key == x          =  Just y-    | otherwise         =  lookup key xys---- | Map a function over a list and concatenate the results.-concatMap               :: (a -> [b]) -> [a] -> [b]-concatMap f             =  foldr ((++) . f) []---- | Concatenate a list of lists.-concat :: [[a]] -> [a]-concat = foldr (++) []--{-# NOINLINE [1] concat #-}--{-# RULES-  "concat" forall xs. concat xs = build (\c n -> foldr (\x y -> foldr c y x) n xs)--- We don't bother to turn non-fusible applications of concat back into concat- #-}--\end{code}---\begin{code}--- | List index (subscript) operator, starting from 0.--- It is an instance of the more general 'Data.List.genericIndex',--- which takes an index of any integral type.-(!!)                    :: [a] -> Int -> a-#ifdef USE_REPORT_PRELUDE-xs     !! n | n < 0 =  error "Prelude.!!: negative index"-[]     !! _         =  error "Prelude.!!: index too large"-(x:_)  !! 0         =  x-(_:xs) !! n         =  xs !! (n-1)-#else--- HBC version (stolen), then unboxified--- The semantics is not quite the same for error conditions--- in the more efficient version.----xs !! (I# n0) | isTrue# (n0 <# 0#) =  error "Prelude.(!!): negative index\n"-              | otherwise          =  sub xs n0-                         where-                            sub :: [a] -> Int# -> a-                            sub []     _ = error "Prelude.(!!): index too large\n"-                            sub (y:ys) n = if isTrue# (n ==# 0#)-                                           then y-                                           else sub ys (n -# 1#)-#endif-\end{code}---%*********************************************************-%*                                                      *-\subsection{The zip family}-%*                                                      *-%*********************************************************--\begin{code}-foldr2 :: (a -> b -> c -> c) -> c -> [a] -> [b] -> c-foldr2 k z = go-  where-	go []    _ys     = z-	go _xs   []      = z-	go (x:xs) (y:ys) = k x y (go xs ys)-{-# INLINE [0] foldr2 #-}--foldr2_left :: (a -> b -> c -> d) -> d -> a -> ([b] -> c) -> [b] -> d-foldr2_left _k  z _x _r []     = z-foldr2_left  k _z  x  r (y:ys) = k x y (r ys)--foldr2_right :: (a -> b -> c -> d) -> d -> b -> ([a] -> c) -> [a] -> d-foldr2_right _k z  _y _r []     = z-foldr2_right  k _z  y  r (x:xs) = k x y (r xs)---- foldr2 k z xs ys = foldr (foldr2_left k z)  (\_ -> z) xs ys--- foldr2 k z xs ys = foldr (foldr2_right k z) (\_ -> z) ys xs-{-# RULES-"foldr2/left"   forall k z ys (g::forall b.(a->b->b)->b->b) .-                  foldr2 k z (build g) ys = g (foldr2_left  k z) (\_ -> z) ys--"foldr2/right"  forall k z xs (g::forall b.(a->b->b)->b->b) .-                  foldr2 k z xs (build g) = g (foldr2_right k z) (\_ -> z) xs- #-}-\end{code}--The foldr2/right rule isn't exactly right, because it changes-the strictness of foldr2 (and thereby zip)--E.g. main = print (null (zip nonobviousNil (build undefined)))-          where   nonobviousNil = f 3-                  f n = if n == 0 then [] else f (n-1)--I'm going to leave it though.---Zips for larger tuples are in the List module.--\begin{code}-------------------------------------------------- | 'zip' takes two lists and returns a list of corresponding pairs.--- If one input list is short, excess elements of the longer list are--- discarded.-{-# NOINLINE [1] zip #-}-zip :: [a] -> [b] -> [(a,b)]-zip (a:as) (b:bs) = (a,b) : zip as bs-zip _      _      = []--{-# INLINE [0] zipFB #-}-zipFB :: ((a, b) -> c -> d) -> a -> b -> c -> d-zipFB c = \x y r -> (x,y) `c` r--{-# RULES-"zip"      [~1] forall xs ys. zip xs ys = build (\c n -> foldr2 (zipFB c) n xs ys)-"zipList"  [1]  foldr2 (zipFB (:)) []   = zip- #-}-\end{code}--\begin{code}-------------------------------------------------- | 'zip3' takes three lists and returns a list of triples, analogous to--- 'zip'.-zip3 :: [a] -> [b] -> [c] -> [(a,b,c)]--- Specification--- zip3 =  zipWith3 (,,)-zip3 (a:as) (b:bs) (c:cs) = (a,b,c) : zip3 as bs cs-zip3 _      _      _      = []-\end{code}----- The zipWith family generalises the zip family by zipping with the--- function given as the first argument, instead of a tupling function.--\begin{code}-------------------------------------------------- | 'zipWith' generalises 'zip' by zipping with the function given--- as the first argument, instead of a tupling function.--- For example, @'zipWith' (+)@ is applied to two lists to produce the--- list of corresponding sums.-{-# NOINLINE [1] zipWith #-}-zipWith :: (a->b->c) -> [a]->[b]->[c]-zipWith f (a:as) (b:bs) = f a b : zipWith f as bs-zipWith _ _      _      = []---- zipWithFB must have arity 2 since it gets two arguments in the "zipWith"--- rule; it might not get inlined otherwise-{-# INLINE [0] zipWithFB #-}-zipWithFB :: (a -> b -> c) -> (d -> e -> a) -> d -> e -> b -> c-zipWithFB c f = \x y r -> (x `f` y) `c` r--{-# RULES-"zipWith"       [~1] forall f xs ys.    zipWith f xs ys = build (\c n -> foldr2 (zipWithFB c f) n xs ys)-"zipWithList"   [1]  forall f.  foldr2 (zipWithFB (:) f) [] = zipWith f-  #-}-\end{code}--\begin{code}--- | The 'zipWith3' function takes a function which combines three--- elements, as well as three lists and returns a list of their point-wise--- combination, analogous to 'zipWith'.-zipWith3                :: (a->b->c->d) -> [a]->[b]->[c]->[d]-zipWith3 z (a:as) (b:bs) (c:cs)-                        =  z a b c : zipWith3 z as bs cs-zipWith3 _ _ _ _        =  []---- | 'unzip' transforms a list of pairs into a list of first components--- and a list of second components.-unzip    :: [(a,b)] -> ([a],[b])-{-# INLINE unzip #-}-unzip    =  foldr (\(a,b) ~(as,bs) -> (a:as,b:bs)) ([],[])---- | The 'unzip3' function takes a list of triples and returns three--- lists, analogous to 'unzip'.-unzip3   :: [(a,b,c)] -> ([a],[b],[c])-{-# INLINE unzip3 #-}-unzip3   =  foldr (\(a,b,c) ~(as,bs,cs) -> (a:as,b:bs,c:cs))-                  ([],[],[])-\end{code}---%*********************************************************-%*                                                      *-\subsection{Error code}-%*                                                      *-%*********************************************************--Common up near identical calls to `error' to reduce the number-constant strings created when compiled:--\begin{code}-errorEmptyList :: String -> a-errorEmptyList fun =-  error (prel_list_str ++ fun ++ ": empty list")--prel_list_str :: String-prel_list_str = "Prelude."-\end{code}
GHC/MVar.hs view
@@ -1,5 +1,5 @@-{-# LANGUAGE Unsafe, DeriveDataTypeable #-}-{-# LANGUAGE NoImplicitPrelude, MagicHash, UnboxedTuples #-}+{-# LANGUAGE Unsafe #-}+{-# LANGUAGE NoImplicitPrelude, MagicHash, UnboxedTuples, AutoDeriveTypeable #-} {-# OPTIONS_GHC -funbox-strict-fields #-} {-# OPTIONS_HADDOCK hide #-} @@ -33,7 +33,6 @@     ) where  import GHC.Base-import Data.Maybe import Data.Typeable  data MVar a = MVar (MVar# RealWorld a) deriving( Typeable )@@ -157,7 +156,7 @@ -- returns immediately, with 'Nothing' if the 'MVar' was empty, or -- @'Just' a@ if the 'MVar' was full with contents @a@. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 tryReadMVar :: MVar a -> IO (Maybe a) tryReadMVar (MVar m) = IO $ \ s ->     case tryReadMVar# m s of
+ GHC/Natural.hs view
@@ -0,0 +1,644 @@+{-# LANGUAGE AutoDeriveTypeable #-}+{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE CPP #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE MagicHash #-}+{-# LANGUAGE NoImplicitPrelude #-}+{-# LANGUAGE UnboxedTuples #-}+{-# LANGUAGE Unsafe #-}++{-# OPTIONS_HADDOCK not-home #-}++-----------------------------------------------------------------------------+-- |+-- Module      :  GHC.Natural+-- Copyright   :  (C) 2014 Herbert Valerio Riedel,+--                (C) 2011 Edward Kmett+-- License     :  see libraries/base/LICENSE+--+-- Maintainer  :  libraries@haskell.org+-- Stability   :  internal+-- Portability :  non-portable (GHC Extensions)+--+-- The arbitrary-precision 'Natural' number type.+--+-- __Note__: This is an internal GHC module with an API subject to+-- change.  It's recommended use the "Numeric.Natural" module to import+-- the 'Natural' type.+--+-- @since 4.8.0.0+-----------------------------------------------------------------------------+module GHC.Natural+    ( -- * The 'Natural' number type+      --+      -- | __Warning__: The internal implementation of 'Natural'+      -- (i.e. which constructors are available) depends on the+      -- 'Integer' backend used!+      Natural(..)+    , isValidNatural+      -- * Conversions+    , wordToNatural+    , naturalToWordMaybe+      -- * Checked subtraction+    , minusNaturalMaybe+      -- * Modular arithmetic+    , powModNatural+    ) where++#include "MachDeps.h"++#if defined(MIN_VERSION_integer_gmp)+# define HAVE_GMP_BIGNAT MIN_VERSION_integer_gmp(1,0,0)+#else+# define HAVE_GMP_BIGNAT 0+#endif++import GHC.Arr+import GHC.Base+import GHC.Exception+#if HAVE_GMP_BIGNAT+import GHC.Integer.GMP.Internals+import Data.Word+import Data.Int+#endif+import GHC.Num+import GHC.Real+import GHC.Read+import GHC.Show+import GHC.Enum+import GHC.List++import Data.Bits+import Data.Data++default ()++#if HAVE_GMP_BIGNAT+-- TODO: if saturated arithmetic is to used, replace 'throw Underflow' by '0'++-- | Type representing arbitrary-precision non-negative integers.+--+-- Operations whose result would be negative+-- @'throw' ('Underflow' :: 'ArithException')@.+--+-- @since 4.8.0.0+data Natural = NatS#                 GmpLimb# -- ^ in @[0, maxBound::Word]@+             | NatJ# {-# UNPACK #-} !BigNat   -- ^ in @]maxBound::Word, +inf[@+                                              --+                                              -- __Invariant__: 'NatJ#' is used+                                              -- /iff/ value doesn't fit in+                                              -- 'NatS#' constructor.+             deriving (Eq,Ord) -- NB: Order of constructors *must*+                               -- coincide with 'Ord' relation++-- | Test whether all internal invariants are satisfied by 'Natural' value+--+-- This operation is mostly useful for test-suites and/or code which+-- constructs 'Integer' values directly.+--+-- @since 4.8.0.0+isValidNatural :: Natural -> Bool+isValidNatural (NatS# _)  = True+isValidNatural (NatJ# bn) = isTrue# (isValidBigNat# bn)+                            && I# (sizeofBigNat# bn) > 0++{-# RULES+"fromIntegral/Natural->Natural"  fromIntegral = id :: Natural -> Natural+"fromIntegral/Natural->Integer"  fromIntegral = toInteger :: Natural->Integer+"fromIntegral/Natural->Word"     fromIntegral = naturalToWord+"fromIntegral/Natural->Word8"+    fromIntegral = (fromIntegral :: Word -> Word8)  . naturalToWord+"fromIntegral/Natural->Word16"+    fromIntegral = (fromIntegral :: Word -> Word16) . naturalToWord+"fromIntegral/Natural->Word32"+    fromIntegral = (fromIntegral :: Word -> Word32) . naturalToWord+"fromIntegral/Natural->Int8"+    fromIntegral = (fromIntegral :: Int -> Int8)    . naturalToInt+"fromIntegral/Natural->Int16"+    fromIntegral = (fromIntegral :: Int -> Int16)   . naturalToInt+"fromIntegral/Natural->Int32"+    fromIntegral = (fromIntegral :: Int -> Int32)   . naturalToInt+  #-}++{-# RULES+"fromIntegral/Word->Natural"     fromIntegral = wordToNatural+"fromIntegral/Word8->Natural"+    fromIntegral = wordToNatural . (fromIntegral :: Word8  -> Word)+"fromIntegral/Word16->Natural"+    fromIntegral = wordToNatural . (fromIntegral :: Word16 -> Word)+"fromIntegral/Word32->Natural"+    fromIntegral = wordToNatural . (fromIntegral :: Word32 -> Word)+"fromIntegral/Int->Natural"     fromIntegral = intToNatural+"fromIntegral/Int8->Natural"+    fromIntegral = intToNatural  . (fromIntegral :: Int8  -> Int)+"fromIntegral/Int16->Natural"+    fromIntegral = intToNatural  . (fromIntegral :: Int16 -> Int)+"fromIntegral/Int32->Natural"+    fromIntegral = intToNatural  . (fromIntegral :: Int32 -> Int)+  #-}++#if WORD_SIZE_IN_BITS == 64+-- these RULES are valid for Word==Word64 & Int==Int64+{-# RULES+"fromIntegral/Natural->Word64"+    fromIntegral = (fromIntegral :: Word -> Word64) . naturalToWord+"fromIntegral/Natural->Int64"+    fromIntegral = (fromIntegral :: Int -> Int64) . naturalToInt+"fromIntegral/Word64->Natural"+    fromIntegral = wordToNatural . (fromIntegral :: Word64 -> Word)+"fromIntegral/Int64->Natural"+    fromIntegral = intToNatural . (fromIntegral :: Int64 -> Int)+  #-}+#endif++instance Show Natural where+    showsPrec p (NatS# w#)  = showsPrec p (W# w#)+    showsPrec p (NatJ# bn)  = showsPrec p (Jp# bn)++instance Read Natural where+    readsPrec d = map (\(n, s) -> (fromInteger n, s))+                  . filter ((>= 0) . (\(x,_)->x)) . readsPrec d++instance Num Natural where+    fromInteger (S# i#) | I# i# >= 0  = NatS# (int2Word# i#)+    fromInteger (Jp# bn)              = bigNatToNatural bn+    fromInteger _                     = throw Underflow++    (+) = plusNatural+    (*) = timesNatural+    (-) = minusNatural++    abs                  = id++    signum (NatS# 0##)   = NatS# 0##+    signum _             = NatS# 1##++    negate (NatS# 0##)   = NatS# 0##+    negate _             = throw Underflow++instance Real Natural where+    toRational (NatS# w)  = toRational (W# w)+    toRational (NatJ# bn) = toRational (Jp# bn)++#if OPTIMISE_INTEGER_GCD_LCM+{-# RULES+"gcd/Natural->Natural->Natural" gcd = gcdNatural+"lcm/Natural->Natural->Natural" lcm = lcmNatural+  #-}++-- | Compute greatest common divisor.+gcdNatural :: Natural -> Natural -> Natural+gcdNatural (NatS# 0##) y       = y+gcdNatural x       (NatS# 0##) = x+gcdNatural (NatS# 1##) _       = (NatS# 1##)+gcdNatural _       (NatS# 1##) = (NatS# 1##)+gcdNatural (NatJ# x) (NatJ# y) = bigNatToNatural (gcdBigNat x y)+gcdNatural (NatJ# x) (NatS# y) = NatS# (gcdBigNatWord x y)+gcdNatural (NatS# x) (NatJ# y) = NatS# (gcdBigNatWord y x)+gcdNatural (NatS# x) (NatS# y) = NatS# (gcdWord x y)++-- | compute least common multiplier.+lcmNatural :: Natural -> Natural -> Natural+lcmNatural (NatS# 0##) _ = (NatS# 0##)+lcmNatural _ (NatS# 0##) = (NatS# 0##)+lcmNatural (NatS# 1##) y = y+lcmNatural x (NatS# 1##) = x+lcmNatural x y           = (x `quot` (gcdNatural x y)) * y++#endif++instance Enum Natural where+    succ n = n `plusNatural`  NatS# 1##+    pred n = n `minusNatural` NatS# 1##++    toEnum = intToNatural++    fromEnum (NatS# w) | i >= 0 = i+      where+        i = fromIntegral (W# w)+    fromEnum _ = error "fromEnum: out of Int range"++    enumFrom x        = enumDeltaNatural      x (NatS# 1##)+    enumFromThen x y+      | x <= y        = enumDeltaNatural      x (y-x)+      | otherwise     = enumNegDeltaToNatural x (x-y) (NatS# 0##)++    enumFromTo x lim  = enumDeltaToNatural    x (NatS# 1##) lim+    enumFromThenTo x y lim+      | x <= y        = enumDeltaToNatural    x (y-x) lim+      | otherwise     = enumNegDeltaToNatural x (x-y) lim++----------------------------------------------------------------------------+-- Helpers for 'Enum Natural'; TODO: optimise & make fusion work++enumDeltaNatural :: Natural -> Natural -> [Natural]+enumDeltaNatural !x d = x : enumDeltaNatural (x+d) d++enumDeltaToNatural :: Natural -> Natural -> Natural -> [Natural]+enumDeltaToNatural x0 delta lim = go x0+  where+    go x | x > lim   = []+         | otherwise = x : go (x+delta)++enumNegDeltaToNatural :: Natural -> Natural -> Natural -> [Natural]+enumNegDeltaToNatural x0 ndelta lim = go x0+  where+    go x | x < lim     = []+         | x >= ndelta = x : go (x-ndelta)+         | otherwise   = [x]++----------------------------------------------------------------------------++instance Integral Natural where+    toInteger (NatS# w)  = wordToInteger w+    toInteger (NatJ# bn) = Jp# bn++    divMod = quotRem+    div    = quot+    mod    = rem++    quotRem _ (NatS# 0##) = throw DivideByZero+    quotRem n (NatS# 1##) = (n,NatS# 0##)+    quotRem n@(NatS# _) (NatJ# _) = (NatS# 0##, n)+    quotRem (NatS# n) (NatS# d) = case quotRem (W# n) (W# d) of+        (q,r) -> (wordToNatural q, wordToNatural r)+    quotRem (NatJ# n) (NatS# d) = case quotRemBigNatWord n d of+        (# q,r #) -> (bigNatToNatural q, NatS# r)+    quotRem (NatJ# n) (NatJ# d) = case quotRemBigNat n d of+        (# q,r #) -> (bigNatToNatural q, bigNatToNatural r)++    quot _       (NatS# 0##) = throw DivideByZero+    quot n       (NatS# 1##) = n+    quot (NatS# _) (NatJ# _) = NatS# 0##+    quot (NatS# n) (NatS# d) = wordToNatural (quot (W# n) (W# d))+    quot (NatJ# n) (NatS# d) = bigNatToNatural (quotBigNatWord n d)+    quot (NatJ# n) (NatJ# d) = bigNatToNatural (quotBigNat n d)++    rem _         (NatS# 0##) = throw DivideByZero+    rem _         (NatS# 1##) = NatS# 0##+    rem n@(NatS# _) (NatJ# _) = n+    rem   (NatS# n) (NatS# d) = wordToNatural (rem (W# n) (W# d))+    rem   (NatJ# n) (NatS# d) = NatS# (remBigNatWord n d)+    rem   (NatJ# n) (NatJ# d) = bigNatToNatural (remBigNat n d)++instance Ix Natural where+    range (m,n) = [m..n]+    inRange (m,n) i = m <= i && i <= n+    unsafeIndex (m,_) i = fromIntegral (i-m)+    index b i | inRange b i = unsafeIndex b i+              | otherwise   = indexError b i "Natural"+++instance Bits Natural where+    NatS# n .&. NatS# m = wordToNatural (W# n .&. W# m)+    NatS# n .&. NatJ# m = wordToNatural (W# n .&. W# (bigNatToWord m))+    NatJ# n .&. NatS# m = wordToNatural (W# (bigNatToWord n) .&. W# m)+    NatJ# n .&. NatJ# m = bigNatToNatural (andBigNat n m)++    NatS# n .|. NatS# m = wordToNatural (W# n .|. W# m)+    NatS# n .|. NatJ# m = NatJ# (orBigNat (wordToBigNat n) m)+    NatJ# n .|. NatS# m = NatJ# (orBigNat n (wordToBigNat m))+    NatJ# n .|. NatJ# m = NatJ# (orBigNat n m)++    NatS# n `xor` NatS# m = wordToNatural (W# n `xor` W# m)+    NatS# n `xor` NatJ# m = NatJ# (xorBigNat (wordToBigNat n) m)+    NatJ# n `xor` NatS# m = NatJ# (xorBigNat n (wordToBigNat m))+    NatJ# n `xor` NatJ# m = bigNatToNatural (xorBigNat n m)++    complement _ = error "Bits.complement: Natural complement undefined"++    bitSizeMaybe _ = Nothing+    bitSize = error "Natural: bitSize"+    isSigned _ = False++    bit i@(I# i#) | i < finiteBitSize (0::Word) = wordToNatural (bit i)+                  | otherwise                   = NatJ# (bitBigNat i#)++    testBit (NatS# w) i = testBit (W# w) i+    testBit (NatJ# bn) (I# i#) = testBitBigNat bn i#++    -- TODO: setBit, clearBit, complementBit (needs more primitives)++    shiftL n           0 = n+    shiftL (NatS# 0##) _ = NatS# 0##+    shiftL (NatS# 1##) i = bit i+    shiftL (NatS# w) (I# i#)+        = bigNatToNatural $ shiftLBigNat (wordToBigNat w) i#+    shiftL (NatJ# bn) (I# i#)+        = bigNatToNatural $ shiftLBigNat bn i#++    shiftR n          0       = n+    shiftR (NatS# w)  i       = wordToNatural $ shiftR (W# w) i+    shiftR (NatJ# bn) (I# i#) = bigNatToNatural (shiftRBigNat bn i#)++    rotateL = shiftL+    rotateR = shiftR++    popCount (NatS# w)  = popCount (W# w)+    popCount (NatJ# bn) = I# (popCountBigNat bn)++    zeroBits = NatS# 0##++----------------------------------------------------------------------------++-- | 'Natural' Addition+plusNatural :: Natural -> Natural -> Natural+plusNatural (NatS# 0##) y         = y+plusNatural x         (NatS# 0##) = x+plusNatural (NatS# x) (NatS# y)+    = case plusWord2# x y of+       (# 0##, l #) -> NatS# l+       (# h,   l #) -> NatJ# (wordToBigNat2 h l)+plusNatural (NatS# x) (NatJ# y) = NatJ# (plusBigNatWord y x)+plusNatural (NatJ# x) (NatS# y) = NatJ# (plusBigNatWord x y)+plusNatural (NatJ# x) (NatJ# y) = NatJ# (plusBigNat     x y)++-- | 'Natural' multiplication+timesNatural :: Natural -> Natural -> Natural+timesNatural _         (NatS# 0##) = NatS# 0##+timesNatural (NatS# 0##) _         = NatS# 0##+timesNatural x         (NatS# 1##) = x+timesNatural (NatS# 1##) y         = y+timesNatural (NatS# x) (NatS# y) = case timesWord2# x y of+    (# 0##, 0## #) -> NatS# 0##+    (# 0##, xy  #) -> NatS# xy+    (# h  , l   #) -> NatJ# $ wordToBigNat2 h l+timesNatural (NatS# x) (NatJ# y) = NatJ# $ timesBigNatWord y x+timesNatural (NatJ# x) (NatS# y) = NatJ# $ timesBigNatWord x y+timesNatural (NatJ# x) (NatJ# y) = NatJ# $ timesBigNat     x y++-- | 'Natural' subtraction. May @'throw' 'Underflow'@.+minusNatural :: Natural -> Natural -> Natural+minusNatural x         (NatS# 0##) = x+minusNatural (NatS# x) (NatS# y) = case subWordC# x y of+    (# l, 0# #) -> NatS# l+    _           -> throw Underflow+minusNatural (NatS# _) (NatJ# _) = throw Underflow+minusNatural (NatJ# x) (NatS# y)+    = bigNatToNatural $ minusBigNatWord x y+minusNatural (NatJ# x) (NatJ# y)+    = bigNatToNatural $ minusBigNat     x y++-- | 'Natural' subtraction. Returns 'Nothing's for non-positive results.+--+-- @since 4.8.0.0+minusNaturalMaybe :: Natural -> Natural -> Maybe Natural+minusNaturalMaybe x         (NatS# 0##) = Just x+minusNaturalMaybe (NatS# x) (NatS# y) = case subWordC# x y of+    (# l, 0# #) -> Just (NatS# l)+    _           -> Nothing+  where+minusNaturalMaybe (NatS# _) (NatJ# _) = Nothing+minusNaturalMaybe (NatJ# x) (NatS# y)+    = Just $ bigNatToNatural $ minusBigNatWord x y+minusNaturalMaybe (NatJ# x) (NatJ# y)+  | isTrue# (isNullBigNat# res) = Nothing+  | otherwise = Just (bigNatToNatural res)+  where+    res = minusBigNat x y++-- | Helper for 'minusNatural' and 'minusNaturalMaybe'+subWordC# :: Word# -> Word# -> (# Word#, Int# #)+subWordC# x# y# = (# d#, c# #)+  where+    d# = x# `minusWord#` y#+    c# = d# `gtWord#` x#++-- | Convert 'BigNat' to 'Natural'.+-- Throws 'Underflow' if passed a 'nullBigNat'.+bigNatToNatural :: BigNat -> Natural+bigNatToNatural bn+  | isTrue# (sizeofBigNat# bn ==# 1#) = NatS# (bigNatToWord bn)+  | isTrue# (isNullBigNat# bn)        = throw Underflow+  | otherwise                         = NatJ# bn++naturalToBigNat :: Natural -> BigNat+naturalToBigNat (NatS# w#) = wordToBigNat w#+naturalToBigNat (NatJ# bn) = bn++-- | Convert 'Int' to 'Natural'.+-- Throws 'Underflow' when passed a negative 'Int'.+intToNatural :: Int -> Natural+intToNatural i | i<0 = throw Underflow+intToNatural (I# i#) = NatS# (int2Word# i#)++naturalToWord :: Natural -> Word+naturalToWord (NatS# w#) = W# w#+naturalToWord (NatJ# bn) = W# (bigNatToWord bn)++naturalToInt :: Natural -> Int+naturalToInt (NatS# w#) = I# (word2Int# w#)+naturalToInt (NatJ# bn) = I# (bigNatToInt bn)++#else /* !HAVE_GMP_BIGNAT */+----------------------------------------------------------------------------+-- Use wrapped 'Integer' as fallback; taken from Edward Kmett's nats package++-- | Type representing arbitrary-precision non-negative integers.+--+-- Operations whose result would be negative+-- @'throw' ('Underflow' :: 'ArithException')@.+--+-- @since 4.8.0.0+newtype Natural = Natural Integer -- ^ __Invariant__: non-negative 'Integer'+                deriving (Eq,Ord,Ix)++-- | Test whether all internal invariants are satisfied by 'Natural' value+--+-- This operation is mostly useful for test-suites and/or code which+-- constructs 'Integer' values directly.+--+-- @since 4.8.0.0+isValidNatural :: Natural -> Bool+isValidNatural (Natural i) = i >= 0++instance Read Natural where+    readsPrec d = map (\(n, s) -> (Natural n, s))+                  . filter ((>= 0) . (\(x,_)->x)) . readsPrec d++instance Show Natural where+    showsPrec d (Natural i) = showsPrec d i++instance Num Natural where+  Natural n + Natural m = Natural (n + m)+  {-# INLINE (+) #-}+  Natural n * Natural m = Natural (n * m)+  {-# INLINE (*) #-}+  Natural n - Natural m | result < 0 = throw Underflow+                        | otherwise  = Natural result+    where result = n - m+  {-# INLINE (-) #-}+  abs (Natural n) = Natural n+  {-# INLINE abs #-}+  signum (Natural n) = Natural (signum n)+  {-# INLINE signum #-}+  fromInteger n+    | n >= 0 = Natural n+    | otherwise = throw Underflow+  {-# INLINE fromInteger #-}++-- | 'Natural' subtraction. Returns 'Nothing's for non-positive results.+--+-- @since 4.8.0.0+minusNaturalMaybe :: Natural -> Natural -> Maybe Natural+minusNaturalMaybe x y+  | x >= y    = Just (x - y)+  | otherwise = Nothing++instance Bits Natural where+  Natural n .&. Natural m = Natural (n .&. m)+  {-# INLINE (.&.) #-}+  Natural n .|. Natural m = Natural (n .|. m)+  {-# INLINE (.|.) #-}+  xor (Natural n) (Natural m) = Natural (xor n m)+  {-# INLINE xor #-}+  complement _ = error "Bits.complement: Natural complement undefined"+  {-# INLINE complement #-}+  shift (Natural n) = Natural . shift n+  {-# INLINE shift #-}+  rotate (Natural n) = Natural . rotate n+  {-# INLINE rotate #-}+  bit = Natural . bit+  {-# INLINE bit #-}+  setBit (Natural n) = Natural . setBit n+  {-# INLINE setBit #-}+  clearBit (Natural n) = Natural . clearBit n+  {-# INLINE clearBit #-}+  complementBit (Natural n) = Natural . complementBit n+  {-# INLINE complementBit #-}+  testBit (Natural n) = testBit n+  {-# INLINE testBit #-}+  bitSizeMaybe _ = Nothing+  {-# INLINE bitSizeMaybe #-}+  bitSize = error "Natural: bitSize"+  {-# INLINE bitSize #-}+  isSigned _ = False+  {-# INLINE isSigned #-}+  shiftL (Natural n) = Natural . shiftL n+  {-# INLINE shiftL #-}+  shiftR (Natural n) = Natural . shiftR n+  {-# INLINE shiftR #-}+  rotateL (Natural n) = Natural . rotateL n+  {-# INLINE rotateL #-}+  rotateR (Natural n) = Natural . rotateR n+  {-# INLINE rotateR #-}+  popCount (Natural n) = popCount n+  {-# INLINE popCount #-}+  zeroBits = Natural 0++instance Real Natural where+  toRational (Natural a) = toRational a+  {-# INLINE toRational #-}++instance Enum Natural where+  pred (Natural 0) = error "Natural.pred: 0"+  pred (Natural n) = Natural (pred n)+  {-# INLINE pred #-}+  succ (Natural n) = Natural (succ n)+  {-# INLINE succ #-}+  fromEnum (Natural n) = fromEnum n+  {-# INLINE fromEnum #-}+  toEnum n | n < 0     = error "Natural.toEnum: negative"+           | otherwise = Natural (toEnum n)+  {-# INLINE toEnum #-}++  enumFrom     = coerce (enumFrom     :: Integer -> [Integer])+  enumFromThen x y+    | x <= y    = coerce (enumFromThen :: Integer -> Integer -> [Integer]) x y+    | otherwise = enumFromThenTo x y 0++  enumFromTo   = coerce (enumFromTo   :: Integer -> Integer -> [Integer])+  enumFromThenTo+    = coerce (enumFromThenTo :: Integer -> Integer -> Integer -> [Integer])++instance Integral Natural where+  quot (Natural a) (Natural b) = Natural (quot a b)+  {-# INLINE quot #-}+  rem (Natural a) (Natural b) = Natural (rem a b)+  {-# INLINE rem #-}+  div (Natural a) (Natural b) = Natural (div a b)+  {-# INLINE div #-}+  mod (Natural a) (Natural b) = Natural (mod a b)+  {-# INLINE mod #-}+  divMod (Natural a) (Natural b) = (Natural q, Natural r)+    where (q,r) = divMod a b+  {-# INLINE divMod #-}+  quotRem (Natural a) (Natural b) = (Natural q, Natural r)+    where (q,r) = quotRem a b+  {-# INLINE quotRem #-}+  toInteger (Natural a) = a+  {-# INLINE toInteger #-}+#endif++-- | Construct 'Natural' from 'Word' value.+--+-- @since 4.8.0.0+wordToNatural :: Word -> Natural+#if HAVE_GMP_BIGNAT+wordToNatural (W# w#) = NatS# w#+#else+wordToNatural w = Natural (fromIntegral w)+#endif++-- | Try downcasting 'Natural' to 'Word' value.+-- Returns 'Nothing' if value doesn't fit in 'Word'.+--+-- @since 4.8.0.0+naturalToWordMaybe :: Natural -> Maybe Word+#if HAVE_GMP_BIGNAT+naturalToWordMaybe (NatS# w#) = Just (W# w#)+naturalToWordMaybe (NatJ# _)  = Nothing+#else+naturalToWordMaybe (Natural i)+  | i <= maxw  = Just (fromIntegral i)+  | otherwise  = Nothing+  where+    maxw = toInteger (maxBound :: Word)+#endif++-- This follows the same style as the other integral 'Data' instances+-- defined in "Data.Data"+naturalType :: DataType+naturalType = mkIntType "Numeric.Natural.Natural"++instance Data Natural where+  toConstr x = mkIntegralConstr naturalType x+  gunfold _ z c = case constrRep c of+                    (IntConstr x) -> z (fromIntegral x)+                    _ -> error $ "Data.Data.gunfold: Constructor " ++ show c+                                 ++ " is not of type Natural"+  dataTypeOf _ = naturalType++-- | \"@'powModNatural' /b/ /e/ /m/@\" computes base @/b/@ raised to+-- exponent @/e/@ modulo @/m/@.+--+-- @since 4.8.0.0+powModNatural :: Natural -> Natural -> Natural -> Natural+#if HAVE_GMP_BIGNAT+powModNatural _           _           (NatS# 0##) = throw DivideByZero+powModNatural _           _           (NatS# 1##) = NatS# 0##+powModNatural _           (NatS# 0##) _           = NatS# 1##+powModNatural (NatS# 0##) _           _           = NatS# 0##+powModNatural (NatS# 1##) _           _           = NatS# 1##+powModNatural (NatS# b)   (NatS# e)   (NatS# m)   = NatS# (powModWord b e m)+powModNatural b           e           (NatS# m)+  = NatS# (powModBigNatWord (naturalToBigNat b) (naturalToBigNat e) m)+powModNatural b           e           (NatJ# m)+  = bigNatToNatural (powModBigNat (naturalToBigNat b) (naturalToBigNat e) m)+#else+-- Portable reference fallback implementation+powModNatural _ _ 0 = throw DivideByZero+powModNatural _ _ 1 = 0+powModNatural _ 0 _ = 1+powModNatural 0 _ _ = 0+powModNatural 1 _ _ = 1+powModNatural b0 e0 m = go b0 e0 1+  where+    go !b e !r+      | odd e     = go b' e' (r*b `mod` m)+      | e == 0    = r+      | otherwise = go b' e' r+      where+        b' = b*b `mod` m+        e' = e   `unsafeShiftR` 1 -- slightly faster than "e `div` 2"+#endif
+ GHC/Num.hs view
@@ -0,0 +1,99 @@+{-# LANGUAGE Trustworthy #-}+{-# LANGUAGE NoImplicitPrelude, MagicHash, UnboxedTuples #-}+{-# OPTIONS_HADDOCK hide #-}++-----------------------------------------------------------------------------+-- |+-- Module      :  GHC.Num+-- Copyright   :  (c) The University of Glasgow 1994-2002+-- License     :  see libraries/base/LICENSE+--+-- Maintainer  :  cvs-ghc@haskell.org+-- Stability   :  internal+-- Portability :  non-portable (GHC Extensions)+--+-- The 'Num' class and the 'Integer' type.+--+-----------------------------------------------------------------------------++module GHC.Num (module GHC.Num, module GHC.Integer) where++import GHC.Base+import GHC.Integer++infixl 7  *+infixl 6  +, -++default ()              -- Double isn't available yet,+                        -- and we shouldn't be using defaults anyway++-- | Basic numeric class.+class  Num a  where+    {-# MINIMAL (+), (*), abs, signum, fromInteger, (negate | (-)) #-}++    (+), (-), (*)       :: a -> a -> a+    -- | Unary negation.+    negate              :: a -> a+    -- | Absolute value.+    abs                 :: a -> a+    -- | Sign of a number.+    -- The functions 'abs' and 'signum' should satisfy the law:+    --+    -- > abs x * signum x == x+    --+    -- For real numbers, the 'signum' is either @-1@ (negative), @0@ (zero)+    -- or @1@ (positive).+    signum              :: a -> a+    -- | Conversion from an 'Integer'.+    -- An integer literal represents the application of the function+    -- 'fromInteger' to the appropriate value of type 'Integer',+    -- so such literals have type @('Num' a) => a@.+    fromInteger         :: Integer -> a++    {-# INLINE (-) #-}+    {-# INLINE negate #-}+    x - y               = x + negate y+    negate x            = 0 - x++-- | the same as @'flip' ('-')@.+--+-- Because @-@ is treated specially in the Haskell grammar,+-- @(-@ /e/@)@ is not a section, but an application of prefix negation.+-- However, @('subtract'@ /exp/@)@ is equivalent to the disallowed section.+{-# INLINE subtract #-}+subtract :: (Num a) => a -> a -> a+subtract x y = y - x++instance  Num Int  where+    I# x + I# y = I# (x +# y)+    I# x - I# y = I# (x -# y)+    negate (I# x) = I# (negateInt# x)+    I# x * I# y = I# (x *# y)+    abs n  = if n `geInt` 0 then n else negate n++    signum n | n `ltInt` 0 = negate 1+             | n `eqInt` 0 = 0+             | otherwise   = 1++    {-# INLINE fromInteger #-}   -- Just to be sure!+    fromInteger i = I# (integerToInt i)++instance Num Word where+    (W# x#) + (W# y#)      = W# (x# `plusWord#` y#)+    (W# x#) - (W# y#)      = W# (x# `minusWord#` y#)+    (W# x#) * (W# y#)      = W# (x# `timesWord#` y#)+    negate (W# x#)         = W# (int2Word# (negateInt# (word2Int# x#)))+    abs x                  = x+    signum 0               = 0+    signum _               = 1+    fromInteger i          = W# (integerToWord i)++instance  Num Integer  where+    (+) = plusInteger+    (-) = minusInteger+    (*) = timesInteger+    negate         = negateInteger+    fromInteger x  =  x++    abs = absInteger+    signum = signumInteger
− GHC/Num.lhs
@@ -1,135 +0,0 @@-\begin{code}-{-# LANGUAGE Trustworthy #-}-{-# LANGUAGE NoImplicitPrelude, MagicHash, UnboxedTuples #-}-{-# OPTIONS_HADDOCK hide #-}--------------------------------------------------------------------------------- |--- Module      :  GHC.Num--- Copyright   :  (c) The University of Glasgow 1994-2002--- License     :  see libraries/base/LICENSE------ Maintainer  :  cvs-ghc@haskell.org--- Stability   :  internal--- Portability :  non-portable (GHC Extensions)------ The 'Num' class and the 'Integer' type.-----------------------------------------------------------------------------------module GHC.Num (module GHC.Num, module GHC.Integer) where--import GHC.Base-import GHC.Integer--infixl 7  *-infixl 6  +, ---default ()              -- Double isn't available yet,-                        -- and we shouldn't be using defaults anyway-\end{code}--%*********************************************************-%*                                                      *-\subsection{Standard numeric class}-%*                                                      *-%*********************************************************--\begin{code}--- | Basic numeric class.------ Minimal complete definition: all except 'negate' or @(-)@-class  Num a  where-    (+), (-), (*)       :: a -> a -> a-    -- | Unary negation.-    negate              :: a -> a-    -- | Absolute value.-    abs                 :: a -> a-    -- | Sign of a number.-    -- The functions 'abs' and 'signum' should satisfy the law:-    ---    -- > abs x * signum x == x-    ---    -- For real numbers, the 'signum' is either @-1@ (negative), @0@ (zero)-    -- or @1@ (positive).-    signum              :: a -> a-    -- | Conversion from an 'Integer'.-    -- An integer literal represents the application of the function-    -- 'fromInteger' to the appropriate value of type 'Integer',-    -- so such literals have type @('Num' a) => a@.-    fromInteger         :: Integer -> a--    {-# INLINE (-) #-}-    {-# INLINE negate #-}-    x - y               = x + negate y-    negate x            = 0 - x-    {-# MINIMAL (+), (*), abs, signum, fromInteger, (negate | (-)) #-}---- | the same as @'flip' ('-')@.------ Because @-@ is treated specially in the Haskell grammar,--- @(-@ /e/@)@ is not a section, but an application of prefix negation.--- However, @('subtract'@ /exp/@)@ is equivalent to the disallowed section.-{-# INLINE subtract #-}-subtract :: (Num a) => a -> a -> a-subtract x y = y - x-\end{code}---%*********************************************************-%*                                                      *-\subsection{Instances for @Int@}-%*                                                      *-%*********************************************************--\begin{code}-instance  Num Int  where-    I# x + I# y = I# (x +# y)-    I# x - I# y = I# (x -# y)-    negate (I# x) = I# (negateInt# x)-    I# x * I# y = I# (x *# y)-    abs n  = if n `geInt` 0 then n else negate n--    signum n | n `ltInt` 0 = negate 1-             | n `eqInt` 0 = 0-             | otherwise   = 1--    {-# INLINE fromInteger #-}	 -- Just to be sure!-    fromInteger i = I# (integerToInt i)-\end{code}--%*********************************************************-%*                                                      *-\subsection{Instances for @Word@}-%*                                                      *-%*********************************************************--\begin{code}-instance Num Word where-    (W# x#) + (W# y#)      = W# (x# `plusWord#` y#)-    (W# x#) - (W# y#)      = W# (x# `minusWord#` y#)-    (W# x#) * (W# y#)      = W# (x# `timesWord#` y#)-    negate (W# x#)         = W# (int2Word# (negateInt# (word2Int# x#)))-    abs x                  = x-    signum 0               = 0-    signum _               = 1-    fromInteger i          = W# (integerToWord i)-\end{code}--%*********************************************************-%*                                                      *-\subsection{The @Integer@ instances for @Num@}-%*                                                      *-%*********************************************************--\begin{code}-instance  Num Integer  where-    (+) = plusInteger-    (-) = minusInteger-    (*) = timesInteger-    negate         = negateInteger-    fromInteger x  =  x--    abs = absInteger-    signum = signumInteger-\end{code}-
+ GHC/OldList.hs view
@@ -0,0 +1,29 @@+{-# LANGUAGE NoImplicitPrelude #-}+{-# LANGUAGE Safe #-}++-----------------------------------------------------------------------------+-- |+-- Module      :  GHC.OldList+-- Copyright   :  (c) The University of Glasgow 2001+-- License     :  BSD-style (see the file libraries/base/LICENSE)+--+-- Maintainer  :  libraries@haskell.org+-- Stability   :  experimental+-- Portability :  portable+--+-- This legacy module provides access to the list-specialised operations+-- of "Data.List". This module may go away again in future GHC versions and+-- is provided as transitional tool to access some of the list-specialised+-- operations that had to be generalised due to the implementation of the+-- <https://wiki.haskell.org/Foldable_Traversable_In_Prelude Foldable/Traversable-in-Prelude Proposal (FTP)>.+--+-- If the operations needed are available in "GHC.List", it's+-- recommended to avoid importing this module and use "GHC.List"+-- instead for now.+--+-- @since 4.8.0.0+-----------------------------------------------------------------------------++module GHC.OldList (module Data.OldList) where++import Data.OldList
GHC/PArr.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE Trustworthy #-}+{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ParallelArrays, MagicHash #-} {-# OPTIONS_GHC -funbox-strict-fields #-} {-# OPTIONS_HADDOCK hide #-}
+ GHC/Pack.hs view
@@ -0,0 +1,101 @@+{-# LANGUAGE Unsafe #-}+{-# LANGUAGE NoImplicitPrelude, MagicHash, UnboxedTuples #-}+{-# OPTIONS_HADDOCK hide #-}++-----------------------------------------------------------------------------+-- |+-- Module      :  GHC.Pack+-- Copyright   :  (c) The University of Glasgow 1997-2002+-- License     :  see libraries/base/LICENSE+--+-- Maintainer  :  cvs-ghc@haskell.org+-- Stability   :  internal+-- Portability :  non-portable (GHC Extensions)+--+-- This module provides a small set of low-level functions for packing+-- and unpacking a chunk of bytes. Used by code emitted by the compiler+-- plus the prelude libraries.+--+-- The programmer level view of packed strings is provided by a GHC+-- system library PackedString.+--+-----------------------------------------------------------------------------++module GHC.Pack+       (+        -- (**) - emitted by compiler.++        packCString#,+        unpackCString,+        unpackCString#,+        unpackNBytes#,+        unpackFoldrCString#,  -- (**)+        unpackAppendCString#,  -- (**)+       )+        where++import GHC.Base+import GHC.List ( length )+import GHC.ST+import GHC.Ptr++data ByteArray ix              = ByteArray        ix ix ByteArray#+data MutableByteArray s ix     = MutableByteArray ix ix (MutableByteArray# s)++unpackCString :: Ptr a -> [Char]+unpackCString a@(Ptr addr)+  | a == nullPtr  = []+  | otherwise      = unpackCString# addr++packCString#         :: [Char]          -> ByteArray#+packCString# str = case (packString str) of { ByteArray _ _ bytes -> bytes }++packString :: [Char] -> ByteArray Int+packString str = runST (packStringST str)++packStringST :: [Char] -> ST s (ByteArray Int)+packStringST str =+  let len = length str  in+  packNBytesST len str++packNBytesST :: Int -> [Char] -> ST s (ByteArray Int)+packNBytesST (I# length#) str =+  {-+   allocate an array that will hold the string+   (not forgetting the NUL byte at the end)+  -}+ new_ps_array (length# +# 1#) >>= \ ch_array ->+   -- fill in packed string from "str"+ fill_in ch_array 0# str   >>+   -- freeze the puppy:+ freeze_ps_array ch_array length#+ where+  fill_in :: MutableByteArray s Int -> Int# -> [Char] -> ST s ()+  fill_in arr_in# idx [] =+   write_ps_array arr_in# idx (chr# 0#) >>+   return ()++  fill_in arr_in# idx (C# c : cs) =+   write_ps_array arr_in# idx c  >>+   fill_in arr_in# (idx +# 1#) cs++-- (Very :-) ``Specialised'' versions of some CharArray things...++new_ps_array    :: Int# -> ST s (MutableByteArray s Int)+write_ps_array  :: MutableByteArray s Int -> Int# -> Char# -> ST s ()+freeze_ps_array :: MutableByteArray s Int -> Int# -> ST s (ByteArray Int)++new_ps_array size = ST $ \ s ->+    case (newByteArray# size s)   of { (# s2#, barr# #) ->+    (# s2#, MutableByteArray bot bot barr# #) }+  where+    bot = error "new_ps_array"++write_ps_array (MutableByteArray _ _ barr#) n ch = ST $ \ s# ->+    case writeCharArray# barr# n ch s#  of { s2#   ->+    (# s2#, () #) }++-- same as unsafeFreezeByteArray+freeze_ps_array (MutableByteArray _ _ arr#) len# = ST $ \ s# ->+    case unsafeFreezeByteArray# arr# s# of { (# s2#, frozen# #) ->+    (# s2#, ByteArray 0 (I# len#) frozen# #) }
− GHC/Pack.lhs
@@ -1,103 +0,0 @@-\begin{code}-{-# LANGUAGE Unsafe #-}-{-# LANGUAGE NoImplicitPrelude, MagicHash, UnboxedTuples #-}-{-# OPTIONS_HADDOCK hide #-}---------------------------------------------------------------------------------- |--- Module      :  GHC.Pack--- Copyright   :  (c) The University of Glasgow 1997-2002--- License     :  see libraries/base/LICENSE--- --- Maintainer  :  cvs-ghc@haskell.org--- Stability   :  internal--- Portability :  non-portable (GHC Extensions)------ This module provides a small set of low-level functions for packing--- and unpacking a chunk of bytes. Used by code emitted by the compiler--- plus the prelude libraries.--- --- The programmer level view of packed strings is provided by a GHC--- system library PackedString.-----------------------------------------------------------------------------------module GHC.Pack-       (-        -- (**) - emitted by compiler.--        packCString#,-        unpackCString,-        unpackCString#,-        unpackNBytes#,-        unpackFoldrCString#,  -- (**)-        unpackAppendCString#,  -- (**)-       ) -        where--import GHC.Base-import GHC.List ( length )-import GHC.ST-import GHC.Ptr--data ByteArray ix              = ByteArray        ix ix ByteArray#-data MutableByteArray s ix     = MutableByteArray ix ix (MutableByteArray# s)--unpackCString :: Ptr a -> [Char]-unpackCString a@(Ptr addr)-  | a == nullPtr  = []-  | otherwise      = unpackCString# addr--packCString#         :: [Char]          -> ByteArray#-packCString# str = case (packString str) of { ByteArray _ _ bytes -> bytes }--packString :: [Char] -> ByteArray Int-packString str = runST (packStringST str)--packStringST :: [Char] -> ST s (ByteArray Int)-packStringST str =-  let len = length str  in-  packNBytesST len str--packNBytesST :: Int -> [Char] -> ST s (ByteArray Int)-packNBytesST (I# length#) str =-  {- -   allocate an array that will hold the string-   (not forgetting the NUL byte at the end)-  -}- new_ps_array (length# +# 1#) >>= \ ch_array ->-   -- fill in packed string from "str"- fill_in ch_array 0# str   >>-   -- freeze the puppy:- freeze_ps_array ch_array length#- where-  fill_in :: MutableByteArray s Int -> Int# -> [Char] -> ST s ()-  fill_in arr_in# idx [] =-   write_ps_array arr_in# idx (chr# 0#) >>-   return ()--  fill_in arr_in# idx (C# c : cs) =-   write_ps_array arr_in# idx c  >>-   fill_in arr_in# (idx +# 1#) cs---- (Very :-) ``Specialised'' versions of some CharArray things...--new_ps_array    :: Int# -> ST s (MutableByteArray s Int)-write_ps_array  :: MutableByteArray s Int -> Int# -> Char# -> ST s () -freeze_ps_array :: MutableByteArray s Int -> Int# -> ST s (ByteArray Int)--new_ps_array size = ST $ \ s ->-    case (newByteArray# size s)   of { (# s2#, barr# #) ->-    (# s2#, MutableByteArray bot bot barr# #) }-  where-    bot = error "new_ps_array"--write_ps_array (MutableByteArray _ _ barr#) n ch = ST $ \ s# ->-    case writeCharArray# barr# n ch s#  of { s2#   ->-    (# s2#, () #) }---- same as unsafeFreezeByteArray-freeze_ps_array (MutableByteArray _ _ arr#) len# = ST $ \ s# ->-    case unsafeFreezeByteArray# arr# s# of { (# s2#, frozen# #) ->-    (# s2#, ByteArray 0 (I# len#) frozen# #) }-\end{code}
GHC/Profiling.hs view
@@ -1,5 +1,10 @@--- | /Since: 4.7.0.0/+{-# LANGUAGE Trustworthy #-}+{-# LANGUAGE NoImplicitPrelude #-}++-- | @since 4.7.0.0 module GHC.Profiling where++import GHC.Base  foreign import ccall startProfTimer :: IO () foreign import ccall stopProfTimer :: IO ()
+ GHC/Ptr.hs view
@@ -0,0 +1,174 @@+{-# LANGUAGE Unsafe #-}+{-# LANGUAGE CPP, NoImplicitPrelude, MagicHash, RoleAnnotations #-}+{-# OPTIONS_HADDOCK hide #-}++-----------------------------------------------------------------------------+-- |+-- Module      :  GHC.Ptr+-- Copyright   :  (c) The FFI Task Force, 2000-2002+-- License     :  see libraries/base/LICENSE+--+-- Maintainer  :  ffi@haskell.org+-- Stability   :  internal+-- Portability :  non-portable (GHC Extensions)+--+-- The 'Ptr' and 'FunPtr' types and operations.+--+-----------------------------------------------------------------------------++module GHC.Ptr (+        Ptr(..), FunPtr(..),+        nullPtr, castPtr, plusPtr, alignPtr, minusPtr,+        nullFunPtr, castFunPtr,++        -- * Unsafe functions+        castFunPtrToPtr, castPtrToFunPtr+    ) where++import GHC.Base+import GHC.Show+import GHC.Num+import GHC.List ( length, replicate )+import Numeric          ( showHex )++#include "MachDeps.h"++------------------------------------------------------------------------+-- Data pointers.++-- The role of Ptr's parameter is phantom, as there is no relation between+-- the Haskell representation and whathever the user puts at the end of the+-- pointer. And phantom is useful to implement castPtr (see #9163)++-- redundant role annotation checks that this doesn't change+type role Ptr phantom+data Ptr a = Ptr Addr# deriving (Eq, Ord)+-- ^ A value of type @'Ptr' a@ represents a pointer to an object, or an+-- array of objects, which may be marshalled to or from Haskell values+-- of type @a@.+--+-- The type @a@ will often be an instance of class+-- 'Foreign.Storable.Storable' which provides the marshalling operations.+-- However this is not essential, and you can provide your own operations+-- to access the pointer.  For example you might write small foreign+-- functions to get or set the fields of a C @struct@.++-- |The constant 'nullPtr' contains a distinguished value of 'Ptr'+-- that is not associated with a valid memory location.+nullPtr :: Ptr a+nullPtr = Ptr nullAddr#++-- |The 'castPtr' function casts a pointer from one type to another.+castPtr :: Ptr a -> Ptr b+castPtr = coerce++-- |Advances the given address by the given offset in bytes.+plusPtr :: Ptr a -> Int -> Ptr b+plusPtr (Ptr addr) (I# d) = Ptr (plusAddr# addr d)++-- |Given an arbitrary address and an alignment constraint,+-- 'alignPtr' yields the next higher address that fulfills the+-- alignment constraint.  An alignment constraint @x@ is fulfilled by+-- any address divisible by @x@.  This operation is idempotent.+alignPtr :: Ptr a -> Int -> Ptr a+alignPtr addr@(Ptr a) (I# i)+  = case remAddr# a i of {+      0# -> addr;+      n -> Ptr (plusAddr# a (i -# n)) }++-- |Computes the offset required to get from the second to the first+-- argument.  We have+--+-- > p2 == p1 `plusPtr` (p2 `minusPtr` p1)+minusPtr :: Ptr a -> Ptr b -> Int+minusPtr (Ptr a1) (Ptr a2) = I# (minusAddr# a1 a2)++------------------------------------------------------------------------+-- Function pointers for the default calling convention.++-- 'FunPtr' has a phantom role for similar reasons to 'Ptr'. Note+-- that 'FunPtr's role cannot become nominal without changes elsewhere+-- in GHC. See Note [FFI type roles] in TcForeign.+type role FunPtr phantom+data FunPtr a = FunPtr Addr# deriving (Eq, Ord)+-- ^ A value of type @'FunPtr' a@ is a pointer to a function callable+-- from foreign code.  The type @a@ will normally be a /foreign type/,+-- a function type with zero or more arguments where+--+-- * the argument types are /marshallable foreign types/,+--   i.e. 'Char', 'Int', 'Double', 'Float',+--   'Bool', 'Data.Int.Int8', 'Data.Int.Int16', 'Data.Int.Int32',+--   'Data.Int.Int64', 'Data.Word.Word8', 'Data.Word.Word16',+--   'Data.Word.Word32', 'Data.Word.Word64', @'Ptr' a@, @'FunPtr' a@,+--   @'Foreign.StablePtr.StablePtr' a@ or a renaming of any of these+--   using @newtype@.+--+-- * the return type is either a marshallable foreign type or has the form+--   @'IO' t@ where @t@ is a marshallable foreign type or @()@.+--+-- A value of type @'FunPtr' a@ may be a pointer to a foreign function,+-- either returned by another foreign function or imported with a+-- a static address import like+--+-- > foreign import ccall "stdlib.h &free"+-- >   p_free :: FunPtr (Ptr a -> IO ())+--+-- or a pointer to a Haskell function created using a /wrapper/ stub+-- declared to produce a 'FunPtr' of the correct type.  For example:+--+-- > type Compare = Int -> Int -> Bool+-- > foreign import ccall "wrapper"+-- >   mkCompare :: Compare -> IO (FunPtr Compare)+--+-- Calls to wrapper stubs like @mkCompare@ allocate storage, which+-- should be released with 'Foreign.Ptr.freeHaskellFunPtr' when no+-- longer required.+--+-- To convert 'FunPtr' values to corresponding Haskell functions, one+-- can define a /dynamic/ stub for the specific foreign type, e.g.+--+-- > type IntFunction = CInt -> IO ()+-- > foreign import ccall "dynamic"+-- >   mkFun :: FunPtr IntFunction -> IntFunction++-- |The constant 'nullFunPtr' contains a+-- distinguished value of 'FunPtr' that is not+-- associated with a valid memory location.+nullFunPtr :: FunPtr a+nullFunPtr = FunPtr nullAddr#++-- |Casts a 'FunPtr' to a 'FunPtr' of a different type.+castFunPtr :: FunPtr a -> FunPtr b+castFunPtr = coerce++-- |Casts a 'FunPtr' to a 'Ptr'.+--+-- /Note:/ this is valid only on architectures where data and function+-- pointers range over the same set of addresses, and should only be used+-- for bindings to external libraries whose interface already relies on+-- this assumption.+castFunPtrToPtr :: FunPtr a -> Ptr b+castFunPtrToPtr (FunPtr addr) = Ptr addr++-- |Casts a 'Ptr' to a 'FunPtr'.+--+-- /Note:/ this is valid only on architectures where data and function+-- pointers range over the same set of addresses, and should only be used+-- for bindings to external libraries whose interface already relies on+-- this assumption.+castPtrToFunPtr :: Ptr a -> FunPtr b+castPtrToFunPtr (Ptr addr) = FunPtr addr+++------------------------------------------------------------------------+-- Show instances for Ptr and FunPtr++instance Show (Ptr a) where+   showsPrec _ (Ptr a) rs = pad_out (showHex (wordToInteger(int2Word#(addr2Int# a))) "")+     where+        -- want 0s prefixed to pad it out to a fixed length.+       pad_out ls =+          '0':'x':(replicate (2*SIZEOF_HSPTR - length ls) '0') ++ ls ++ rs++instance Show (FunPtr a) where+   showsPrec p = showsPrec p . castFunPtrToPtr
− GHC/Ptr.lhs
@@ -1,169 +0,0 @@-\begin{code}-{-# LANGUAGE Unsafe #-}-{-# LANGUAGE CPP, NoImplicitPrelude, MagicHash, RoleAnnotations #-}-{-# OPTIONS_HADDOCK hide #-}---------------------------------------------------------------------------------- |--- Module      :  GHC.Ptr--- Copyright   :  (c) The FFI Task Force, 2000-2002--- License     :  see libraries/base/LICENSE--- --- Maintainer  :  ffi@haskell.org--- Stability   :  internal--- Portability :  non-portable (GHC Extensions)------ The 'Ptr' and 'FunPtr' types and operations.-----------------------------------------------------------------------------------module GHC.Ptr (-        Ptr(..), FunPtr(..),-        nullPtr, castPtr, plusPtr, alignPtr, minusPtr,-        nullFunPtr, castFunPtr,--        -- * Unsafe functions-        castFunPtrToPtr, castPtrToFunPtr-    ) where--import GHC.Base-import GHC.Show-import GHC.Num-import GHC.List ( length, replicate )-import Numeric          ( showHex )--#include "MachDeps.h"----------------------------------------------------------------------------- Data pointers.--type role Ptr representational-data Ptr a = Ptr Addr# deriving (Eq, Ord)--- ^ A value of type @'Ptr' a@ represents a pointer to an object, or an--- array of objects, which may be marshalled to or from Haskell values--- of type @a@.------ The type @a@ will often be an instance of class--- 'Foreign.Storable.Storable' which provides the marshalling operations.--- However this is not essential, and you can provide your own operations--- to access the pointer.  For example you might write small foreign--- functions to get or set the fields of a C @struct@.---- |The constant 'nullPtr' contains a distinguished value of 'Ptr'--- that is not associated with a valid memory location.-nullPtr :: Ptr a-nullPtr = Ptr nullAddr#---- |The 'castPtr' function casts a pointer from one type to another.-castPtr :: Ptr a -> Ptr b-castPtr (Ptr addr) = Ptr addr---- |Advances the given address by the given offset in bytes.-plusPtr :: Ptr a -> Int -> Ptr b-plusPtr (Ptr addr) (I# d) = Ptr (plusAddr# addr d)---- |Given an arbitrary address and an alignment constraint,--- 'alignPtr' yields the next higher address that fulfills the--- alignment constraint.  An alignment constraint @x@ is fulfilled by--- any address divisible by @x@.  This operation is idempotent.-alignPtr :: Ptr a -> Int -> Ptr a-alignPtr addr@(Ptr a) (I# i)-  = case remAddr# a i of {-      0# -> addr;-      n -> Ptr (plusAddr# a (i -# n)) }---- |Computes the offset required to get from the second to the first--- argument.  We have ------ > p2 == p1 `plusPtr` (p2 `minusPtr` p1)-minusPtr :: Ptr a -> Ptr b -> Int-minusPtr (Ptr a1) (Ptr a2) = I# (minusAddr# a1 a2)----------------------------------------------------------------------------- Function pointers for the default calling convention.--type role FunPtr representational-data FunPtr a = FunPtr Addr# deriving (Eq, Ord)--- ^ A value of type @'FunPtr' a@ is a pointer to a function callable--- from foreign code.  The type @a@ will normally be a /foreign type/,--- a function type with zero or more arguments where------ * the argument types are /marshallable foreign types/,---   i.e. 'Char', 'Int', 'Double', 'Float',---   'Bool', 'Data.Int.Int8', 'Data.Int.Int16', 'Data.Int.Int32',---   'Data.Int.Int64', 'Data.Word.Word8', 'Data.Word.Word16',---   'Data.Word.Word32', 'Data.Word.Word64', @'Ptr' a@, @'FunPtr' a@,---   @'Foreign.StablePtr.StablePtr' a@ or a renaming of any of these---   using @newtype@.--- --- * the return type is either a marshallable foreign type or has the form---   @'IO' t@ where @t@ is a marshallable foreign type or @()@.------ A value of type @'FunPtr' a@ may be a pointer to a foreign function,--- either returned by another foreign function or imported with a--- a static address import like------ > foreign import ccall "stdlib.h &free"--- >   p_free :: FunPtr (Ptr a -> IO ())------ or a pointer to a Haskell function created using a /wrapper/ stub--- declared to produce a 'FunPtr' of the correct type.  For example:------ > type Compare = Int -> Int -> Bool--- > foreign import ccall "wrapper"--- >   mkCompare :: Compare -> IO (FunPtr Compare)------ Calls to wrapper stubs like @mkCompare@ allocate storage, which--- should be released with 'Foreign.Ptr.freeHaskellFunPtr' when no--- longer required.------ To convert 'FunPtr' values to corresponding Haskell functions, one--- can define a /dynamic/ stub for the specific foreign type, e.g.------ > type IntFunction = CInt -> IO ()--- > foreign import ccall "dynamic" --- >   mkFun :: FunPtr IntFunction -> IntFunction---- |The constant 'nullFunPtr' contains a--- distinguished value of 'FunPtr' that is not--- associated with a valid memory location.-nullFunPtr :: FunPtr a-nullFunPtr = FunPtr nullAddr#---- |Casts a 'FunPtr' to a 'FunPtr' of a different type.-castFunPtr :: FunPtr a -> FunPtr b-castFunPtr (FunPtr addr) = FunPtr addr---- |Casts a 'FunPtr' to a 'Ptr'.------ /Note:/ this is valid only on architectures where data and function--- pointers range over the same set of addresses, and should only be used--- for bindings to external libraries whose interface already relies on--- this assumption.-castFunPtrToPtr :: FunPtr a -> Ptr b-castFunPtrToPtr (FunPtr addr) = Ptr addr---- |Casts a 'Ptr' to a 'FunPtr'.------ /Note:/ this is valid only on architectures where data and function--- pointers range over the same set of addresses, and should only be used--- for bindings to external libraries whose interface already relies on--- this assumption.-castPtrToFunPtr :: Ptr a -> FunPtr b-castPtrToFunPtr (Ptr addr) = FunPtr addr------------------------------------------------------------------------------ Show instances for Ptr and FunPtr--instance Show (Ptr a) where-   showsPrec _ (Ptr a) rs = pad_out (showHex (wordToInteger(int2Word#(addr2Int# a))) "")-     where-        -- want 0s prefixed to pad it out to a fixed length.-       pad_out ls = -          '0':'x':(replicate (2*SIZEOF_HSPTR - length ls) '0') ++ ls ++ rs--instance Show (FunPtr a) where-   showsPrec p = showsPrec p . castFunPtrToPtr--\end{code}
+ GHC/RTS/Flags.hsc view
@@ -0,0 +1,408 @@+{-# LANGUAGE NoImplicitPrelude #-}+{-# LANGUAGE RecordWildCards   #-}++-- | Accessors to GHC RTS flags.+-- Descriptions of flags can be seen in+-- <https://www.haskell.org/ghc/docs/latest/html/users_guide/runtime-control.html GHC User's Guide>,+-- or by running RTS help message using @+RTS --help@.+--+-- @since 4.8.0.0+--+module GHC.RTS.Flags+  ( RTSFlags (..)+  , GCFlags (..)+  , ConcFlags (..)+  , MiscFlags (..)+  , DebugFlags (..)+  , CCFlags (..)+  , ProfFlags (..)+  , TraceFlags (..)+  , TickyFlags (..)+  , getRTSFlags+  , getGCFlags+  , getConcFlags+  , getMiscFlags+  , getDebugFlags+  , getCCFlags+  , getProfFlags+  , getTraceFlags+  , getTickyFlags+  ) where++#include "Rts.h"+#include "rts/Flags.h"++import Control.Applicative+import Control.Monad++import Foreign.C.String    (peekCString)+import Foreign.C.Types     (CChar, CInt)+import Foreign.Ptr         (Ptr, nullPtr)+import Foreign.Storable    (peekByteOff)++import GHC.Base+import GHC.Enum+import GHC.IO+import GHC.Real+import GHC.Show+import GHC.Word++-- | @'Time'@ is defined as a @'StgWord64'@ in @stg/Types.h@+type Time = Word64++-- | @'nat'@ defined in @rts/Types.h@+type Nat = #{type unsigned int}++data GiveGCStats+    = NoGCStats+    | CollectGCStats+    | OneLineGCStats+    | SummaryGCStats+    | VerboseGCStats+    deriving (Show)++instance Enum GiveGCStats where+    fromEnum NoGCStats      = #{const NO_GC_STATS}+    fromEnum CollectGCStats = #{const COLLECT_GC_STATS}+    fromEnum OneLineGCStats = #{const ONELINE_GC_STATS}+    fromEnum SummaryGCStats = #{const SUMMARY_GC_STATS}+    fromEnum VerboseGCStats = #{const VERBOSE_GC_STATS}++    toEnum #{const NO_GC_STATS}      = NoGCStats+    toEnum #{const COLLECT_GC_STATS} = CollectGCStats+    toEnum #{const ONELINE_GC_STATS} = OneLineGCStats+    toEnum #{const SUMMARY_GC_STATS} = SummaryGCStats+    toEnum #{const VERBOSE_GC_STATS} = VerboseGCStats+    toEnum e = error ("invalid enum for GiveGCStats: " ++ show e)++data GCFlags = GCFlags+    { statsFile             :: Maybe FilePath+    , giveStats             :: GiveGCStats+    , maxStkSize            :: Nat+    , initialStkSize        :: Nat+    , stkChunkSize          :: Nat+    , stkChunkBufferSize    :: Nat+    , maxHeapSize           :: Nat+    , minAllocAreaSize      :: Nat+    , minOldGenSize         :: Nat+    , heapSizeSuggestion    :: Nat+    , heapSizeSuggestionAuto :: Bool+    , oldGenFactor          :: Double+    , pcFreeHeap            :: Double+    , generations           :: Nat+    , steps                 :: Nat+    , squeezeUpdFrames      :: Bool+    , compact               :: Bool -- ^ True <=> "compact all the time"+    , compactThreshold      :: Double+    , sweep                 :: Bool+      -- ^ use "mostly mark-sweep" instead of copying for the oldest generation+    , ringBell              :: Bool+    , frontpanel            :: Bool+    , idleGCDelayTime       :: Time+    , doIdleGC              :: Bool+    , heapBase              :: Word -- ^ address to ask the OS for memory+    , allocLimitGrace       :: Word+    } deriving (Show)++data ConcFlags = ConcFlags+    { ctxtSwitchTime  :: Time+    , ctxtSwitchTicks :: Int+    } deriving (Show)++data MiscFlags = MiscFlags+    { tickInterval          :: Time+    , installSignalHandlers :: Bool+    , machineReadable       :: Bool+    , linkerMemBase         :: Word+      -- ^ address to ask the OS for memory for the linker, 0 ==> off+    } deriving (Show)++-- | Flags to control debugging output & extra checking in various+-- subsystems.+data DebugFlags = DebugFlags+    { scheduler   :: Bool -- ^ 's'+    , interpreter :: Bool -- ^ 'i'+    , weak        :: Bool -- ^ 'w'+    , gccafs      :: Bool -- ^ 'G'+    , gc          :: Bool -- ^ 'g'+    , block_alloc :: Bool -- ^ 'b'+    , sanity      :: Bool -- ^ 'S'+    , stable      :: Bool -- ^ 't'+    , prof        :: Bool -- ^ 'p'+    , linker      :: Bool -- ^ 'l' the object linker+    , apply       :: Bool -- ^ 'a'+    , stm         :: Bool -- ^ 'm'+    , squeeze     :: Bool -- ^ 'z' stack squeezing & lazy blackholing+    , hpc         :: Bool -- ^ 'c' coverage+    , sparks      :: Bool -- ^ 'r'+    } deriving (Show)++data DoCostCentres+    = CostCentresNone+    | CostCentresSummary+    | CostCentresVerbose+    | CostCentresAll+    | CostCentresXML+    deriving (Show)++instance Enum DoCostCentres where+    fromEnum CostCentresNone    = #{const COST_CENTRES_NONE}+    fromEnum CostCentresSummary = #{const COST_CENTRES_SUMMARY}+    fromEnum CostCentresVerbose = #{const COST_CENTRES_VERBOSE}+    fromEnum CostCentresAll     = #{const COST_CENTRES_ALL}+    fromEnum CostCentresXML     = #{const COST_CENTRES_XML}++    toEnum #{const COST_CENTRES_NONE}    = CostCentresNone+    toEnum #{const COST_CENTRES_SUMMARY} = CostCentresSummary+    toEnum #{const COST_CENTRES_VERBOSE} = CostCentresVerbose+    toEnum #{const COST_CENTRES_ALL}     = CostCentresAll+    toEnum #{const COST_CENTRES_XML}     = CostCentresXML+    toEnum e = error ("invalid enum for DoCostCentres: " ++ show e)++data CCFlags = CCFlags+    { doCostCentres :: DoCostCentres+    , profilerTicks :: Int+    , msecsPerTick  :: Int+    } deriving (Show)++data DoHeapProfile+    = NoHeapProfiling+    | HeapByCCS+    | HeapByMod+    | HeapByDescr+    | HeapByType+    | HeapByRetainer+    | HeapByLDV+    | HeapByClosureType+    deriving (Show)++instance Enum DoHeapProfile where+    fromEnum NoHeapProfiling   = #{const NO_HEAP_PROFILING}+    fromEnum HeapByCCS         = #{const HEAP_BY_CCS}+    fromEnum HeapByMod         = #{const HEAP_BY_MOD}+    fromEnum HeapByDescr       = #{const HEAP_BY_DESCR}+    fromEnum HeapByType        = #{const HEAP_BY_TYPE}+    fromEnum HeapByRetainer    = #{const HEAP_BY_RETAINER}+    fromEnum HeapByLDV         = #{const HEAP_BY_LDV}+    fromEnum HeapByClosureType = #{const HEAP_BY_CLOSURE_TYPE}++    toEnum #{const NO_HEAP_PROFILING}    = NoHeapProfiling+    toEnum #{const HEAP_BY_CCS}          = HeapByCCS+    toEnum #{const HEAP_BY_MOD}          = HeapByMod+    toEnum #{const HEAP_BY_DESCR}        = HeapByDescr+    toEnum #{const HEAP_BY_TYPE}         = HeapByType+    toEnum #{const HEAP_BY_RETAINER}     = HeapByRetainer+    toEnum #{const HEAP_BY_LDV}          = HeapByLDV+    toEnum #{const HEAP_BY_CLOSURE_TYPE} = HeapByClosureType+    toEnum e = error ("invalid enum for DoHeapProfile: " ++ show e)++data ProfFlags = ProfFlags+    { doHeapProfile            :: DoHeapProfile+    , heapProfileInterval      :: Time -- ^ time between samples+    , heapProfileIntervalTicks :: Word -- ^ ticks between samples (derived)+    , includeTSOs              :: Bool+    , showCCSOnException       :: Bool+    , maxRetainerSetSize       :: Word+    , ccsLength                :: Word+    , modSelector              :: Maybe String+    , descrSelector            :: Maybe String+    , typeSelector             :: Maybe String+    , ccSelector               :: Maybe String+    , ccsSelector              :: Maybe String+    , retainerSelector         :: Maybe String+    , bioSelector              :: Maybe String+    } deriving (Show)++data DoTrace+    = TraceNone+    | TraceEventLog+    | TraceStderr+    deriving (Show)++instance Enum DoTrace where+    fromEnum TraceNone     = #{const TRACE_NONE}+    fromEnum TraceEventLog = #{const TRACE_EVENTLOG}+    fromEnum TraceStderr   = #{const TRACE_STDERR}++    toEnum #{const TRACE_NONE}     = TraceNone+    toEnum #{const TRACE_EVENTLOG} = TraceEventLog+    toEnum #{const TRACE_STDERR}   = TraceStderr+    toEnum e = error ("invalid enum for DoTrace: " ++ show e)++data TraceFlags = TraceFlags+    { tracing        :: DoTrace+    , timestamp      :: Bool -- ^ show timestamp in stderr output+    , traceScheduler :: Bool -- ^ trace scheduler events+    , traceGc        :: Bool -- ^ trace GC events+    , sparksSampled  :: Bool -- ^ trace spark events by a sampled method+    , sparksFull     :: Bool -- ^ trace spark events 100% accurately+    , user           :: Bool -- ^ trace user events (emitted from Haskell code)+    } deriving (Show)++data TickyFlags = TickyFlags+    { showTickyStats :: Bool+    , tickyFile      :: Maybe FilePath+    } deriving (Show)++data RTSFlags = RTSFlags+    { gcFlags         :: GCFlags+    , concurrentFlags :: ConcFlags+    , miscFlags       :: MiscFlags+    , debugFlags      :: DebugFlags+    , costCentreFlags :: CCFlags+    , profilingFlags  :: ProfFlags+    , traceFlags      :: TraceFlags+    , tickyFlags      :: TickyFlags+    } deriving (Show)++foreign import ccall safe "getGcFlags"+  getGcFlagsPtr :: IO (Ptr ())++foreign import ccall safe "getConcFlags"+  getConcFlagsPtr :: IO (Ptr ())++foreign import ccall safe "getMiscFlags"+  getMiscFlagsPtr :: IO (Ptr ())++foreign import ccall safe "getDebugFlags"+  getDebugFlagsPtr :: IO (Ptr ())++foreign import ccall safe "getCcFlags"+  getCcFlagsPtr :: IO (Ptr ())++foreign import ccall safe "getProfFlags" getProfFlagsPtr :: IO (Ptr ())++foreign import ccall safe "getTraceFlags"+  getTraceFlagsPtr :: IO (Ptr ())++foreign import ccall safe "getTickyFlags"+  getTickyFlagsPtr :: IO (Ptr ())++getRTSFlags :: IO RTSFlags+getRTSFlags = do+  RTSFlags <$> getGCFlags+           <*> getConcFlags+           <*> getMiscFlags+           <*> getDebugFlags+           <*> getCCFlags+           <*> getProfFlags+           <*> getTraceFlags+           <*> getTickyFlags++peekFilePath :: Ptr () -> IO (Maybe FilePath)+peekFilePath ptr+  | ptr == nullPtr = return Nothing+  | otherwise      = return (Just "<filepath>")++-- | Read a NUL terminated string. Return Nothing in case of a NULL pointer.+peekCStringOpt :: Ptr CChar -> IO (Maybe String)+peekCStringOpt ptr+  | ptr == nullPtr = return Nothing+  | otherwise      = Just <$> peekCString ptr++getGCFlags :: IO GCFlags+getGCFlags = do+  ptr <- getGcFlagsPtr+  GCFlags <$> (peekFilePath =<< #{peek GC_FLAGS, statsFile} ptr)+          <*> (toEnum . fromIntegral <$>+                (#{peek GC_FLAGS, giveStats} ptr :: IO Nat))+          <*> #{peek GC_FLAGS, maxStkSize} ptr+          <*> #{peek GC_FLAGS, initialStkSize} ptr+          <*> #{peek GC_FLAGS, stkChunkSize} ptr+          <*> #{peek GC_FLAGS, stkChunkBufferSize} ptr+          <*> #{peek GC_FLAGS, maxHeapSize} ptr+          <*> #{peek GC_FLAGS, minAllocAreaSize} ptr+          <*> #{peek GC_FLAGS, minOldGenSize} ptr+          <*> #{peek GC_FLAGS, heapSizeSuggestion} ptr+          <*> #{peek GC_FLAGS, heapSizeSuggestionAuto} ptr+          <*> #{peek GC_FLAGS, oldGenFactor} ptr+          <*> #{peek GC_FLAGS, pcFreeHeap} ptr+          <*> #{peek GC_FLAGS, generations} ptr+          <*> #{peek GC_FLAGS, steps} ptr+          <*> #{peek GC_FLAGS, squeezeUpdFrames} ptr+          <*> #{peek GC_FLAGS, compact} ptr+          <*> #{peek GC_FLAGS, compactThreshold} ptr+          <*> #{peek GC_FLAGS, sweep} ptr+          <*> #{peek GC_FLAGS, ringBell} ptr+          <*> #{peek GC_FLAGS, frontpanel} ptr+          <*> #{peek GC_FLAGS, idleGCDelayTime} ptr+          <*> #{peek GC_FLAGS, doIdleGC} ptr+          <*> #{peek GC_FLAGS, heapBase} ptr+          <*> #{peek GC_FLAGS, allocLimitGrace} ptr++getConcFlags :: IO ConcFlags+getConcFlags = do+  ptr <- getConcFlagsPtr+  ConcFlags <$> #{peek CONCURRENT_FLAGS, ctxtSwitchTime} ptr+            <*> #{peek CONCURRENT_FLAGS, ctxtSwitchTicks} ptr++getMiscFlags :: IO MiscFlags+getMiscFlags = do+  ptr <- getMiscFlagsPtr+  MiscFlags <$> #{peek MISC_FLAGS, tickInterval} ptr+            <*> #{peek MISC_FLAGS, install_signal_handlers} ptr+            <*> #{peek MISC_FLAGS, machineReadable} ptr+            <*> #{peek MISC_FLAGS, linkerMemBase} ptr++getDebugFlags :: IO DebugFlags+getDebugFlags = do+  ptr <- getDebugFlagsPtr+  DebugFlags <$> #{peek DEBUG_FLAGS, scheduler} ptr+             <*> #{peek DEBUG_FLAGS, interpreter} ptr+             <*> #{peek DEBUG_FLAGS, weak} ptr+             <*> #{peek DEBUG_FLAGS, gccafs} ptr+             <*> #{peek DEBUG_FLAGS, gc} ptr+             <*> #{peek DEBUG_FLAGS, block_alloc} ptr+             <*> #{peek DEBUG_FLAGS, sanity} ptr+             <*> #{peek DEBUG_FLAGS, stable} ptr+             <*> #{peek DEBUG_FLAGS, prof} ptr+             <*> #{peek DEBUG_FLAGS, linker} ptr+             <*> #{peek DEBUG_FLAGS, apply} ptr+             <*> #{peek DEBUG_FLAGS, stm} ptr+             <*> #{peek DEBUG_FLAGS, squeeze} ptr+             <*> #{peek DEBUG_FLAGS, hpc} ptr+             <*> #{peek DEBUG_FLAGS, sparks} ptr++getCCFlags :: IO CCFlags+getCCFlags = do+  ptr <- getCcFlagsPtr+  CCFlags <$> (toEnum . fromIntegral+                <$> (#{peek COST_CENTRE_FLAGS, doCostCentres} ptr :: IO Nat))+          <*> #{peek COST_CENTRE_FLAGS, profilerTicks} ptr+          <*> #{peek COST_CENTRE_FLAGS, msecsPerTick} ptr++getProfFlags :: IO ProfFlags+getProfFlags = do+  ptr <- getProfFlagsPtr+  ProfFlags <$> (toEnum <$> #{peek PROFILING_FLAGS, doHeapProfile} ptr)+            <*> #{peek PROFILING_FLAGS, heapProfileInterval} ptr+            <*> #{peek PROFILING_FLAGS, heapProfileIntervalTicks} ptr+            <*> #{peek PROFILING_FLAGS, includeTSOs} ptr+            <*> #{peek PROFILING_FLAGS, showCCSOnException} ptr+            <*> #{peek PROFILING_FLAGS, maxRetainerSetSize} ptr+            <*> #{peek PROFILING_FLAGS, ccsLength} ptr+            <*> (peekCStringOpt =<< #{peek PROFILING_FLAGS, modSelector} ptr)+            <*> (peekCStringOpt =<< #{peek PROFILING_FLAGS, descrSelector} ptr)+            <*> (peekCStringOpt =<< #{peek PROFILING_FLAGS, typeSelector} ptr)+            <*> (peekCStringOpt =<< #{peek PROFILING_FLAGS, ccSelector} ptr)+            <*> (peekCStringOpt =<< #{peek PROFILING_FLAGS, ccsSelector} ptr)+            <*> (peekCStringOpt =<< #{peek PROFILING_FLAGS, retainerSelector} ptr)+            <*> (peekCStringOpt =<< #{peek PROFILING_FLAGS, bioSelector} ptr)++getTraceFlags :: IO TraceFlags+getTraceFlags = do+  ptr <- getTraceFlagsPtr+  TraceFlags <$> (toEnum . fromIntegral+                   <$> (#{peek TRACE_FLAGS, tracing} ptr :: IO CInt))+             <*> #{peek TRACE_FLAGS, timestamp} ptr+             <*> #{peek TRACE_FLAGS, scheduler} ptr+             <*> #{peek TRACE_FLAGS, gc} ptr+             <*> #{peek TRACE_FLAGS, sparks_sampled} ptr+             <*> #{peek TRACE_FLAGS, sparks_full} ptr+             <*> #{peek TRACE_FLAGS, user} ptr++getTickyFlags :: IO TickyFlags+getTickyFlags = do+  ptr <- getTickyFlagsPtr+  TickyFlags <$> #{peek TICKY_FLAGS, showTickyStats} ptr+             <*> (peekFilePath =<< #{peek TICKY_FLAGS, tickyFile} ptr)
+ GHC/Read.hs view
@@ -0,0 +1,650 @@+{-# LANGUAGE Trustworthy #-}+{-# LANGUAGE NoImplicitPrelude, StandaloneDeriving, ScopedTypeVariables #-}+{-# OPTIONS_HADDOCK hide #-}++-----------------------------------------------------------------------------+-- |+-- Module      :  GHC.Read+-- Copyright   :  (c) The University of Glasgow, 1994-2002+-- License     :  see libraries/base/LICENSE+--+-- Maintainer  :  cvs-ghc@haskell.org+-- Stability   :  internal+-- Portability :  non-portable (GHC Extensions)+--+-- The 'Read' class and instances for basic data types.+--+-----------------------------------------------------------------------------++module GHC.Read+  ( Read(..)   -- class++  -- ReadS type+  , ReadS++  -- H2010 compatibility+  , lex+  , lexLitChar+  , readLitChar+  , lexDigits++  -- defining readers+  , lexP, expectP+  , paren+  , parens+  , list+  , choose+  , readListDefault, readListPrecDefault+  , readNumber++  -- Temporary+  , readParen+  )+ where++import qualified Text.ParserCombinators.ReadP as P++import Text.ParserCombinators.ReadP+  ( ReadS+  , readP_to_S+  )++import qualified Text.Read.Lex as L+-- Lex exports 'lex', which is also defined here,+-- hence the qualified import.+-- We can't import *anything* unqualified, because that+-- confuses Haddock.++import Text.ParserCombinators.ReadPrec++import Data.Maybe++import GHC.Unicode       ( isDigit )+import GHC.Num+import GHC.Real+import GHC.Float+import GHC.Show+import GHC.Base+import GHC.Arr+++-- | @'readParen' 'True' p@ parses what @p@ parses, but surrounded with+-- parentheses.+--+-- @'readParen' 'False' p@ parses what @p@ parses, but optionally+-- surrounded with parentheses.+readParen       :: Bool -> ReadS a -> ReadS a+-- A Haskell 2010 function+readParen b g   =  if b then mandatory else optional+                   where optional r  = g r ++ mandatory r+                         mandatory r = do+                                ("(",s) <- lex r+                                (x,t)   <- optional s+                                (")",u) <- lex t+                                return (x,u)++-- | Parsing of 'String's, producing values.+--+-- Derived instances of 'Read' make the following assumptions, which+-- derived instances of 'Text.Show.Show' obey:+--+-- * If the constructor is defined to be an infix operator, then the+--   derived 'Read' instance will parse only infix applications of+--   the constructor (not the prefix form).+--+-- * Associativity is not used to reduce the occurrence of parentheses,+--   although precedence may be.+--+-- * If the constructor is defined using record syntax, the derived 'Read'+--   will parse only the record-syntax form, and furthermore, the fields+--   must be given in the same order as the original declaration.+--+-- * The derived 'Read' instance allows arbitrary Haskell whitespace+--   between tokens of the input string.  Extra parentheses are also+--   allowed.+--+-- For example, given the declarations+--+-- > infixr 5 :^:+-- > data Tree a =  Leaf a  |  Tree a :^: Tree a+--+-- the derived instance of 'Read' in Haskell 2010 is equivalent to+--+-- > instance (Read a) => Read (Tree a) where+-- >+-- >         readsPrec d r =  readParen (d > app_prec)+-- >                          (\r -> [(Leaf m,t) |+-- >                                  ("Leaf",s) <- lex r,+-- >                                  (m,t) <- readsPrec (app_prec+1) s]) r+-- >+-- >                       ++ readParen (d > up_prec)+-- >                          (\r -> [(u:^:v,w) |+-- >                                  (u,s) <- readsPrec (up_prec+1) r,+-- >                                  (":^:",t) <- lex s,+-- >                                  (v,w) <- readsPrec (up_prec+1) t]) r+-- >+-- >           where app_prec = 10+-- >                 up_prec = 5+--+-- Note that right-associativity of @:^:@ is unused.+--+-- The derived instance in GHC is equivalent to+--+-- > instance (Read a) => Read (Tree a) where+-- >+-- >         readPrec = parens $ (prec app_prec $ do+-- >                                  Ident "Leaf" <- lexP+-- >                                  m <- step readPrec+-- >                                  return (Leaf m))+-- >+-- >                      +++ (prec up_prec $ do+-- >                                  u <- step readPrec+-- >                                  Symbol ":^:" <- lexP+-- >                                  v <- step readPrec+-- >                                  return (u :^: v))+-- >+-- >           where app_prec = 10+-- >                 up_prec = 5+-- >+-- >         readListPrec = readListPrecDefault++class Read a where+  {-# MINIMAL readsPrec | readPrec #-}++  -- | attempts to parse a value from the front of the string, returning+  -- a list of (parsed value, remaining string) pairs.  If there is no+  -- successful parse, the returned list is empty.+  --+  -- Derived instances of 'Read' and 'Text.Show.Show' satisfy the following:+  --+  -- * @(x,\"\")@ is an element of+  --   @('readsPrec' d ('Text.Show.showsPrec' d x \"\"))@.+  --+  -- That is, 'readsPrec' parses the string produced by+  -- 'Text.Show.showsPrec', and delivers the value that+  -- 'Text.Show.showsPrec' started with.++  readsPrec    :: Int   -- ^ the operator precedence of the enclosing+                        -- context (a number from @0@ to @11@).+                        -- Function application has precedence @10@.+                -> ReadS a++  -- | The method 'readList' is provided to allow the programmer to+  -- give a specialised way of parsing lists of values.+  -- For example, this is used by the predefined 'Read' instance of+  -- the 'Char' type, where values of type 'String' should be are+  -- expected to use double quotes, rather than square brackets.+  readList     :: ReadS [a]++  -- | Proposed replacement for 'readsPrec' using new-style parsers (GHC only).+  readPrec     :: ReadPrec a++  -- | Proposed replacement for 'readList' using new-style parsers (GHC only).+  -- The default definition uses 'readList'.  Instances that define 'readPrec'+  -- should also define 'readListPrec' as 'readListPrecDefault'.+  readListPrec :: ReadPrec [a]++  -- default definitions+  readsPrec    = readPrec_to_S readPrec+  readList     = readPrec_to_S (list readPrec) 0+  readPrec     = readS_to_Prec readsPrec+  readListPrec = readS_to_Prec (\_ -> readList)++readListDefault :: Read a => ReadS [a]+-- ^ A possible replacement definition for the 'readList' method (GHC only).+--   This is only needed for GHC, and even then only for 'Read' instances+--   where 'readListPrec' isn't defined as 'readListPrecDefault'.+readListDefault = readPrec_to_S readListPrec 0++readListPrecDefault :: Read a => ReadPrec [a]+-- ^ A possible replacement definition for the 'readListPrec' method,+--   defined using 'readPrec' (GHC only).+readListPrecDefault = list readPrec++------------------------------------------------------------------------+-- H2010 compatibility++-- | The 'lex' function reads a single lexeme from the input, discarding+-- initial white space, and returning the characters that constitute the+-- lexeme.  If the input string contains only white space, 'lex' returns a+-- single successful \`lexeme\' consisting of the empty string.  (Thus+-- @'lex' \"\" = [(\"\",\"\")]@.)  If there is no legal lexeme at the+-- beginning of the input string, 'lex' fails (i.e. returns @[]@).+--+-- This lexer is not completely faithful to the Haskell lexical syntax+-- in the following respects:+--+-- * Qualified names are not handled properly+--+-- * Octal and hexadecimal numerics are not recognized as a single token+--+-- * Comments are not treated properly+lex :: ReadS String             -- As defined by H2010+lex s  = readP_to_S L.hsLex s++-- | Read a string representation of a character, using Haskell+-- source-language escape conventions.  For example:+--+-- > lexLitChar  "\\nHello"  =  [("\\n", "Hello")]+--+lexLitChar :: ReadS String      -- As defined by H2010+lexLitChar = readP_to_S (do { (s, _) <- P.gather L.lexChar ;+                              return s })+        -- There was a skipSpaces before the P.gather L.lexChar,+        -- but that seems inconsistent with readLitChar++-- | Read a string representation of a character, using Haskell+-- source-language escape conventions, and convert it to the character+-- that it encodes.  For example:+--+-- > readLitChar "\\nHello"  =  [('\n', "Hello")]+--+readLitChar :: ReadS Char       -- As defined by H2010+readLitChar = readP_to_S L.lexChar++-- | Reads a non-empty string of decimal digits.+lexDigits :: ReadS String+lexDigits = readP_to_S (P.munch1 isDigit)++------------------------------------------------------------------------+-- utility parsers++lexP :: ReadPrec L.Lexeme+-- ^ Parse a single lexeme+lexP = lift L.lex++expectP :: L.Lexeme -> ReadPrec ()+expectP lexeme = lift (L.expect lexeme)++paren :: ReadPrec a -> ReadPrec a+-- ^ @(paren p)@ parses \"(P0)\"+--      where @p@ parses \"P0\" in precedence context zero+paren p = do expectP (L.Punc "(")+             x <- reset p+             expectP (L.Punc ")")+             return x++parens :: ReadPrec a -> ReadPrec a+-- ^ @(parens p)@ parses \"P\", \"(P0)\", \"((P0))\", etc,+--      where @p@ parses \"P\"  in the current precedence context+--          and parses \"P0\" in precedence context zero+parens p = optional+ where+  optional  = p +++ mandatory+  mandatory = paren optional++list :: ReadPrec a -> ReadPrec [a]+-- ^ @(list p)@ parses a list of things parsed by @p@,+-- using the usual square-bracket syntax.+list readx =+  parens+  ( do expectP (L.Punc "[")+       (listRest False +++ listNext)+  )+ where+  listRest started =+    do L.Punc c <- lexP+       case c of+         "]"           -> return []+         "," | started -> listNext+         _             -> pfail++  listNext =+    do x  <- reset readx+       xs <- listRest True+       return (x:xs)++choose :: [(String, ReadPrec a)] -> ReadPrec a+-- ^ Parse the specified lexeme and continue as specified.+-- Esp useful for nullary constructors; e.g.+--    @choose [(\"A\", return A), (\"B\", return B)]@+-- We match both Ident and Symbol because the constructor+-- might be an operator eg @(:~:)@+choose sps = foldr ((+++) . try_one) pfail sps+           where+             try_one (s,p) = do { token <- lexP ;+                                  case token of+                                    L.Ident s'  | s==s' -> p+                                    L.Symbol s' | s==s' -> p+                                    _other              -> pfail }++--------------------------------------------------------------+-- Simple instances of Read+--------------------------------------------------------------++instance Read Char where+  readPrec =+    parens+    ( do L.Char c <- lexP+         return c+    )++  readListPrec =+    parens+    ( do L.String s <- lexP     -- Looks for "foo"+         return s+     ++++      readListPrecDefault       -- Looks for ['f','o','o']+    )                           -- (more generous than H2010 spec)++  readList = readListDefault++instance Read Bool where+  readPrec =+    parens+    ( do L.Ident s <- lexP+         case s of+           "True"  -> return True+           "False" -> return False+           _       -> pfail+    )++  readListPrec = readListPrecDefault+  readList     = readListDefault++instance Read Ordering where+  readPrec =+    parens+    ( do L.Ident s <- lexP+         case s of+           "LT" -> return LT+           "EQ" -> return EQ+           "GT" -> return GT+           _    -> pfail+    )++  readListPrec = readListPrecDefault+  readList     = readListDefault++--------------------------------------------------------------+-- Structure instances of Read: Maybe, List etc+--------------------------------------------------------------++{-+For structured instances of Read we start using the precedences.  The+idea is then that 'parens (prec k p)' will fail immediately when trying+to parse it in a context with a higher precedence level than k. But if+there is one parenthesis parsed, then the required precedence level+drops to 0 again, and parsing inside p may succeed.++'appPrec' is just the precedence level of function application.  So,+if we are parsing function application, we'd better require the+precedence level to be at least 'appPrec'. Otherwise, we have to put+parentheses around it.++'step' is used to increase the precedence levels inside a+parser, and can be used to express left- or right- associativity. For+example, % is defined to be left associative, so we only increase+precedence on the right hand side.++Note how step is used in for example the Maybe parser to increase the+precedence beyond appPrec, so that basically only literals and+parenthesis-like objects such as (...) and [...] can be an argument to+'Just'.+-}++instance Read a => Read (Maybe a) where+  readPrec =+    parens+    (do expectP (L.Ident "Nothing")+        return Nothing+     ++++     prec appPrec (+        do expectP (L.Ident "Just")+           x <- step readPrec+           return (Just x))+    )++  readListPrec = readListPrecDefault+  readList     = readListDefault++instance Read a => Read [a] where+  {-# SPECIALISE instance Read [String] #-}+  {-# SPECIALISE instance Read [Char] #-}+  {-# SPECIALISE instance Read [Int] #-}+  readPrec     = readListPrec+  readListPrec = readListPrecDefault+  readList     = readListDefault++instance  (Ix a, Read a, Read b) => Read (Array a b)  where+    readPrec = parens $ prec appPrec $+               do expectP (L.Ident "array")+                  theBounds <- step readPrec+                  vals   <- step readPrec+                  return (array theBounds vals)++    readListPrec = readListPrecDefault+    readList     = readListDefault++instance Read L.Lexeme where+  readPrec     = lexP+  readListPrec = readListPrecDefault+  readList     = readListDefault++--------------------------------------------------------------+-- Numeric instances of Read+--------------------------------------------------------------++readNumber :: Num a => (L.Lexeme -> ReadPrec a) -> ReadPrec a+-- Read a signed number+readNumber convert =+  parens+  ( do x <- lexP+       case x of+         L.Symbol "-" -> do y <- lexP+                            n <- convert y+                            return (negate n)++         _   -> convert x+  )+++convertInt :: Num a => L.Lexeme -> ReadPrec a+convertInt (L.Number n)+ | Just i <- L.numberToInteger n = return (fromInteger i)+convertInt _ = pfail++convertFrac :: forall a . RealFloat a => L.Lexeme -> ReadPrec a+convertFrac (L.Ident "NaN")      = return (0 / 0)+convertFrac (L.Ident "Infinity") = return (1 / 0)+convertFrac (L.Number n) = let resRange = floatRange (undefined :: a)+                           in case L.numberToRangedRational resRange n of+                              Nothing -> return (1 / 0)+                              Just rat -> return $ fromRational rat+convertFrac _            = pfail++instance Read Int where+  readPrec     = readNumber convertInt+  readListPrec = readListPrecDefault+  readList     = readListDefault++instance Read Word where+    readsPrec p s = [(fromInteger x, r) | (x, r) <- readsPrec p s]++instance Read Integer where+  readPrec     = readNumber convertInt+  readListPrec = readListPrecDefault+  readList     = readListDefault++instance Read Float where+  readPrec     = readNumber convertFrac+  readListPrec = readListPrecDefault+  readList     = readListDefault++instance Read Double where+  readPrec     = readNumber convertFrac+  readListPrec = readListPrecDefault+  readList     = readListDefault++instance (Integral a, Read a) => Read (Ratio a) where+  readPrec =+    parens+    ( prec ratioPrec+      ( do x <- step readPrec+           expectP (L.Symbol "%")+           y <- step readPrec+           return (x % y)+      )+    )++  readListPrec = readListPrecDefault+  readList     = readListDefault+++------------------------------------------------------------------------+-- Tuple instances of Read, up to size 15+------------------------------------------------------------------------++instance Read () where+  readPrec =+    parens+    ( paren+      ( return ()+      )+    )++  readListPrec = readListPrecDefault+  readList     = readListDefault++instance (Read a, Read b) => Read (a,b) where+  readPrec = wrap_tup read_tup2+  readListPrec = readListPrecDefault+  readList     = readListDefault++wrap_tup :: ReadPrec a -> ReadPrec a+wrap_tup p = parens (paren p)++read_comma :: ReadPrec ()+read_comma = expectP (L.Punc ",")++read_tup2 :: (Read a, Read b) => ReadPrec (a,b)+-- Reads "a , b"  no parens!+read_tup2 = do x <- readPrec+               read_comma+               y <- readPrec+               return (x,y)++read_tup4 :: (Read a, Read b, Read c, Read d) => ReadPrec (a,b,c,d)+read_tup4 = do  (a,b) <- read_tup2+                read_comma+                (c,d) <- read_tup2+                return (a,b,c,d)+++read_tup8 :: (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h)+          => ReadPrec (a,b,c,d,e,f,g,h)+read_tup8 = do  (a,b,c,d) <- read_tup4+                read_comma+                (e,f,g,h) <- read_tup4+                return (a,b,c,d,e,f,g,h)+++instance (Read a, Read b, Read c) => Read (a, b, c) where+  readPrec = wrap_tup (do { (a,b) <- read_tup2; read_comma+                          ; c <- readPrec+                          ; return (a,b,c) })+  readListPrec = readListPrecDefault+  readList     = readListDefault++instance (Read a, Read b, Read c, Read d) => Read (a, b, c, d) where+  readPrec = wrap_tup read_tup4+  readListPrec = readListPrecDefault+  readList     = readListDefault++instance (Read a, Read b, Read c, Read d, Read e) => Read (a, b, c, d, e) where+  readPrec = wrap_tup (do { (a,b,c,d) <- read_tup4; read_comma+                          ; e <- readPrec+                          ; return (a,b,c,d,e) })+  readListPrec = readListPrecDefault+  readList     = readListDefault++instance (Read a, Read b, Read c, Read d, Read e, Read f)+        => Read (a, b, c, d, e, f) where+  readPrec = wrap_tup (do { (a,b,c,d) <- read_tup4; read_comma+                          ; (e,f) <- read_tup2+                          ; return (a,b,c,d,e,f) })+  readListPrec = readListPrecDefault+  readList     = readListDefault++instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g)+        => Read (a, b, c, d, e, f, g) where+  readPrec = wrap_tup (do { (a,b,c,d) <- read_tup4; read_comma+                          ; (e,f) <- read_tup2; read_comma+                          ; g <- readPrec+                          ; return (a,b,c,d,e,f,g) })+  readListPrec = readListPrecDefault+  readList     = readListDefault++instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h)+        => Read (a, b, c, d, e, f, g, h) where+  readPrec     = wrap_tup read_tup8+  readListPrec = readListPrecDefault+  readList     = readListDefault++instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,+          Read i)+        => Read (a, b, c, d, e, f, g, h, i) where+  readPrec = wrap_tup (do { (a,b,c,d,e,f,g,h) <- read_tup8; read_comma+                          ; i <- readPrec+                          ; return (a,b,c,d,e,f,g,h,i) })+  readListPrec = readListPrecDefault+  readList     = readListDefault++instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,+          Read i, Read j)+        => Read (a, b, c, d, e, f, g, h, i, j) where+  readPrec = wrap_tup (do { (a,b,c,d,e,f,g,h) <- read_tup8; read_comma+                          ; (i,j) <- read_tup2+                          ; return (a,b,c,d,e,f,g,h,i,j) })+  readListPrec = readListPrecDefault+  readList     = readListDefault++instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,+          Read i, Read j, Read k)+        => Read (a, b, c, d, e, f, g, h, i, j, k) where+  readPrec = wrap_tup (do { (a,b,c,d,e,f,g,h) <- read_tup8; read_comma+                          ; (i,j) <- read_tup2; read_comma+                          ; k <- readPrec+                          ; return (a,b,c,d,e,f,g,h,i,j,k) })+  readListPrec = readListPrecDefault+  readList     = readListDefault++instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,+          Read i, Read j, Read k, Read l)+        => Read (a, b, c, d, e, f, g, h, i, j, k, l) where+  readPrec = wrap_tup (do { (a,b,c,d,e,f,g,h) <- read_tup8; read_comma+                          ; (i,j,k,l) <- read_tup4+                          ; return (a,b,c,d,e,f,g,h,i,j,k,l) })+  readListPrec = readListPrecDefault+  readList     = readListDefault++instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,+          Read i, Read j, Read k, Read l, Read m)+        => Read (a, b, c, d, e, f, g, h, i, j, k, l, m) where+  readPrec = wrap_tup (do { (a,b,c,d,e,f,g,h) <- read_tup8; read_comma+                          ; (i,j,k,l) <- read_tup4; read_comma+                          ; m <- readPrec+                          ; return (a,b,c,d,e,f,g,h,i,j,k,l,m) })+  readListPrec = readListPrecDefault+  readList     = readListDefault++instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,+          Read i, Read j, Read k, Read l, Read m, Read n)+        => Read (a, b, c, d, e, f, g, h, i, j, k, l, m, n) where+  readPrec = wrap_tup (do { (a,b,c,d,e,f,g,h) <- read_tup8; read_comma+                          ; (i,j,k,l) <- read_tup4; read_comma+                          ; (m,n) <- read_tup2+                          ; return (a,b,c,d,e,f,g,h,i,j,k,l,m,n) })+  readListPrec = readListPrecDefault+  readList     = readListDefault++instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,+          Read i, Read j, Read k, Read l, Read m, Read n, Read o)+        => Read (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) where+  readPrec = wrap_tup (do { (a,b,c,d,e,f,g,h) <- read_tup8; read_comma+                          ; (i,j,k,l) <- read_tup4; read_comma+                          ; (m,n) <- read_tup2; read_comma+                          ; o <- readPrec+                          ; return (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) })+  readListPrec = readListPrecDefault+  readList     = readListDefault
− GHC/Read.lhs
@@ -1,682 +0,0 @@-\begin{code}-{-# LANGUAGE Trustworthy #-}-{-# LANGUAGE NoImplicitPrelude, StandaloneDeriving, ScopedTypeVariables #-}-{-# OPTIONS_HADDOCK hide #-}---------------------------------------------------------------------------------- |--- Module      :  GHC.Read--- Copyright   :  (c) The University of Glasgow, 1994-2002--- License     :  see libraries/base/LICENSE--- --- Maintainer  :  cvs-ghc@haskell.org--- Stability   :  internal--- Portability :  non-portable (GHC Extensions)------ The 'Read' class and instances for basic data types.-----------------------------------------------------------------------------------module GHC.Read-  ( Read(..)   -- class--  -- ReadS type-  , ReadS--  -- H2010 compatibility-  , lex-  , lexLitChar-  , readLitChar-  , lexDigits--  -- defining readers-  , lexP, expectP-  , paren-  , parens-  , list-  , choose-  , readListDefault, readListPrecDefault-  , readNumber--  -- Temporary-  , readParen-  )- where--import qualified Text.ParserCombinators.ReadP as P--import Text.ParserCombinators.ReadP-  ( ReadS-  , readP_to_S-  )--import qualified Text.Read.Lex as L--- Lex exports 'lex', which is also defined here,--- hence the qualified import.--- We can't import *anything* unqualified, because that--- confuses Haddock.--import Text.ParserCombinators.ReadPrec--import Data.Maybe--import {-# SOURCE #-} GHC.Unicode       ( isDigit )-import GHC.Num-import GHC.Real-import GHC.Float-import GHC.Show-import GHC.Base-import GHC.Arr-\end{code}---\begin{code}--- | @'readParen' 'True' p@ parses what @p@ parses, but surrounded with--- parentheses.------ @'readParen' 'False' p@ parses what @p@ parses, but optionally--- surrounded with parentheses.-readParen       :: Bool -> ReadS a -> ReadS a--- A Haskell 2010 function-readParen b g   =  if b then mandatory else optional-                   where optional r  = g r ++ mandatory r-                         mandatory r = do-                                ("(",s) <- lex r-                                (x,t)   <- optional s-                                (")",u) <- lex t-                                return (x,u)-\end{code}---%*********************************************************-%*                                                      *-\subsection{The @Read@ class}-%*                                                      *-%*********************************************************--\begin{code}---------------------------------------------------------------------------- class Read---- | Parsing of 'String's, producing values.------ Minimal complete definition: 'readsPrec' (or, for GHC only, 'readPrec')------ Derived instances of 'Read' make the following assumptions, which--- derived instances of 'Text.Show.Show' obey:------ * If the constructor is defined to be an infix operator, then the---   derived 'Read' instance will parse only infix applications of---   the constructor (not the prefix form).------ * Associativity is not used to reduce the occurrence of parentheses,---   although precedence may be.------ * If the constructor is defined using record syntax, the derived 'Read'---   will parse only the record-syntax form, and furthermore, the fields---   must be given in the same order as the original declaration.------ * The derived 'Read' instance allows arbitrary Haskell whitespace---   between tokens of the input string.  Extra parentheses are also---   allowed.------ For example, given the declarations------ > infixr 5 :^:--- > data Tree a =  Leaf a  |  Tree a :^: Tree a------ the derived instance of 'Read' in Haskell 2010 is equivalent to------ > instance (Read a) => Read (Tree a) where--- >--- >         readsPrec d r =  readParen (d > app_prec)--- >                          (\r -> [(Leaf m,t) |--- >                                  ("Leaf",s) <- lex r,--- >                                  (m,t) <- readsPrec (app_prec+1) s]) r--- >--- >                       ++ readParen (d > up_prec)--- >                          (\r -> [(u:^:v,w) |--- >                                  (u,s) <- readsPrec (up_prec+1) r,--- >                                  (":^:",t) <- lex s,--- >                                  (v,w) <- readsPrec (up_prec+1) t]) r--- >--- >           where app_prec = 10--- >                 up_prec = 5------ Note that right-associativity of @:^:@ is unused.------ The derived instance in GHC is equivalent to------ > instance (Read a) => Read (Tree a) where--- >--- >         readPrec = parens $ (prec app_prec $ do--- >                                  Ident "Leaf" <- lexP--- >                                  m <- step readPrec--- >                                  return (Leaf m))--- >--- >                      +++ (prec up_prec $ do--- >                                  u <- step readPrec--- >                                  Symbol ":^:" <- lexP--- >                                  v <- step readPrec--- >                                  return (u :^: v))--- >--- >           where app_prec = 10--- >                 up_prec = 5--- >--- >         readListPrec = readListPrecDefault--class Read a where-  -- | attempts to parse a value from the front of the string, returning-  -- a list of (parsed value, remaining string) pairs.  If there is no-  -- successful parse, the returned list is empty.-  ---  -- Derived instances of 'Read' and 'Text.Show.Show' satisfy the following:-  ---  -- * @(x,\"\")@ is an element of-  --   @('readsPrec' d ('Text.Show.showsPrec' d x \"\"))@.-  ---  -- That is, 'readsPrec' parses the string produced by-  -- 'Text.Show.showsPrec', and delivers the value that-  -- 'Text.Show.showsPrec' started with.--  readsPrec    :: Int   -- ^ the operator precedence of the enclosing-                        -- context (a number from @0@ to @11@).-                        -- Function application has precedence @10@.-                -> ReadS a--  -- | The method 'readList' is provided to allow the programmer to-  -- give a specialised way of parsing lists of values.-  -- For example, this is used by the predefined 'Read' instance of-  -- the 'Char' type, where values of type 'String' should be are-  -- expected to use double quotes, rather than square brackets.-  readList     :: ReadS [a]--  -- | Proposed replacement for 'readsPrec' using new-style parsers (GHC only).-  readPrec     :: ReadPrec a--  -- | Proposed replacement for 'readList' using new-style parsers (GHC only).-  -- The default definition uses 'readList'.  Instances that define 'readPrec'-  -- should also define 'readListPrec' as 'readListPrecDefault'.-  readListPrec :: ReadPrec [a]-  -  -- default definitions-  readsPrec    = readPrec_to_S readPrec-  readList     = readPrec_to_S (list readPrec) 0-  readPrec     = readS_to_Prec readsPrec-  readListPrec = readS_to_Prec (\_ -> readList)-  {-# MINIMAL readsPrec | readPrec #-}--readListDefault :: Read a => ReadS [a]--- ^ A possible replacement definition for the 'readList' method (GHC only).---   This is only needed for GHC, and even then only for 'Read' instances---   where 'readListPrec' isn't defined as 'readListPrecDefault'.-readListDefault = readPrec_to_S readListPrec 0--readListPrecDefault :: Read a => ReadPrec [a]--- ^ A possible replacement definition for the 'readListPrec' method,---   defined using 'readPrec' (GHC only).-readListPrecDefault = list readPrec----------------------------------------------------------------------------- H2010 compatibility---- | The 'lex' function reads a single lexeme from the input, discarding--- initial white space, and returning the characters that constitute the--- lexeme.  If the input string contains only white space, 'lex' returns a--- single successful \`lexeme\' consisting of the empty string.  (Thus--- @'lex' \"\" = [(\"\",\"\")]@.)  If there is no legal lexeme at the--- beginning of the input string, 'lex' fails (i.e. returns @[]@).------ This lexer is not completely faithful to the Haskell lexical syntax--- in the following respects:------ * Qualified names are not handled properly------ * Octal and hexadecimal numerics are not recognized as a single token------ * Comments are not treated properly-lex :: ReadS String             -- As defined by H2010-lex s  = readP_to_S L.hsLex s---- | Read a string representation of a character, using Haskell--- source-language escape conventions.  For example:------ > lexLitChar  "\\nHello"  =  [("\\n", "Hello")]----lexLitChar :: ReadS String      -- As defined by H2010-lexLitChar = readP_to_S (do { (s, _) <- P.gather L.lexChar ;-                              return s })-        -- There was a skipSpaces before the P.gather L.lexChar,-        -- but that seems inconsistent with readLitChar---- | Read a string representation of a character, using Haskell--- source-language escape conventions, and convert it to the character--- that it encodes.  For example:------ > readLitChar "\\nHello"  =  [('\n', "Hello")]----readLitChar :: ReadS Char       -- As defined by H2010-readLitChar = readP_to_S L.lexChar---- | Reads a non-empty string of decimal digits.-lexDigits :: ReadS String-lexDigits = readP_to_S (P.munch1 isDigit)----------------------------------------------------------------------------- utility parsers--lexP :: ReadPrec L.Lexeme--- ^ Parse a single lexeme-lexP = lift L.lex--expectP :: L.Lexeme -> ReadPrec ()-expectP lexeme = lift (L.expect lexeme)--paren :: ReadPrec a -> ReadPrec a--- ^ @(paren p)@ parses \"(P0)\"---      where @p@ parses \"P0\" in precedence context zero-paren p = do expectP (L.Punc "(")-             x <- reset p-             expectP (L.Punc ")")-             return x--parens :: ReadPrec a -> ReadPrec a--- ^ @(parens p)@ parses \"P\", \"(P0)\", \"((P0))\", etc, ---      where @p@ parses \"P\"  in the current precedence context---          and parses \"P0\" in precedence context zero-parens p = optional- where-  optional  = p +++ mandatory-  mandatory = paren optional--list :: ReadPrec a -> ReadPrec [a]--- ^ @(list p)@ parses a list of things parsed by @p@,--- using the usual square-bracket syntax.-list readx =-  parens-  ( do expectP (L.Punc "[")-       (listRest False +++ listNext)-  )- where-  listRest started =-    do L.Punc c <- lexP-       case c of-         "]"           -> return []-         "," | started -> listNext-         _             -> pfail-  -  listNext =-    do x  <- reset readx-       xs <- listRest True-       return (x:xs)--choose :: [(String, ReadPrec a)] -> ReadPrec a--- ^ Parse the specified lexeme and continue as specified.--- Esp useful for nullary constructors; e.g.---    @choose [(\"A\", return A), (\"B\", return B)]@--- We match both Ident and Symbol because the constructor--- might be an operator eg @(:~:)@-choose sps = foldr ((+++) . try_one) pfail sps-           where-             try_one (s,p) = do { token <- lexP ;-                                  case token of-                                    L.Ident s'  | s==s' -> p-                                    L.Symbol s' | s==s' -> p-                                    _other              -> pfail }-\end{code}---%*********************************************************-%*                                                      *-\subsection{Simple instances of Read}-%*                                                      *-%*********************************************************--\begin{code}-instance Read Char where-  readPrec =-    parens-    ( do L.Char c <- lexP-         return c-    )--  readListPrec =-    parens-    ( do L.String s <- lexP     -- Looks for "foo"-         return s-     +++-      readListPrecDefault       -- Looks for ['f','o','o']-    )                           -- (more generous than H2010 spec)--  readList = readListDefault--instance Read Bool where-  readPrec =-    parens-    ( do L.Ident s <- lexP-         case s of-           "True"  -> return True-           "False" -> return False-           _       -> pfail-    )--  readListPrec = readListPrecDefault-  readList     = readListDefault--instance Read Ordering where-  readPrec =-    parens-    ( do L.Ident s <- lexP-         case s of-           "LT" -> return LT-           "EQ" -> return EQ-           "GT" -> return GT-           _    -> pfail-    )--  readListPrec = readListPrecDefault-  readList     = readListDefault-\end{code}---%*********************************************************-%*                                                      *-\subsection{Structure instances of Read: Maybe, List etc}-%*                                                      *-%*********************************************************--For structured instances of Read we start using the precedences.  The-idea is then that 'parens (prec k p)' will fail immediately when trying-to parse it in a context with a higher precedence level than k. But if-there is one parenthesis parsed, then the required precedence level-drops to 0 again, and parsing inside p may succeed.--'appPrec' is just the precedence level of function application.  So,-if we are parsing function application, we'd better require the-precedence level to be at least 'appPrec'. Otherwise, we have to put-parentheses around it.--'step' is used to increase the precedence levels inside a-parser, and can be used to express left- or right- associativity. For-example, % is defined to be left associative, so we only increase-precedence on the right hand side.--Note how step is used in for example the Maybe parser to increase the-precedence beyond appPrec, so that basically only literals and-parenthesis-like objects such as (...) and [...] can be an argument to-'Just'.--\begin{code}-instance Read a => Read (Maybe a) where-  readPrec =-    parens-    (do expectP (L.Ident "Nothing")-        return Nothing-     +++-     prec appPrec (-        do expectP (L.Ident "Just")-           x <- step readPrec-           return (Just x))-    )--  readListPrec = readListPrecDefault-  readList     = readListDefault--instance Read a => Read [a] where-  readPrec     = readListPrec-  readListPrec = readListPrecDefault-  readList     = readListDefault--instance  (Ix a, Read a, Read b) => Read (Array a b)  where-    readPrec = parens $ prec appPrec $-               do expectP (L.Ident "array")-                  theBounds <- step readPrec-                  vals   <- step readPrec-                  return (array theBounds vals)--    readListPrec = readListPrecDefault-    readList     = readListDefault--instance Read L.Lexeme where-  readPrec     = lexP-  readListPrec = readListPrecDefault-  readList     = readListDefault-\end{code}---%*********************************************************-%*                                                      *-\subsection{Numeric instances of Read}-%*                                                      *-%*********************************************************--\begin{code}-readNumber :: Num a => (L.Lexeme -> ReadPrec a) -> ReadPrec a--- Read a signed number-readNumber convert =-  parens-  ( do x <- lexP-       case x of-         L.Symbol "-" -> do y <- lexP-                            n <- convert y-                            return (negate n)--         _   -> convert x-  )---convertInt :: Num a => L.Lexeme -> ReadPrec a-convertInt (L.Number n)- | Just i <- L.numberToInteger n = return (fromInteger i)-convertInt _ = pfail--convertFrac :: forall a . RealFloat a => L.Lexeme -> ReadPrec a-convertFrac (L.Ident "NaN")      = return (0 / 0)-convertFrac (L.Ident "Infinity") = return (1 / 0)-convertFrac (L.Number n) = let resRange = floatRange (undefined :: a)-                           in case L.numberToRangedRational resRange n of-                              Nothing -> return (1 / 0)-                              Just rat -> return $ fromRational rat-convertFrac _            = pfail--instance Read Int where-  readPrec     = readNumber convertInt-  readListPrec = readListPrecDefault-  readList     = readListDefault--instance Read Word where-    readsPrec p s = [(fromInteger x, r) | (x, r) <- readsPrec p s]--instance Read Integer where-  readPrec     = readNumber convertInt-  readListPrec = readListPrecDefault-  readList     = readListDefault--instance Read Float where-  readPrec     = readNumber convertFrac-  readListPrec = readListPrecDefault-  readList     = readListDefault--instance Read Double where-  readPrec     = readNumber convertFrac-  readListPrec = readListPrecDefault-  readList     = readListDefault--instance (Integral a, Read a) => Read (Ratio a) where-  readPrec =-    parens-    ( prec ratioPrec-      ( do x <- step readPrec-           expectP (L.Symbol "%")-           y <- step readPrec-           return (x % y)-      )-    )--  readListPrec = readListPrecDefault-  readList     = readListDefault-\end{code}---%*********************************************************-%*                                                      *-        Tuple instances of Read, up to size 15-%*                                                      *-%*********************************************************--\begin{code}-instance Read () where-  readPrec =-    parens-    ( paren-      ( return ()-      )-    )--  readListPrec = readListPrecDefault-  readList     = readListDefault--instance (Read a, Read b) => Read (a,b) where-  readPrec = wrap_tup read_tup2-  readListPrec = readListPrecDefault-  readList     = readListDefault--wrap_tup :: ReadPrec a -> ReadPrec a-wrap_tup p = parens (paren p)--read_comma :: ReadPrec ()-read_comma = expectP (L.Punc ",")--read_tup2 :: (Read a, Read b) => ReadPrec (a,b)--- Reads "a , b"  no parens!-read_tup2 = do x <- readPrec-               read_comma-               y <- readPrec-               return (x,y)--read_tup4 :: (Read a, Read b, Read c, Read d) => ReadPrec (a,b,c,d)-read_tup4 = do  (a,b) <- read_tup2-                read_comma-                (c,d) <- read_tup2-                return (a,b,c,d)---read_tup8 :: (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h)-          => ReadPrec (a,b,c,d,e,f,g,h)-read_tup8 = do  (a,b,c,d) <- read_tup4-                read_comma-                (e,f,g,h) <- read_tup4-                return (a,b,c,d,e,f,g,h)---instance (Read a, Read b, Read c) => Read (a, b, c) where-  readPrec = wrap_tup (do { (a,b) <- read_tup2; read_comma -                          ; c <- readPrec -                          ; return (a,b,c) })-  readListPrec = readListPrecDefault-  readList     = readListDefault--instance (Read a, Read b, Read c, Read d) => Read (a, b, c, d) where-  readPrec = wrap_tup read_tup4-  readListPrec = readListPrecDefault-  readList     = readListDefault--instance (Read a, Read b, Read c, Read d, Read e) => Read (a, b, c, d, e) where-  readPrec = wrap_tup (do { (a,b,c,d) <- read_tup4; read_comma-                          ; e <- readPrec-                          ; return (a,b,c,d,e) })-  readListPrec = readListPrecDefault-  readList     = readListDefault--instance (Read a, Read b, Read c, Read d, Read e, Read f)-        => Read (a, b, c, d, e, f) where-  readPrec = wrap_tup (do { (a,b,c,d) <- read_tup4; read_comma-                          ; (e,f) <- read_tup2-                          ; return (a,b,c,d,e,f) })-  readListPrec = readListPrecDefault-  readList     = readListDefault--instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g)-        => Read (a, b, c, d, e, f, g) where-  readPrec = wrap_tup (do { (a,b,c,d) <- read_tup4; read_comma-                          ; (e,f) <- read_tup2; read_comma-                          ; g <- readPrec-                          ; return (a,b,c,d,e,f,g) })-  readListPrec = readListPrecDefault-  readList     = readListDefault--instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h)-        => Read (a, b, c, d, e, f, g, h) where-  readPrec     = wrap_tup read_tup8-  readListPrec = readListPrecDefault-  readList     = readListDefault--instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,-          Read i)-        => Read (a, b, c, d, e, f, g, h, i) where-  readPrec = wrap_tup (do { (a,b,c,d,e,f,g,h) <- read_tup8; read_comma-                          ; i <- readPrec-                          ; return (a,b,c,d,e,f,g,h,i) })-  readListPrec = readListPrecDefault-  readList     = readListDefault--instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,-          Read i, Read j)-        => Read (a, b, c, d, e, f, g, h, i, j) where-  readPrec = wrap_tup (do { (a,b,c,d,e,f,g,h) <- read_tup8; read_comma-                          ; (i,j) <- read_tup2-                          ; return (a,b,c,d,e,f,g,h,i,j) })-  readListPrec = readListPrecDefault-  readList     = readListDefault--instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,-          Read i, Read j, Read k)-        => Read (a, b, c, d, e, f, g, h, i, j, k) where-  readPrec = wrap_tup (do { (a,b,c,d,e,f,g,h) <- read_tup8; read_comma-                          ; (i,j) <- read_tup2; read_comma-                          ; k <- readPrec-                          ; return (a,b,c,d,e,f,g,h,i,j,k) })-  readListPrec = readListPrecDefault-  readList     = readListDefault--instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,-          Read i, Read j, Read k, Read l)-        => Read (a, b, c, d, e, f, g, h, i, j, k, l) where-  readPrec = wrap_tup (do { (a,b,c,d,e,f,g,h) <- read_tup8; read_comma-                          ; (i,j,k,l) <- read_tup4-                          ; return (a,b,c,d,e,f,g,h,i,j,k,l) })-  readListPrec = readListPrecDefault-  readList     = readListDefault--instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,-          Read i, Read j, Read k, Read l, Read m)-        => Read (a, b, c, d, e, f, g, h, i, j, k, l, m) where-  readPrec = wrap_tup (do { (a,b,c,d,e,f,g,h) <- read_tup8; read_comma-                          ; (i,j,k,l) <- read_tup4; read_comma-                          ; m <- readPrec-                          ; return (a,b,c,d,e,f,g,h,i,j,k,l,m) })-  readListPrec = readListPrecDefault-  readList     = readListDefault--instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,-          Read i, Read j, Read k, Read l, Read m, Read n)-        => Read (a, b, c, d, e, f, g, h, i, j, k, l, m, n) where-  readPrec = wrap_tup (do { (a,b,c,d,e,f,g,h) <- read_tup8; read_comma-                          ; (i,j,k,l) <- read_tup4; read_comma-                          ; (m,n) <- read_tup2-                          ; return (a,b,c,d,e,f,g,h,i,j,k,l,m,n) })-  readListPrec = readListPrecDefault-  readList     = readListDefault--instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h,-          Read i, Read j, Read k, Read l, Read m, Read n, Read o)-        => Read (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) where-  readPrec = wrap_tup (do { (a,b,c,d,e,f,g,h) <- read_tup8; read_comma-                          ; (i,j,k,l) <- read_tup4; read_comma-                          ; (m,n) <- read_tup2; read_comma-                          ; o <- readPrec-                          ; return (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) })-  readListPrec = readListPrecDefault-  readList     = readListDefault-\end{code}-
+ GHC/Real.hs view
@@ -0,0 +1,664 @@+{-# LANGUAGE Trustworthy #-}+{-# LANGUAGE CPP, NoImplicitPrelude, MagicHash, UnboxedTuples, BangPatterns #-}+{-# OPTIONS_GHC -fno-warn-orphans #-}+{-# OPTIONS_HADDOCK hide #-}++-----------------------------------------------------------------------------+-- |+-- Module      :  GHC.Real+-- Copyright   :  (c) The University of Glasgow, 1994-2002+-- License     :  see libraries/base/LICENSE+--+-- Maintainer  :  cvs-ghc@haskell.org+-- Stability   :  internal+-- Portability :  non-portable (GHC Extensions)+--+-- The types 'Ratio' and 'Rational', and the classes 'Real', 'Fractional',+-- 'Integral', and 'RealFrac'.+--+-----------------------------------------------------------------------------++module GHC.Real where++import GHC.Base+import GHC.Num+import GHC.List+import GHC.Enum+import GHC.Show+import {-# SOURCE #-} GHC.Exception( divZeroException, overflowException, ratioZeroDenomException )++#ifdef OPTIMISE_INTEGER_GCD_LCM+# if defined(MIN_VERSION_integer_gmp)+import GHC.Integer.GMP.Internals+# else+#  error unsupported OPTIMISE_INTEGER_GCD_LCM configuration+# endif+#endif++infixr 8  ^, ^^+infixl 7  /, `quot`, `rem`, `div`, `mod`+infixl 7  %++default ()              -- Double isn't available yet,+                        -- and we shouldn't be using defaults anyway++------------------------------------------------------------------------+-- Divide by zero and arithmetic overflow+------------------------------------------------------------------------++-- We put them here because they are needed relatively early+-- in the libraries before the Exception type has been defined yet.++{-# NOINLINE divZeroError #-}+divZeroError :: a+divZeroError = raise# divZeroException++{-# NOINLINE ratioZeroDenominatorError #-}+ratioZeroDenominatorError :: a+ratioZeroDenominatorError = raise# ratioZeroDenomException++{-# NOINLINE overflowError #-}+overflowError :: a+overflowError = raise# overflowException++--------------------------------------------------------------+-- The Ratio and Rational types+--------------------------------------------------------------++-- | Rational numbers, with numerator and denominator of some 'Integral' type.+data  Ratio a = !a :% !a  deriving (Eq)++-- | Arbitrary-precision rational numbers, represented as a ratio of+-- two 'Integer' values.  A rational number may be constructed using+-- the '%' operator.+type  Rational          =  Ratio Integer++ratioPrec, ratioPrec1 :: Int+ratioPrec  = 7  -- Precedence of ':%' constructor+ratioPrec1 = ratioPrec + 1++infinity, notANumber :: Rational+infinity   = 1 :% 0+notANumber = 0 :% 0++-- Use :%, not % for Inf/NaN; the latter would+-- immediately lead to a runtime error, because it normalises.++-- | Forms the ratio of two integral numbers.+{-# SPECIALISE (%) :: Integer -> Integer -> Rational #-}+(%)                     :: (Integral a) => a -> a -> Ratio a++-- | Extract the numerator of the ratio in reduced form:+-- the numerator and denominator have no common factor and the denominator+-- is positive.+numerator       :: (Integral a) => Ratio a -> a++-- | Extract the denominator of the ratio in reduced form:+-- the numerator and denominator have no common factor and the denominator+-- is positive.+denominator     :: (Integral a) => Ratio a -> a+++-- | 'reduce' is a subsidiary function used only in this module.+-- It normalises a ratio by dividing both numerator and denominator by+-- their greatest common divisor.+reduce ::  (Integral a) => a -> a -> Ratio a+{-# SPECIALISE reduce :: Integer -> Integer -> Rational #-}+reduce _ 0              =  ratioZeroDenominatorError+reduce x y              =  (x `quot` d) :% (y `quot` d)+                           where d = gcd x y++x % y                   =  reduce (x * signum y) (abs y)++numerator   (x :% _)    =  x+denominator (_ :% y)    =  y++--------------------------------------------------------------+-- Standard numeric classes+--------------------------------------------------------------++class  (Num a, Ord a) => Real a  where+    -- | the rational equivalent of its real argument with full precision+    toRational          ::  a -> Rational++-- | Integral numbers, supporting integer division.+class  (Real a, Enum a) => Integral a  where+    -- | integer division truncated toward zero+    quot                :: a -> a -> a+    -- | integer remainder, satisfying+    --+    -- > (x `quot` y)*y + (x `rem` y) == x+    rem                 :: a -> a -> a+    -- | integer division truncated toward negative infinity+    div                 :: a -> a -> a+    -- | integer modulus, satisfying+    --+    -- > (x `div` y)*y + (x `mod` y) == x+    mod                 :: a -> a -> a+    -- | simultaneous 'quot' and 'rem'+    quotRem             :: a -> a -> (a,a)+    -- | simultaneous 'div' and 'mod'+    divMod              :: a -> a -> (a,a)+    -- | conversion to 'Integer'+    toInteger           :: a -> Integer++    {-# INLINE quot #-}+    {-# INLINE rem #-}+    {-# INLINE div #-}+    {-# INLINE mod #-}+    n `quot` d          =  q  where (q,_) = quotRem n d+    n `rem` d           =  r  where (_,r) = quotRem n d+    n `div` d           =  q  where (q,_) = divMod n d+    n `mod` d           =  r  where (_,r) = divMod n d++    divMod n d          =  if signum r == negate (signum d) then (q-1, r+d) else qr+                           where qr@(q,r) = quotRem n d++-- | Fractional numbers, supporting real division.+class  (Num a) => Fractional a  where+    {-# MINIMAL fromRational, (recip | (/)) #-}++    -- | fractional division+    (/)                 :: a -> a -> a+    -- | reciprocal fraction+    recip               :: a -> a+    -- | Conversion from a 'Rational' (that is @'Ratio' 'Integer'@).+    -- A floating literal stands for an application of 'fromRational'+    -- to a value of type 'Rational', so such literals have type+    -- @('Fractional' a) => a@.+    fromRational        :: Rational -> a++    {-# INLINE recip #-}+    {-# INLINE (/) #-}+    recip x             =  1 / x+    x / y               = x * recip y++-- | Extracting components of fractions.+class  (Real a, Fractional a) => RealFrac a  where+    -- | The function 'properFraction' takes a real fractional number @x@+    -- and returns a pair @(n,f)@ such that @x = n+f@, and:+    --+    -- * @n@ is an integral number with the same sign as @x@; and+    --+    -- * @f@ is a fraction with the same type and sign as @x@,+    --   and with absolute value less than @1@.+    --+    -- The default definitions of the 'ceiling', 'floor', 'truncate'+    -- and 'round' functions are in terms of 'properFraction'.+    properFraction      :: (Integral b) => a -> (b,a)+    -- | @'truncate' x@ returns the integer nearest @x@ between zero and @x@+    truncate            :: (Integral b) => a -> b+    -- | @'round' x@ returns the nearest integer to @x@;+    --   the even integer if @x@ is equidistant between two integers+    round               :: (Integral b) => a -> b+    -- | @'ceiling' x@ returns the least integer not less than @x@+    ceiling             :: (Integral b) => a -> b+    -- | @'floor' x@ returns the greatest integer not greater than @x@+    floor               :: (Integral b) => a -> b++    {-# INLINE truncate #-}+    truncate x          =  m  where (m,_) = properFraction x++    round x             =  let (n,r) = properFraction x+                               m     = if r < 0 then n - 1 else n + 1+                           in case signum (abs r - 0.5) of+                                -1 -> n+                                0  -> if even n then n else m+                                1  -> m+                                _  -> error "round default defn: Bad value"++    ceiling x           =  if r > 0 then n + 1 else n+                           where (n,r) = properFraction x++    floor x             =  if r < 0 then n - 1 else n+                           where (n,r) = properFraction x++-- These 'numeric' enumerations come straight from the Report++numericEnumFrom         :: (Fractional a) => a -> [a]+numericEnumFrom n       =  n `seq` (n : numericEnumFrom (n + 1))++numericEnumFromThen     :: (Fractional a) => a -> a -> [a]+numericEnumFromThen n m = n `seq` m `seq` (n : numericEnumFromThen m (m+m-n))++numericEnumFromTo       :: (Ord a, Fractional a) => a -> a -> [a]+numericEnumFromTo n m   = takeWhile (<= m + 1/2) (numericEnumFrom n)++numericEnumFromThenTo   :: (Ord a, Fractional a) => a -> a -> a -> [a]+numericEnumFromThenTo e1 e2 e3+    = takeWhile predicate (numericEnumFromThen e1 e2)+                                where+                                 mid = (e2 - e1) / 2+                                 predicate | e2 >= e1  = (<= e3 + mid)+                                           | otherwise = (>= e3 + mid)++--------------------------------------------------------------+-- Instances for Int+--------------------------------------------------------------++instance  Real Int  where+    toRational x        =  toInteger x :% 1++instance  Integral Int  where+    toInteger (I# i) = smallInteger i++    a `quot` b+     | b == 0                     = divZeroError+     | b == (-1) && a == minBound = overflowError -- Note [Order of tests]+                                                  -- in GHC.Int+     | otherwise                  =  a `quotInt` b++    a `rem` b+     | b == 0                     = divZeroError+       -- The quotRem CPU instruction fails for minBound `quotRem` -1,+       -- but minBound `rem` -1 is well-defined (0). We therefore+       -- special-case it.+     | b == (-1)                  = 0+     | otherwise                  =  a `remInt` b++    a `div` b+     | b == 0                     = divZeroError+     | b == (-1) && a == minBound = overflowError -- Note [Order of tests]+                                                  -- in GHC.Int+     | otherwise                  =  a `divInt` b++    a `mod` b+     | b == 0                     = divZeroError+       -- The divMod CPU instruction fails for minBound `divMod` -1,+       -- but minBound `mod` -1 is well-defined (0). We therefore+       -- special-case it.+     | b == (-1)                  = 0+     | otherwise                  =  a `modInt` b++    a `quotRem` b+     | b == 0                     = divZeroError+       -- Note [Order of tests] in GHC.Int+     | b == (-1) && a == minBound = (overflowError, 0)+     | otherwise                  =  a `quotRemInt` b++    a `divMod` b+     | b == 0                     = divZeroError+       -- Note [Order of tests] in GHC.Int+     | b == (-1) && a == minBound = (overflowError, 0)+     | otherwise                  =  a `divModInt` b++--------------------------------------------------------------+-- Instances for @Word@+--------------------------------------------------------------++instance Real Word where+    toRational x = toInteger x % 1++instance Integral Word where+    quot    (W# x#) y@(W# y#)+        | y /= 0                = W# (x# `quotWord#` y#)+        | otherwise             = divZeroError+    rem     (W# x#) y@(W# y#)+        | y /= 0                = W# (x# `remWord#` y#)+        | otherwise             = divZeroError+    div     (W# x#) y@(W# y#)+        | y /= 0                = W# (x# `quotWord#` y#)+        | otherwise             = divZeroError+    mod     (W# x#) y@(W# y#)+        | y /= 0                = W# (x# `remWord#` y#)+        | otherwise             = divZeroError+    quotRem (W# x#) y@(W# y#)+        | y /= 0                = case x# `quotRemWord#` y# of+                                  (# q, r #) ->+                                      (W# q, W# r)+        | otherwise             = divZeroError+    divMod  (W# x#) y@(W# y#)+        | y /= 0                = (W# (x# `quotWord#` y#), W# (x# `remWord#` y#))+        | otherwise             = divZeroError+    toInteger (W# x#)           = wordToInteger x#++--------------------------------------------------------------+-- Instances for Integer+--------------------------------------------------------------++instance  Real Integer  where+    toRational x        =  x :% 1++-- Note [Integer division constant folding]+-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+--+-- Constant folding of quot, rem, div, mod, divMod and quotRem for+-- Integer arguments depends crucially on inlining. Constant folding+-- rules defined in compiler/prelude/PrelRules.lhs trigger for+-- quotInteger, remInteger and so on. So if calls to quot, rem and so on+-- were not inlined the rules would not fire. The rules would also not+-- fire if calls to quotInteger and so on were inlined, but this does not+-- happen because they are all marked with NOINLINE pragma - see documentation+-- of integer-gmp or integer-simple.++instance  Integral Integer where+    toInteger n      = n++    {-# INLINE quot #-}+    _ `quot` 0 = divZeroError+    n `quot` d = n `quotInteger` d++    {-# INLINE rem #-}+    _ `rem` 0 = divZeroError+    n `rem` d = n `remInteger` d++    {-# INLINE div #-}+    _ `div` 0 = divZeroError+    n `div` d = n `divInteger` d++    {-# INLINE mod #-}+    _ `mod` 0 = divZeroError+    n `mod` d = n `modInteger` d++    {-# INLINE divMod #-}+    _ `divMod` 0 = divZeroError+    n `divMod` d = case n `divModInteger` d of+                     (# x, y #) -> (x, y)++    {-# INLINE quotRem #-}+    _ `quotRem` 0 = divZeroError+    n `quotRem` d = case n `quotRemInteger` d of+                      (# q, r #) -> (q, r)++--------------------------------------------------------------+-- Instances for @Ratio@+--------------------------------------------------------------++instance  (Integral a)  => Ord (Ratio a)  where+    {-# SPECIALIZE instance Ord Rational #-}+    (x:%y) <= (x':%y')  =  x * y' <= x' * y+    (x:%y) <  (x':%y')  =  x * y' <  x' * y++instance  (Integral a)  => Num (Ratio a)  where+    {-# SPECIALIZE instance Num Rational #-}+    (x:%y) + (x':%y')   =  reduce (x*y' + x'*y) (y*y')+    (x:%y) - (x':%y')   =  reduce (x*y' - x'*y) (y*y')+    (x:%y) * (x':%y')   =  reduce (x * x') (y * y')+    negate (x:%y)       =  (-x) :% y+    abs (x:%y)          =  abs x :% y+    signum (x:%_)       =  signum x :% 1+    fromInteger x       =  fromInteger x :% 1++{-# RULES "fromRational/id" fromRational = id :: Rational -> Rational #-}+instance  (Integral a)  => Fractional (Ratio a)  where+    {-# SPECIALIZE instance Fractional Rational #-}+    (x:%y) / (x':%y')   =  (x*y') % (y*x')+    recip (0:%_)        = ratioZeroDenominatorError+    recip (x:%y)+        | x < 0         = negate y :% negate x+        | otherwise     = y :% x+    fromRational (x:%y) =  fromInteger x % fromInteger y++instance  (Integral a)  => Real (Ratio a)  where+    {-# SPECIALIZE instance Real Rational #-}+    toRational (x:%y)   =  toInteger x :% toInteger y++instance  (Integral a)  => RealFrac (Ratio a)  where+    {-# SPECIALIZE instance RealFrac Rational #-}+    properFraction (x:%y) = (fromInteger (toInteger q), r:%y)+                          where (q,r) = quotRem x y++instance  (Integral a, Show a)  => Show (Ratio a)  where+    {-# SPECIALIZE instance Show Rational #-}+    showsPrec p (x:%y)  =  showParen (p > ratioPrec) $+                           showsPrec ratioPrec1 x .+                           showString " % " .+                           -- H98 report has spaces round the %+                           -- but we removed them [May 04]+                           -- and added them again for consistency with+                           -- Haskell 98 [Sep 08, #1920]+                           showsPrec ratioPrec1 y++instance  (Integral a)  => Enum (Ratio a)  where+    {-# SPECIALIZE instance Enum Rational #-}+    succ x              =  x + 1+    pred x              =  x - 1++    toEnum n            =  fromIntegral n :% 1+    fromEnum            =  fromInteger . truncate++    enumFrom            =  numericEnumFrom+    enumFromThen        =  numericEnumFromThen+    enumFromTo          =  numericEnumFromTo+    enumFromThenTo      =  numericEnumFromThenTo++--------------------------------------------------------------+-- Coercions+--------------------------------------------------------------++-- | general coercion from integral types+{-# NOINLINE [1] fromIntegral #-}+fromIntegral :: (Integral a, Num b) => a -> b+fromIntegral = fromInteger . toInteger++{-# RULES+"fromIntegral/Int->Int" fromIntegral = id :: Int -> Int+    #-}++{-# RULES+"fromIntegral/Int->Word"  fromIntegral = \(I# x#) -> W# (int2Word# x#)+"fromIntegral/Word->Int"  fromIntegral = \(W# x#) -> I# (word2Int# x#)+"fromIntegral/Word->Word" fromIntegral = id :: Word -> Word+    #-}++-- | general coercion to fractional types+realToFrac :: (Real a, Fractional b) => a -> b+{-# NOINLINE [1] realToFrac #-}+realToFrac = fromRational . toRational++--------------------------------------------------------------+-- Overloaded numeric functions+--------------------------------------------------------------++-- | Converts a possibly-negative 'Real' value to a string.+showSigned :: (Real a)+  => (a -> ShowS)       -- ^ a function that can show unsigned values+  -> Int                -- ^ the precedence of the enclosing context+  -> a                  -- ^ the value to show+  -> ShowS+showSigned showPos p x+   | x < 0     = showParen (p > 6) (showChar '-' . showPos (-x))+   | otherwise = showPos x++even, odd       :: (Integral a) => a -> Bool+even n          =  n `rem` 2 == 0+odd             =  not . even+{-# SPECIALISE even :: Int -> Bool #-}+{-# SPECIALISE odd  :: Int -> Bool #-}+{-# SPECIALISE even :: Integer -> Bool #-}+{-# SPECIALISE odd  :: Integer -> Bool #-}++-------------------------------------------------------+-- | raise a number to a non-negative integral power+{-# SPECIALISE [1] (^) ::+        Integer -> Integer -> Integer,+        Integer -> Int -> Integer,+        Int -> Int -> Int #-}+{-# INLINABLE [1] (^) #-}    -- See Note [Inlining (^)]+(^) :: (Num a, Integral b) => a -> b -> a+x0 ^ y0 | y0 < 0    = error "Negative exponent"+        | y0 == 0   = 1+        | otherwise = f x0 y0+    where -- f : x0 ^ y0 = x ^ y+          f x y | even y    = f (x * x) (y `quot` 2)+                | y == 1    = x+                | otherwise = g (x * x) ((y - 1) `quot` 2) x+          -- g : x0 ^ y0 = (x ^ y) * z+          g x y z | even y = g (x * x) (y `quot` 2) z+                  | y == 1 = x * z+                  | otherwise = g (x * x) ((y - 1) `quot` 2) (x * z)++-- | raise a number to an integral power+(^^)            :: (Fractional a, Integral b) => a -> b -> a+{-# INLINABLE [1] (^^) #-}         -- See Note [Inlining (^)+x ^^ n          =  if n >= 0 then x^n else recip (x^(negate n))++{- Note [Inlining (^)+   ~~~~~~~~~~~~~~~~~~~~~+   The INLINABLE pragma allows (^) to be specialised at its call sites.+   If it is called repeatedly at the same type, that can make a huge+   difference, because of those constants which can be repeatedly+   calculated.++   Currently the fromInteger calls are not floated because we get+             \d1 d2 x y -> blah+   after the gentle round of simplification. -}++{- Rules for powers with known small exponent+    see #5237+    For small exponents, (^) is inefficient compared to manually+    expanding the multiplication tree.+    Here, rules for the most common exponent types are given.+    The range of exponents for which rules are given is quite+    arbitrary and kept small to not unduly increase the number of rules.+    0 and 1 are excluded based on the assumption that nobody would+    write x^0 or x^1 in code and the cases where an exponent could+    be statically resolved to 0 or 1 are rare.++    It might be desirable to have corresponding rules also for+    exponents of other types, in particular Word, but we can't+    have those rules here (importing GHC.Word or GHC.Int would+    create a cyclic module dependency), and it's doubtful they+    would fire, since the exponents of other types tend to get+    floated out before the rule has a chance to fire.++    Also desirable would be rules for (^^), but I haven't managed+    to get those to fire.++    Note: Trying to save multiplications by sharing the square for+    exponents 4 and 5 does not save time, indeed, for Double, it is+    up to twice slower, so the rules contain flat sequences of+    multiplications.+-}++{-# RULES+"^2/Int"        forall x. x ^ (2 :: Int) = let u = x in u*u+"^3/Int"        forall x. x ^ (3 :: Int) = let u = x in u*u*u+"^4/Int"        forall x. x ^ (4 :: Int) = let u = x in u*u*u*u+"^5/Int"        forall x. x ^ (5 :: Int) = let u = x in u*u*u*u*u+"^2/Integer"    forall x. x ^ (2 :: Integer) = let u = x in u*u+"^3/Integer"    forall x. x ^ (3 :: Integer) = let u = x in u*u*u+"^4/Integer"    forall x. x ^ (4 :: Integer) = let u = x in u*u*u*u+"^5/Integer"    forall x. x ^ (5 :: Integer) = let u = x in u*u*u*u*u+  #-}++-------------------------------------------------------+-- Special power functions for Rational+--+-- see #4337+--+-- Rationale:+-- For a legitimate Rational (n :% d), the numerator and denominator are+-- coprime, i.e. they have no common prime factor.+-- Therefore all powers (n ^ a) and (d ^ b) are also coprime, so it is+-- not necessary to compute the greatest common divisor, which would be+-- done in the default implementation at each multiplication step.+-- Since exponentiation quickly leads to very large numbers and+-- calculation of gcds is generally very slow for large numbers,+-- avoiding the gcd leads to an order of magnitude speedup relatively+-- soon (and an asymptotic improvement overall).+--+-- Note:+-- We cannot use these functions for general Ratio a because that would+-- change results in a multitude of cases.+-- The cause is that if a and b are coprime, their remainders by any+-- positive modulus generally aren't, so in the default implementation+-- reduction occurs.+--+-- Example:+-- (17 % 3) ^ 3 :: Ratio Word8+-- Default:+-- (17 % 3) ^ 3 = ((17 % 3) ^ 2) * (17 % 3)+--              = ((289 `mod` 256) % 9) * (17 % 3)+--              = (33 % 9) * (17 % 3)+--              = (11 % 3) * (17 % 3)+--              = (187 % 9)+-- But:+-- ((17^3) `mod` 256) % (3^3)   = (4913 `mod` 256) % 27+--                              = 49 % 27+--+-- TODO:+-- Find out whether special-casing for numerator, denominator or+-- exponent = 1 (or -1, where that may apply) gains something.++-- Special version of (^) for Rational base+{-# RULES "(^)/Rational"    (^) = (^%^) #-}+(^%^)           :: Integral a => Rational -> a -> Rational+(n :% d) ^%^ e+    | e < 0     = error "Negative exponent"+    | e == 0    = 1 :% 1+    | otherwise = (n ^ e) :% (d ^ e)++-- Special version of (^^) for Rational base+{-# RULES "(^^)/Rational"   (^^) = (^^%^^) #-}+(^^%^^)         :: Integral a => Rational -> a -> Rational+(n :% d) ^^%^^ e+    | e > 0     = (n ^ e) :% (d ^ e)+    | e == 0    = 1 :% 1+    | n > 0     = (d ^ (negate e)) :% (n ^ (negate e))+    | n == 0    = ratioZeroDenominatorError+    | otherwise = let nn = d ^ (negate e)+                      dd = (negate n) ^ (negate e)+                  in if even e then (nn :% dd) else (negate nn :% dd)++-------------------------------------------------------+-- | @'gcd' x y@ is the non-negative factor of both @x@ and @y@ of which+-- every common factor of @x@ and @y@ is also a factor; for example+-- @'gcd' 4 2 = 2@, @'gcd' (-4) 6 = 2@, @'gcd' 0 4@ = @4@. @'gcd' 0 0@ = @0@.+-- (That is, the common divisor that is \"greatest\" in the divisibility+-- preordering.)+--+-- Note: Since for signed fixed-width integer types, @'abs' 'minBound' < 0@,+-- the result may be negative if one of the arguments is @'minBound'@ (and+-- necessarily is if the other is @0@ or @'minBound'@) for such types.+gcd             :: (Integral a) => a -> a -> a+{-# NOINLINE [1] gcd #-}+gcd x y         =  gcd' (abs x) (abs y)+                   where gcd' a 0  =  a+                         gcd' a b  =  gcd' b (a `rem` b)++-- | @'lcm' x y@ is the smallest positive integer that both @x@ and @y@ divide.+lcm             :: (Integral a) => a -> a -> a+{-# SPECIALISE lcm :: Int -> Int -> Int #-}+{-# NOINLINE [1] lcm #-}+lcm _ 0         =  0+lcm 0 _         =  0+lcm x y         =  abs ((x `quot` (gcd x y)) * y)++#ifdef OPTIMISE_INTEGER_GCD_LCM+{-# RULES+"gcd/Int->Int->Int"             gcd = gcdInt'+"gcd/Integer->Integer->Integer" gcd = gcdInteger+"lcm/Integer->Integer->Integer" lcm = lcmInteger+ #-}++gcdInt' :: Int -> Int -> Int+gcdInt' (I# x) (I# y) = I# (gcdInt x y)++#if MIN_VERSION_integer_gmp(1,0,0)+{-# RULES+"gcd/Word->Word->Word"          gcd = gcdWord'+ #-}++gcdWord' :: Word -> Word -> Word+gcdWord' (W# x) (W# y) = W# (gcdWord x y)+#endif+#endif++integralEnumFrom :: (Integral a, Bounded a) => a -> [a]+integralEnumFrom n = map fromInteger [toInteger n .. toInteger (maxBound `asTypeOf` n)]++integralEnumFromThen :: (Integral a, Bounded a) => a -> a -> [a]+integralEnumFromThen n1 n2+  | i_n2 >= i_n1  = map fromInteger [i_n1, i_n2 .. toInteger (maxBound `asTypeOf` n1)]+  | otherwise     = map fromInteger [i_n1, i_n2 .. toInteger (minBound `asTypeOf` n1)]+  where+    i_n1 = toInteger n1+    i_n2 = toInteger n2++integralEnumFromTo :: Integral a => a -> a -> [a]+integralEnumFromTo n m = map fromInteger [toInteger n .. toInteger m]++integralEnumFromThenTo :: Integral a => a -> a -> a -> [a]+integralEnumFromThenTo n1 n2 m+  = map fromInteger [toInteger n1, toInteger n2 .. toInteger m]
− GHC/Real.lhs
@@ -1,729 +0,0 @@-\begin{code}-{-# LANGUAGE Trustworthy #-}-{-# LANGUAGE CPP, NoImplicitPrelude, MagicHash, UnboxedTuples, BangPatterns #-}-{-# OPTIONS_GHC -fno-warn-orphans #-}-{-# OPTIONS_HADDOCK hide #-}--------------------------------------------------------------------------------- |--- Module      :  GHC.Real--- Copyright   :  (c) The University of Glasgow, 1994-2002--- License     :  see libraries/base/LICENSE------ Maintainer  :  cvs-ghc@haskell.org--- Stability   :  internal--- Portability :  non-portable (GHC Extensions)------ The types 'Ratio' and 'Rational', and the classes 'Real', 'Fractional',--- 'Integral', and 'RealFrac'.-----------------------------------------------------------------------------------module GHC.Real where--import GHC.Base-import GHC.Num-import GHC.List-import GHC.Enum-import GHC.Show-import {-# SOURCE #-} GHC.Exception( divZeroException, overflowException, ratioZeroDenomException )--#ifdef OPTIMISE_INTEGER_GCD_LCM-import GHC.Integer.GMP.Internals-#endif--infixr 8  ^, ^^-infixl 7  /, `quot`, `rem`, `div`, `mod`-infixl 7  %--default ()              -- Double isn't available yet,-                        -- and we shouldn't be using defaults anyway-\end{code}---%*********************************************************-%*                                                      *-       Divide by zero and arithmetic overflow-%*                                                      *-%*********************************************************--We put them here because they are needed relatively early-in the libraries before the Exception type has been defined yet.--\begin{code}-{-# NOINLINE divZeroError #-}-divZeroError :: a-divZeroError = raise# divZeroException--{-# NOINLINE ratioZeroDenominatorError #-}-ratioZeroDenominatorError :: a-ratioZeroDenominatorError = raise# ratioZeroDenomException--{-# NOINLINE overflowError #-}-overflowError :: a-overflowError = raise# overflowException-\end{code}--%*********************************************************-%*                                                      *-\subsection{The @Ratio@ and @Rational@ types}-%*                                                      *-%*********************************************************--\begin{code}--- | Rational numbers, with numerator and denominator of some 'Integral' type.-data  Ratio a = !a :% !a  deriving (Eq)---- | Arbitrary-precision rational numbers, represented as a ratio of--- two 'Integer' values.  A rational number may be constructed using--- the '%' operator.-type  Rational          =  Ratio Integer--ratioPrec, ratioPrec1 :: Int-ratioPrec  = 7  -- Precedence of ':%' constructor-ratioPrec1 = ratioPrec + 1--infinity, notANumber :: Rational-infinity   = 1 :% 0-notANumber = 0 :% 0---- Use :%, not % for Inf/NaN; the latter would--- immediately lead to a runtime error, because it normalises.-\end{code}---\begin{code}--- | Forms the ratio of two integral numbers.-{-# SPECIALISE (%) :: Integer -> Integer -> Rational #-}-(%)                     :: (Integral a) => a -> a -> Ratio a---- | Extract the numerator of the ratio in reduced form:--- the numerator and denominator have no common factor and the denominator--- is positive.-numerator       :: (Integral a) => Ratio a -> a---- | Extract the denominator of the ratio in reduced form:--- the numerator and denominator have no common factor and the denominator--- is positive.-denominator     :: (Integral a) => Ratio a -> a-\end{code}--\tr{reduce} is a subsidiary function used only in this module .-It normalises a ratio by dividing both numerator and denominator by-their greatest common divisor.--\begin{code}-reduce ::  (Integral a) => a -> a -> Ratio a-{-# SPECIALISE reduce :: Integer -> Integer -> Rational #-}-reduce _ 0              =  ratioZeroDenominatorError-reduce x y              =  (x `quot` d) :% (y `quot` d)-                           where d = gcd x y-\end{code}--\begin{code}-x % y                   =  reduce (x * signum y) (abs y)--numerator   (x :% _)    =  x-denominator (_ :% y)    =  y-\end{code}---%*********************************************************-%*                                                      *-\subsection{Standard numeric classes}-%*                                                      *-%*********************************************************--\begin{code}-class  (Num a, Ord a) => Real a  where-    -- | the rational equivalent of its real argument with full precision-    toRational          ::  a -> Rational---- | Integral numbers, supporting integer division.------ Minimal complete definition: 'quotRem' and 'toInteger'-class  (Real a, Enum a) => Integral a  where-    -- | integer division truncated toward zero-    quot                :: a -> a -> a-    -- | integer remainder, satisfying-    ---    -- > (x `quot` y)*y + (x `rem` y) == x-    rem                 :: a -> a -> a-    -- | integer division truncated toward negative infinity-    div                 :: a -> a -> a-    -- | integer modulus, satisfying-    ---    -- > (x `div` y)*y + (x `mod` y) == x-    mod                 :: a -> a -> a-    -- | simultaneous 'quot' and 'rem'-    quotRem             :: a -> a -> (a,a)-    -- | simultaneous 'div' and 'mod'-    divMod              :: a -> a -> (a,a)-    -- | conversion to 'Integer'-    toInteger           :: a -> Integer--    {-# INLINE quot #-}-    {-# INLINE rem #-}-    {-# INLINE div #-}-    {-# INLINE mod #-}-    n `quot` d          =  q  where (q,_) = quotRem n d-    n `rem` d           =  r  where (_,r) = quotRem n d-    n `div` d           =  q  where (q,_) = divMod n d-    n `mod` d           =  r  where (_,r) = divMod n d--    divMod n d          =  if signum r == negate (signum d) then (q-1, r+d) else qr-                           where qr@(q,r) = quotRem n d---- | Fractional numbers, supporting real division.------ Minimal complete definition: 'fromRational' and ('recip' or @('/')@)-class  (Num a) => Fractional a  where-    -- | fractional division-    (/)                 :: a -> a -> a-    -- | reciprocal fraction-    recip               :: a -> a-    -- | Conversion from a 'Rational' (that is @'Ratio' 'Integer'@).-    -- A floating literal stands for an application of 'fromRational'-    -- to a value of type 'Rational', so such literals have type-    -- @('Fractional' a) => a@.-    fromRational        :: Rational -> a--    {-# INLINE recip #-}-    {-# INLINE (/) #-}-    recip x             =  1 / x-    x / y               = x * recip y-    {-# MINIMAL fromRational, (recip | (/)) #-}---- | Extracting components of fractions.------ Minimal complete definition: 'properFraction'-class  (Real a, Fractional a) => RealFrac a  where-    -- | The function 'properFraction' takes a real fractional number @x@-    -- and returns a pair @(n,f)@ such that @x = n+f@, and:-    ---    -- * @n@ is an integral number with the same sign as @x@; and-    ---    -- * @f@ is a fraction with the same type and sign as @x@,-    --   and with absolute value less than @1@.-    ---    -- The default definitions of the 'ceiling', 'floor', 'truncate'-    -- and 'round' functions are in terms of 'properFraction'.-    properFraction      :: (Integral b) => a -> (b,a)-    -- | @'truncate' x@ returns the integer nearest @x@ between zero and @x@-    truncate            :: (Integral b) => a -> b-    -- | @'round' x@ returns the nearest integer to @x@;-    --   the even integer if @x@ is equidistant between two integers-    round               :: (Integral b) => a -> b-    -- | @'ceiling' x@ returns the least integer not less than @x@-    ceiling             :: (Integral b) => a -> b-    -- | @'floor' x@ returns the greatest integer not greater than @x@-    floor               :: (Integral b) => a -> b--    {-# INLINE truncate #-}-    truncate x          =  m  where (m,_) = properFraction x--    round x             =  let (n,r) = properFraction x-                               m     = if r < 0 then n - 1 else n + 1-                           in case signum (abs r - 0.5) of-                                -1 -> n-                                0  -> if even n then n else m-                                1  -> m-                                _  -> error "round default defn: Bad value"--    ceiling x           =  if r > 0 then n + 1 else n-                           where (n,r) = properFraction x--    floor x             =  if r < 0 then n - 1 else n-                           where (n,r) = properFraction x-\end{code}---These 'numeric' enumerations come straight from the Report--\begin{code}-numericEnumFrom         :: (Fractional a) => a -> [a]-numericEnumFrom n	=  n `seq` (n : numericEnumFrom (n + 1))--numericEnumFromThen     :: (Fractional a) => a -> a -> [a]-numericEnumFromThen n m	= n `seq` m `seq` (n : numericEnumFromThen m (m+m-n))--numericEnumFromTo       :: (Ord a, Fractional a) => a -> a -> [a]-numericEnumFromTo n m   = takeWhile (<= m + 1/2) (numericEnumFrom n)--numericEnumFromThenTo   :: (Ord a, Fractional a) => a -> a -> a -> [a]-numericEnumFromThenTo e1 e2 e3-    = takeWhile predicate (numericEnumFromThen e1 e2)-                                where-                                 mid = (e2 - e1) / 2-                                 predicate | e2 >= e1  = (<= e3 + mid)-                                           | otherwise = (>= e3 + mid)-\end{code}---%*********************************************************-%*                                                      *-\subsection{Instances for @Int@}-%*                                                      *-%*********************************************************--\begin{code}-instance  Real Int  where-    toRational x        =  toInteger x :% 1--instance  Integral Int  where-    toInteger (I# i) = smallInteger i--    a `quot` b-     | b == 0                     = divZeroError-     | b == (-1) && a == minBound = overflowError -- Note [Order of tests]-                                                  -- in GHC.Int-     | otherwise                  =  a `quotInt` b--    a `rem` b-     | b == 0                     = divZeroError-       -- The quotRem CPU instruction fails for minBound `quotRem` -1,-       -- but minBound `rem` -1 is well-defined (0). We therefore-       -- special-case it.-     | b == (-1)                  = 0-     | otherwise                  =  a `remInt` b--    a `div` b-     | b == 0                     = divZeroError-     | b == (-1) && a == minBound = overflowError -- Note [Order of tests]-                                                  -- in GHC.Int-     | otherwise                  =  a `divInt` b--    a `mod` b-     | b == 0                     = divZeroError-       -- The divMod CPU instruction fails for minBound `divMod` -1,-       -- but minBound `mod` -1 is well-defined (0). We therefore-       -- special-case it.-     | b == (-1)                  = 0-     | otherwise                  =  a `modInt` b--    a `quotRem` b-     | b == 0                     = divZeroError-       -- Note [Order of tests] in GHC.Int-     | b == (-1) && a == minBound = (overflowError, 0)-     | otherwise                  =  a `quotRemInt` b--    a `divMod` b-     | b == 0                     = divZeroError-       -- Note [Order of tests] in GHC.Int-     | b == (-1) && a == minBound = (overflowError, 0)-     | otherwise                  =  a `divModInt` b-\end{code}---%*********************************************************-%*                                                      *-\subsection{Instances for @Word@}-%*                                                      *-%*********************************************************--\begin{code}-instance Real Word where-    toRational x = toInteger x % 1--instance Integral Word where-    quot    (W# x#) y@(W# y#)-        | y /= 0                = W# (x# `quotWord#` y#)-        | otherwise             = divZeroError-    rem     (W# x#) y@(W# y#)-        | y /= 0                = W# (x# `remWord#` y#)-        | otherwise             = divZeroError-    div     (W# x#) y@(W# y#)-        | y /= 0                = W# (x# `quotWord#` y#)-        | otherwise             = divZeroError-    mod     (W# x#) y@(W# y#)-        | y /= 0                = W# (x# `remWord#` y#)-        | otherwise             = divZeroError-    quotRem (W# x#) y@(W# y#)-        | y /= 0                = case x# `quotRemWord#` y# of-                                  (# q, r #) ->-                                      (W# q, W# r)-        | otherwise             = divZeroError-    divMod  (W# x#) y@(W# y#)-        | y /= 0                = (W# (x# `quotWord#` y#), W# (x# `remWord#` y#))-        | otherwise             = divZeroError-    toInteger (W# x#)-        | isTrue# (i# >=# 0#)   = smallInteger i#-        | otherwise             = wordToInteger x#-        where-        !i# = word2Int# x#--instance Enum Word where-    succ x-        | x /= maxBound = x + 1-        | otherwise     = succError "Word"-    pred x-        | x /= minBound = x - 1-        | otherwise     = predError "Word"-    toEnum i@(I# i#)-        | i >= 0        = W# (int2Word# i#)-        | otherwise     = toEnumError "Word" i (minBound::Word, maxBound::Word)-    fromEnum x@(W# x#)-        | x <= fromIntegral (maxBound::Int)-                        = I# (word2Int# x#)-        | otherwise     = fromEnumError "Word" x-    enumFrom            = integralEnumFrom-    enumFromThen        = integralEnumFromThen-    enumFromTo          = integralEnumFromTo-    enumFromThenTo      = integralEnumFromThenTo-\end{code}---%*********************************************************-%*                                                      *-\subsection{Instances for @Integer@}-%*                                                      *-%*********************************************************--\begin{code}-instance  Real Integer  where-    toRational x        =  x :% 1---- Note [Integer division constant folding]--- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~------ Constant folding of quot, rem, div, mod, divMod and quotRem for--- Integer arguments depends crucially on inlining. Constant folding--- rules defined in compiler/prelude/PrelRules.lhs trigger for--- quotInteger, remInteger and so on. So if calls to quot, rem and so on--- were not inlined the rules would not fire. The rules would also not--- fire if calls to quotInteger and so on were inlined, but this does not--- happen because they are all marked with NOINLINE pragma - see documentation--- of integer-gmp or integer-simple.--instance  Integral Integer where-    toInteger n      = n--    {-# INLINE quot #-}-    _ `quot` 0 = divZeroError-    n `quot` d = n `quotInteger` d--    {-# INLINE rem #-}-    _ `rem` 0 = divZeroError-    n `rem` d = n `remInteger` d--    {-# INLINE div #-}-    _ `div` 0 = divZeroError-    n `div` d = n `divInteger` d--    {-# INLINE mod #-}-    _ `mod` 0 = divZeroError-    n `mod` d = n `modInteger` d--    {-# INLINE divMod #-}-    _ `divMod` 0 = divZeroError-    n `divMod` d = case n `divModInteger` d of-                     (# x, y #) -> (x, y)--    {-# INLINE quotRem #-}-    _ `quotRem` 0 = divZeroError-    n `quotRem` d = case n `quotRemInteger` d of-                      (# q, r #) -> (q, r)-\end{code}---%*********************************************************-%*                                                      *-\subsection{Instances for @Ratio@}-%*                                                      *-%*********************************************************--\begin{code}-instance  (Integral a)  => Ord (Ratio a)  where-    {-# SPECIALIZE instance Ord Rational #-}-    (x:%y) <= (x':%y')  =  x * y' <= x' * y-    (x:%y) <  (x':%y')  =  x * y' <  x' * y--instance  (Integral a)  => Num (Ratio a)  where-    {-# SPECIALIZE instance Num Rational #-}-    (x:%y) + (x':%y')   =  reduce (x*y' + x'*y) (y*y')-    (x:%y) - (x':%y')   =  reduce (x*y' - x'*y) (y*y')-    (x:%y) * (x':%y')   =  reduce (x * x') (y * y')-    negate (x:%y)       =  (-x) :% y-    abs (x:%y)          =  abs x :% y-    signum (x:%_)       =  signum x :% 1-    fromInteger x       =  fromInteger x :% 1--{-# RULES "fromRational/id" fromRational = id :: Rational -> Rational #-}-instance  (Integral a)  => Fractional (Ratio a)  where-    {-# SPECIALIZE instance Fractional Rational #-}-    (x:%y) / (x':%y')   =  (x*y') % (y*x')-    recip (0:%_)        = ratioZeroDenominatorError-    recip (x:%y)-        | x < 0         = negate y :% negate x-        | otherwise     = y :% x-    fromRational (x:%y) =  fromInteger x % fromInteger y--instance  (Integral a)  => Real (Ratio a)  where-    {-# SPECIALIZE instance Real Rational #-}-    toRational (x:%y)   =  toInteger x :% toInteger y--instance  (Integral a)  => RealFrac (Ratio a)  where-    {-# SPECIALIZE instance RealFrac Rational #-}-    properFraction (x:%y) = (fromInteger (toInteger q), r:%y)-                          where (q,r) = quotRem x y--instance  (Integral a, Show a)  => Show (Ratio a)  where-    {-# SPECIALIZE instance Show Rational #-}-    showsPrec p (x:%y)  =  showParen (p > ratioPrec) $-                           showsPrec ratioPrec1 x .-                           showString " % " .-                           -- H98 report has spaces round the %-                           -- but we removed them [May 04]-                           -- and added them again for consistency with-                           -- Haskell 98 [Sep 08, #1920]-                           showsPrec ratioPrec1 y--instance  (Integral a)  => Enum (Ratio a)  where-    {-# SPECIALIZE instance Enum Rational #-}-    succ x              =  x + 1-    pred x              =  x - 1--    toEnum n            =  fromIntegral n :% 1-    fromEnum            =  fromInteger . truncate--    enumFrom            =  numericEnumFrom-    enumFromThen        =  numericEnumFromThen-    enumFromTo          =  numericEnumFromTo-    enumFromThenTo      =  numericEnumFromThenTo-\end{code}---%*********************************************************-%*                                                      *-\subsection{Coercions}-%*                                                      *-%*********************************************************--\begin{code}--- | general coercion from integral types-{-# NOINLINE [1] fromIntegral #-}-fromIntegral :: (Integral a, Num b) => a -> b-fromIntegral = fromInteger . toInteger--{-# RULES-"fromIntegral/Int->Int" fromIntegral = id :: Int -> Int-    #-}--{-# RULES-"fromIntegral/Int->Word"  fromIntegral = \(I# x#) -> W# (int2Word# x#)-"fromIntegral/Word->Int"  fromIntegral = \(W# x#) -> I# (word2Int# x#)-"fromIntegral/Word->Word" fromIntegral = id :: Word -> Word-    #-}---- | general coercion to fractional types-realToFrac :: (Real a, Fractional b) => a -> b-{-# NOINLINE [1] realToFrac #-}-realToFrac = fromRational . toRational-\end{code}--%*********************************************************-%*                                                      *-\subsection{Overloaded numeric functions}-%*                                                      *-%*********************************************************--\begin{code}--- | Converts a possibly-negative 'Real' value to a string.-showSigned :: (Real a)-  => (a -> ShowS)       -- ^ a function that can show unsigned values-  -> Int                -- ^ the precedence of the enclosing context-  -> a                  -- ^ the value to show-  -> ShowS-showSigned showPos p x-   | x < 0     = showParen (p > 6) (showChar '-' . showPos (-x))-   | otherwise = showPos x--even, odd       :: (Integral a) => a -> Bool-even n          =  n `rem` 2 == 0-odd             =  not . even------------------------------------------------------------ | raise a number to a non-negative integral power-{-# SPECIALISE [1] (^) ::-        Integer -> Integer -> Integer,-        Integer -> Int -> Integer,-        Int -> Int -> Int #-}-{-# INLINABLE [1] (^) #-}    -- See Note [Inlining (^)]-(^) :: (Num a, Integral b) => a -> b -> a-x0 ^ y0 | y0 < 0    = error "Negative exponent"-        | y0 == 0   = 1-        | otherwise = f x0 y0-    where -- f : x0 ^ y0 = x ^ y-          f x y | even y    = f (x * x) (y `quot` 2)-                | y == 1    = x-                | otherwise = g (x * x) ((y - 1) `quot` 2) x-          -- g : x0 ^ y0 = (x ^ y) * z-          g x y z | even y = g (x * x) (y `quot` 2) z-                  | y == 1 = x * z-                  | otherwise = g (x * x) ((y - 1) `quot` 2) (x * z)---- | raise a number to an integral power-(^^)            :: (Fractional a, Integral b) => a -> b -> a-{-# INLINABLE [1] (^^) #-}         -- See Note [Inlining (^)-x ^^ n          =  if n >= 0 then x^n else recip (x^(negate n))--{- Note [Inlining (^)-   ~~~~~~~~~~~~~~~~~~~~~-   The INLINABLE pragma allows (^) to be specialised at its call sites.-   If it is called repeatedly at the same type, that can make a huge-   difference, because of those constants which can be repeatedly-   calculated.--   Currently the fromInteger calls are not floated because we get-             \d1 d2 x y -> blah-   after the gentle round of simplification. -}--{- Rules for powers with known small exponent-    see #5237-    For small exponents, (^) is inefficient compared to manually-    expanding the multiplication tree.-    Here, rules for the most common exponent types are given.-    The range of exponents for which rules are given is quite-    arbitrary and kept small to not unduly increase the number of rules.-    0 and 1 are excluded based on the assumption that nobody would-    write x^0 or x^1 in code and the cases where an exponent could-    be statically resolved to 0 or 1 are rare.--    It might be desirable to have corresponding rules also for-    exponents of other types, in particular Word, but we can't-    have those rules here (importing GHC.Word or GHC.Int would-    create a cyclic module dependency), and it's doubtful they-    would fire, since the exponents of other types tend to get-    floated out before the rule has a chance to fire.--    Also desirable would be rules for (^^), but I haven't managed-    to get those to fire.--    Note: Trying to save multiplications by sharing the square for-    exponents 4 and 5 does not save time, indeed, for Double, it is-    up to twice slower, so the rules contain flat sequences of-    multiplications.--}--{-# RULES-"^2/Int"        forall x. x ^ (2 :: Int) = let u = x in u*u-"^3/Int"        forall x. x ^ (3 :: Int) = let u = x in u*u*u-"^4/Int"        forall x. x ^ (4 :: Int) = let u = x in u*u*u*u-"^5/Int"        forall x. x ^ (5 :: Int) = let u = x in u*u*u*u*u-"^2/Integer"    forall x. x ^ (2 :: Integer) = let u = x in u*u-"^3/Integer"    forall x. x ^ (3 :: Integer) = let u = x in u*u*u-"^4/Integer"    forall x. x ^ (4 :: Integer) = let u = x in u*u*u*u-"^5/Integer"    forall x. x ^ (5 :: Integer) = let u = x in u*u*u*u*u-  #-}------------------------------------------------------------ Special power functions for Rational------ see #4337------ Rationale:--- For a legitimate Rational (n :% d), the numerator and denominator are--- coprime, i.e. they have no common prime factor.--- Therefore all powers (n ^ a) and (d ^ b) are also coprime, so it is--- not necessary to compute the greatest common divisor, which would be--- done in the default implementation at each multiplication step.--- Since exponentiation quickly leads to very large numbers and--- calculation of gcds is generally very slow for large numbers,--- avoiding the gcd leads to an order of magnitude speedup relatively--- soon (and an asymptotic improvement overall).------ Note:--- We cannot use these functions for general Ratio a because that would--- change results in a multitude of cases.--- The cause is that if a and b are coprime, their remainders by any--- positive modulus generally aren't, so in the default implementation--- reduction occurs.------ Example:--- (17 % 3) ^ 3 :: Ratio Word8--- Default:--- (17 % 3) ^ 3 = ((17 % 3) ^ 2) * (17 % 3)---              = ((289 `mod` 256) % 9) * (17 % 3)---              = (33 % 9) * (17 % 3)---              = (11 % 3) * (17 % 3)---              = (187 % 9)--- But:--- ((17^3) `mod` 256) % (3^3)   = (4913 `mod` 256) % 27---                              = 49 % 27------ TODO:--- Find out whether special-casing for numerator, denominator or--- exponent = 1 (or -1, where that may apply) gains something.---- Special version of (^) for Rational base-{-# RULES "(^)/Rational"    (^) = (^%^) #-}-(^%^)           :: Integral a => Rational -> a -> Rational-(n :% d) ^%^ e-    | e < 0     = error "Negative exponent"-    | e == 0    = 1 :% 1-    | otherwise = (n ^ e) :% (d ^ e)---- Special version of (^^) for Rational base-{-# RULES "(^^)/Rational"   (^^) = (^^%^^) #-}-(^^%^^)         :: Integral a => Rational -> a -> Rational-(n :% d) ^^%^^ e-    | e > 0     = (n ^ e) :% (d ^ e)-    | e == 0    = 1 :% 1-    | n > 0     = (d ^ (negate e)) :% (n ^ (negate e))-    | n == 0    = ratioZeroDenominatorError-    | otherwise = let nn = d ^ (negate e)-                      dd = (negate n) ^ (negate e)-                  in if even e then (nn :% dd) else (negate nn :% dd)------------------------------------------------------------ | @'gcd' x y@ is the non-negative factor of both @x@ and @y@ of which--- every common factor of @x@ and @y@ is also a factor; for example--- @'gcd' 4 2 = 2@, @'gcd' (-4) 6 = 2@, @'gcd' 0 4@ = @4@. @'gcd' 0 0@ = @0@.--- (That is, the common divisor that is \"greatest\" in the divisibility--- preordering.)------ Note: Since for signed fixed-width integer types, @'abs' 'minBound' < 0@,--- the result may be negative if one of the arguments is @'minBound'@ (and--- necessarily is if the other is @0@ or @'minBound'@) for such types.-gcd             :: (Integral a) => a -> a -> a-{-# NOINLINE [1] gcd #-}-gcd x y         =  gcd' (abs x) (abs y)-                   where gcd' a 0  =  a-                         gcd' a b  =  gcd' b (a `rem` b)---- | @'lcm' x y@ is the smallest positive integer that both @x@ and @y@ divide.-lcm             :: (Integral a) => a -> a -> a-{-# SPECIALISE lcm :: Int -> Int -> Int #-}-{-# NOINLINE [1] lcm #-}-lcm _ 0         =  0-lcm 0 _         =  0-lcm x y         =  abs ((x `quot` (gcd x y)) * y)--#ifdef OPTIMISE_INTEGER_GCD_LCM-{-# RULES-"gcd/Int->Int->Int"             gcd = gcdInt'-"gcd/Integer->Integer->Integer" gcd = gcdInteger-"lcm/Integer->Integer->Integer" lcm = lcmInteger- #-}--gcdInt' :: Int -> Int -> Int-gcdInt' (I# x) (I# y) = I# (gcdInt x y)-#endif--integralEnumFrom :: (Integral a, Bounded a) => a -> [a]-integralEnumFrom n = map fromInteger [toInteger n .. toInteger (maxBound `asTypeOf` n)]--integralEnumFromThen :: (Integral a, Bounded a) => a -> a -> [a]-integralEnumFromThen n1 n2-  | i_n2 >= i_n1  = map fromInteger [i_n1, i_n2 .. toInteger (maxBound `asTypeOf` n1)]-  | otherwise     = map fromInteger [i_n1, i_n2 .. toInteger (minBound `asTypeOf` n1)]-  where-    i_n1 = toInteger n1-    i_n2 = toInteger n2--integralEnumFromTo :: Integral a => a -> a -> [a]-integralEnumFromTo n m = map fromInteger [toInteger n .. toInteger m]--integralEnumFromThenTo :: Integral a => a -> a -> a -> [a]-integralEnumFromThenTo n1 n2 m-  = map fromInteger [toInteger n1, toInteger n2 .. toInteger m]-\end{code}
+ GHC/ST.hs view
@@ -0,0 +1,165 @@+{-# LANGUAGE Unsafe #-}+{-# LANGUAGE NoImplicitPrelude, MagicHash, UnboxedTuples, RankNTypes #-}+{-# OPTIONS_HADDOCK hide #-}++-----------------------------------------------------------------------------+-- |+-- Module      :  GHC.ST+-- Copyright   :  (c) The University of Glasgow, 1992-2002+-- License     :  see libraries/base/LICENSE+--+-- Maintainer  :  cvs-ghc@haskell.org+-- Stability   :  internal+-- Portability :  non-portable (GHC Extensions)+--+-- The 'ST' Monad.+--+-----------------------------------------------------------------------------++module GHC.ST (+        ST(..), STret(..), STRep,+        fixST, runST, runSTRep,++        -- * Unsafe functions+        liftST, unsafeInterleaveST+    ) where++import GHC.Base+import GHC.Show++default ()++-- The state-transformer monad proper.  By default the monad is strict;+-- too many people got bitten by space leaks when it was lazy.++-- | The strict state-transformer monad.+-- A computation of type @'ST' s a@ transforms an internal state indexed+-- by @s@, and returns a value of type @a@.+-- The @s@ parameter is either+--+-- * an uninstantiated type variable (inside invocations of 'runST'), or+--+-- * 'RealWorld' (inside invocations of 'Control.Monad.ST.stToIO').+--+-- It serves to keep the internal states of different invocations+-- of 'runST' separate from each other and from invocations of+-- 'Control.Monad.ST.stToIO'.+--+-- The '>>=' and '>>' operations are strict in the state (though not in+-- values stored in the state).  For example,+--+-- @'runST' (writeSTRef _|_ v >>= f) = _|_@+newtype ST s a = ST (STRep s a)+type STRep s a = State# s -> (# State# s, a #)++instance Functor (ST s) where+    fmap f (ST m) = ST $ \ s ->+      case (m s) of { (# new_s, r #) ->+      (# new_s, f r #) }++instance Applicative (ST s) where+    pure = return+    (<*>) = ap++instance Monad (ST s) where+    {-# INLINE return #-}+    {-# INLINE (>>)   #-}+    {-# INLINE (>>=)  #-}+    return x = ST (\ s -> (# s, x #))+    m >> k   = m >>= \ _ -> k++    (ST m) >>= k+      = ST (\ s ->+        case (m s) of { (# new_s, r #) ->+        case (k r) of { ST k2 ->+        (k2 new_s) }})++data STret s a = STret (State# s) a++-- liftST is useful when we want a lifted result from an ST computation.  See+-- fixST below.+liftST :: ST s a -> State# s -> STret s a+liftST (ST m) = \s -> case m s of (# s', r #) -> STret s' r++{-# NOINLINE unsafeInterleaveST #-}+unsafeInterleaveST :: ST s a -> ST s a+unsafeInterleaveST (ST m) = ST ( \ s ->+    let+        r = case m s of (# _, res #) -> res+    in+    (# s, r #)+  )++-- | Allow the result of a state transformer computation to be used (lazily)+-- inside the computation.+-- Note that if @f@ is strict, @'fixST' f = _|_@.+fixST :: (a -> ST s a) -> ST s a+fixST k = ST $ \ s ->+    let ans       = liftST (k r) s+        STret _ r = ans+    in+    case ans of STret s' x -> (# s', x #)++instance  Show (ST s a)  where+    showsPrec _ _  = showString "<<ST action>>"+    showList       = showList__ (showsPrec 0)++{-+Definition of runST+~~~~~~~~~~~~~~~~~~~++SLPJ 95/04: Why @runST@ must not have an unfolding; consider:+\begin{verbatim}+f x =+  runST ( \ s -> let+                    (a, s')  = newArray# 100 [] s+                    (_, s'') = fill_in_array_or_something a x s'+                  in+                  freezeArray# a s'' )+\end{verbatim}+If we inline @runST@, we'll get:+\begin{verbatim}+f x = let+        (a, s')  = newArray# 100 [] realWorld#{-NB-}+        (_, s'') = fill_in_array_or_something a x s'+      in+      freezeArray# a s''+\end{verbatim}+And now the @newArray#@ binding can be floated to become a CAF, which+is totally and utterly wrong:+\begin{verbatim}+f = let+    (a, s')  = newArray# 100 [] realWorld#{-NB-} -- YIKES!!!+    in+    \ x ->+        let (_, s'') = fill_in_array_or_something a x s' in+        freezeArray# a s''+\end{verbatim}+All calls to @f@ will share a {\em single} array!  End SLPJ 95/04.+-}++{-# INLINE runST #-}+-- The INLINE prevents runSTRep getting inlined in *this* module+-- so that it is still visible when runST is inlined in an importing+-- module.  Regrettably delicate.  runST is behaving like a wrapper.++-- | Return the value computed by a state transformer computation.+-- The @forall@ ensures that the internal state used by the 'ST'+-- computation is inaccessible to the rest of the program.+runST :: (forall s. ST s a) -> a+runST st = runSTRep (case st of { ST st_rep -> st_rep })++-- I'm only letting runSTRep be inlined right at the end, in particular *after* full laziness+-- That's what the "INLINE [0]" says.+--              SLPJ Apr 99+-- {-# INLINE [0] runSTRep #-}++-- SDM: further to the above, inline phase 0 is run *before*+-- full-laziness at the moment, which means that the above comment is+-- invalid.  Inlining runSTRep doesn't make a huge amount of+-- difference, anyway.  Hence:++{-# NOINLINE runSTRep #-}+runSTRep :: (forall s. STRep s a) -> a+runSTRep st_rep = case st_rep realWorld# of+                        (# _, r #) -> r
− GHC/ST.lhs
@@ -1,170 +0,0 @@-\begin{code}-{-# LANGUAGE Unsafe #-}-{-# LANGUAGE NoImplicitPrelude, MagicHash, UnboxedTuples, RankNTypes #-}-{-# OPTIONS_HADDOCK hide #-}--------------------------------------------------------------------------------- |--- Module      :  GHC.ST--- Copyright   :  (c) The University of Glasgow, 1992-2002--- License     :  see libraries/base/LICENSE--- --- Maintainer  :  cvs-ghc@haskell.org--- Stability   :  internal--- Portability :  non-portable (GHC Extensions)------ The 'ST' Monad.-----------------------------------------------------------------------------------module GHC.ST (-        ST(..), STret(..), STRep,-        fixST, runST, runSTRep,--        -- * Unsafe functions-        liftST, unsafeInterleaveST-    ) where--import GHC.Base-import GHC.Show--default ()-\end{code}--%*********************************************************-%*                                                      *-\subsection{The @ST@ monad}-%*                                                      *-%*********************************************************--The state-transformer monad proper.  By default the monad is strict;-too many people got bitten by space leaks when it was lazy.--\begin{code}--- | The strict state-transformer monad.--- A computation of type @'ST' s a@ transforms an internal state indexed--- by @s@, and returns a value of type @a@.--- The @s@ parameter is either------ * an uninstantiated type variable (inside invocations of 'runST'), or------ * 'RealWorld' (inside invocations of 'Control.Monad.ST.stToIO').------ It serves to keep the internal states of different invocations--- of 'runST' separate from each other and from invocations of--- 'Control.Monad.ST.stToIO'.------ The '>>=' and '>>' operations are strict in the state (though not in--- values stored in the state).  For example,------ @'runST' (writeSTRef _|_ v >>= f) = _|_@-newtype ST s a = ST (STRep s a)-type STRep s a = State# s -> (# State# s, a #)--instance Functor (ST s) where-    fmap f (ST m) = ST $ \ s ->-      case (m s) of { (# new_s, r #) ->-      (# new_s, f r #) }--instance Monad (ST s) where-    {-# INLINE return #-}-    {-# INLINE (>>)   #-}-    {-# INLINE (>>=)  #-}-    return x = ST (\ s -> (# s, x #))-    m >> k   = m >>= \ _ -> k--    (ST m) >>= k-      = ST (\ s ->-        case (m s) of { (# new_s, r #) ->-        case (k r) of { ST k2 ->-        (k2 new_s) }})--data STret s a = STret (State# s) a---- liftST is useful when we want a lifted result from an ST computation.  See--- fixST below.-liftST :: ST s a -> State# s -> STret s a-liftST (ST m) = \s -> case m s of (# s', r #) -> STret s' r--{-# NOINLINE unsafeInterleaveST #-}-unsafeInterleaveST :: ST s a -> ST s a-unsafeInterleaveST (ST m) = ST ( \ s ->-    let-        r = case m s of (# _, res #) -> res-    in-    (# s, r #)-  )---- | Allow the result of a state transformer computation to be used (lazily)--- inside the computation.--- Note that if @f@ is strict, @'fixST' f = _|_@.-fixST :: (a -> ST s a) -> ST s a-fixST k = ST $ \ s ->-    let ans       = liftST (k r) s-        STret _ r = ans-    in-    case ans of STret s' x -> (# s', x #)--instance  Show (ST s a)  where-    showsPrec _ _  = showString "<<ST action>>"-    showList       = showList__ (showsPrec 0)-\end{code}--Definition of runST-~~~~~~~~~~~~~~~~~~~--SLPJ 95/04: Why @runST@ must not have an unfolding; consider:-\begin{verbatim}-f x =-  runST ( \ s -> let-                    (a, s')  = newArray# 100 [] s-                    (_, s'') = fill_in_array_or_something a x s'-                  in-                  freezeArray# a s'' )-\end{verbatim}-If we inline @runST@, we'll get:-\begin{verbatim}-f x = let-        (a, s')  = newArray# 100 [] realWorld#{-NB-}-        (_, s'') = fill_in_array_or_something a x s'-      in-      freezeArray# a s''-\end{verbatim}-And now the @newArray#@ binding can be floated to become a CAF, which-is totally and utterly wrong:-\begin{verbatim}-f = let-    (a, s')  = newArray# 100 [] realWorld#{-NB-} -- YIKES!!!-    in-    \ x ->-        let (_, s'') = fill_in_array_or_something a x s' in-        freezeArray# a s''-\end{verbatim}-All calls to @f@ will share a {\em single} array!  End SLPJ 95/04.--\begin{code}-{-# INLINE runST #-}--- The INLINE prevents runSTRep getting inlined in *this* module--- so that it is still visible when runST is inlined in an importing--- module.  Regrettably delicate.  runST is behaving like a wrapper.---- | Return the value computed by a state transformer computation.--- The @forall@ ensures that the internal state used by the 'ST'--- computation is inaccessible to the rest of the program.-runST :: (forall s. ST s a) -> a-runST st = runSTRep (case st of { ST st_rep -> st_rep })---- I'm only letting runSTRep be inlined right at the end, in particular *after* full laziness--- That's what the "INLINE [0]" says.---              SLPJ Apr 99--- {-# INLINE [0] runSTRep #-}---- SDM: further to the above, inline phase 0 is run *before*--- full-laziness at the moment, which means that the above comment is--- invalid.  Inlining runSTRep doesn't make a huge amount of--- difference, anyway.  Hence:--{-# NOINLINE runSTRep #-}-runSTRep :: (forall s. STRep s a) -> a-runSTRep st_rep = case st_rep realWorld# of-                        (# _, r #) -> r-\end{code}
+ GHC/STRef.hs view
@@ -0,0 +1,49 @@+{-# LANGUAGE Unsafe #-}+{-# LANGUAGE NoImplicitPrelude, MagicHash, UnboxedTuples #-}+{-# OPTIONS_HADDOCK hide #-}++-----------------------------------------------------------------------------+-- |+-- Module      :  GHC.STRef+-- Copyright   :  (c) The University of Glasgow, 1994-2002+-- License     :  see libraries/base/LICENSE+--+-- Maintainer  :  cvs-ghc@haskell.org+-- Stability   :  internal+-- Portability :  non-portable (GHC Extensions)+--+-- References in the 'ST' monad.+--+-----------------------------------------------------------------------------++module GHC.STRef (+        STRef(..),+        newSTRef, readSTRef, writeSTRef+    ) where++import GHC.ST+import GHC.Base++data STRef s a = STRef (MutVar# s a)+-- ^ a value of type @STRef s a@ is a mutable variable in state thread @s@,+-- containing a value of type @a@++-- |Build a new 'STRef' in the current state thread+newSTRef :: a -> ST s (STRef s a)+newSTRef init = ST $ \s1# ->+    case newMutVar# init s1#            of { (# s2#, var# #) ->+    (# s2#, STRef var# #) }++-- |Read the value of an 'STRef'+readSTRef :: STRef s a -> ST s a+readSTRef (STRef var#) = ST $ \s1# -> readMutVar# var# s1#++-- |Write a new value into an 'STRef'+writeSTRef :: STRef s a -> a -> ST s ()+writeSTRef (STRef var#) val = ST $ \s1# ->+    case writeMutVar# var# val s1#      of { s2# ->+    (# s2#, () #) }++-- Just pointer equality on mutable references:+instance Eq (STRef s a) where+    STRef v1# == STRef v2# = isTrue# (sameMutVar# v1# v2#)
− GHC/STRef.lhs
@@ -1,52 +0,0 @@-\begin{code}-{-# LANGUAGE Unsafe #-}-{-# LANGUAGE NoImplicitPrelude, MagicHash, UnboxedTuples #-}-{-# OPTIONS_HADDOCK hide #-}---------------------------------------------------------------------------------- |--- Module      :  GHC.STRef--- Copyright   :  (c) The University of Glasgow, 1994-2002--- License     :  see libraries/base/LICENSE------ Maintainer  :  cvs-ghc@haskell.org--- Stability   :  internal--- Portability :  non-portable (GHC Extensions)------ References in the 'ST' monad.-----------------------------------------------------------------------------------module GHC.STRef (-        STRef(..),-        newSTRef, readSTRef, writeSTRef-    ) where--import GHC.ST-import GHC.Base--data STRef s a = STRef (MutVar# s a)--- ^ a value of type @STRef s a@ is a mutable variable in state thread @s@,--- containing a value of type @a@---- |Build a new 'STRef' in the current state thread-newSTRef :: a -> ST s (STRef s a)-newSTRef init = ST $ \s1# ->-    case newMutVar# init s1#            of { (# s2#, var# #) ->-    (# s2#, STRef var# #) }---- |Read the value of an 'STRef'-readSTRef :: STRef s a -> ST s a-readSTRef (STRef var#) = ST $ \s1# -> readMutVar# var# s1#---- |Write a new value into an 'STRef'-writeSTRef :: STRef s a -> a -> ST s ()-writeSTRef (STRef var#) val = ST $ \s1# ->-    case writeMutVar# var# val s1#      of { s2# ->-    (# s2#, () #) }---- Just pointer equality on mutable references:-instance Eq (STRef s a) where-    STRef v1# == STRef v2# = isTrue# (sameMutVar# v1# v2#)--\end{code}
+ GHC/Show.hs view
@@ -0,0 +1,507 @@+{-# LANGUAGE Trustworthy #-}+{-# LANGUAGE CPP, NoImplicitPrelude, BangPatterns, StandaloneDeriving,+             MagicHash, UnboxedTuples #-}+{-# OPTIONS_HADDOCK hide #-}++#include "MachDeps.h"+#if SIZEOF_HSWORD == 4+#define DIGITS       9+#define BASE         1000000000+#elif SIZEOF_HSWORD == 8+#define DIGITS       18+#define BASE         1000000000000000000+#else+#error Please define DIGITS and BASE+-- DIGITS should be the largest integer such that+--     10^DIGITS < 2^(SIZEOF_HSWORD * 8 - 1)+-- BASE should be 10^DIGITS. Note that ^ is not available yet.+#endif++-----------------------------------------------------------------------------+-- |+-- Module      :  GHC.Show+-- Copyright   :  (c) The University of Glasgow, 1992-2002+-- License     :  see libraries/base/LICENSE+--+-- Maintainer  :  cvs-ghc@haskell.org+-- Stability   :  internal+-- Portability :  non-portable (GHC Extensions)+--+-- The 'Show' class, and related operations.+--+-----------------------------------------------------------------------------++module GHC.Show+        (+        Show(..), ShowS,++        -- Instances for Show: (), [], Bool, Ordering, Int, Char++        -- Show support code+        shows, showChar, showString, showMultiLineString,+        showParen, showList__, showSpace,+        showLitChar, showLitString, protectEsc,+        intToDigit, showSignedInt,+        appPrec, appPrec1,++        -- Character operations+        asciiTab,+  )+        where++import GHC.Base+import GHC.Num+import GHC.List ((!!), foldr1, break)++-- | The @shows@ functions return a function that prepends the+-- output 'String' to an existing 'String'.  This allows constant-time+-- concatenation of results using function composition.+type ShowS = String -> String++-- | Conversion of values to readable 'String's.+--+-- Derived instances of 'Show' have the following properties, which+-- are compatible with derived instances of 'Text.Read.Read':+--+-- * The result of 'show' is a syntactically correct Haskell+--   expression containing only constants, given the fixity+--   declarations in force at the point where the type is declared.+--   It contains only the constructor names defined in the data type,+--   parentheses, and spaces.  When labelled constructor fields are+--   used, braces, commas, field names, and equal signs are also used.+--+-- * If the constructor is defined to be an infix operator, then+--   'showsPrec' will produce infix applications of the constructor.+--+-- * the representation will be enclosed in parentheses if the+--   precedence of the top-level constructor in @x@ is less than @d@+--   (associativity is ignored).  Thus, if @d@ is @0@ then the result+--   is never surrounded in parentheses; if @d@ is @11@ it is always+--   surrounded in parentheses, unless it is an atomic expression.+--+-- * If the constructor is defined using record syntax, then 'show'+--   will produce the record-syntax form, with the fields given in the+--   same order as the original declaration.+--+-- For example, given the declarations+--+-- > infixr 5 :^:+-- > data Tree a =  Leaf a  |  Tree a :^: Tree a+--+-- the derived instance of 'Show' is equivalent to+--+-- > instance (Show a) => Show (Tree a) where+-- >+-- >        showsPrec d (Leaf m) = showParen (d > app_prec) $+-- >             showString "Leaf " . showsPrec (app_prec+1) m+-- >          where app_prec = 10+-- >+-- >        showsPrec d (u :^: v) = showParen (d > up_prec) $+-- >             showsPrec (up_prec+1) u .+-- >             showString " :^: "      .+-- >             showsPrec (up_prec+1) v+-- >          where up_prec = 5+--+-- Note that right-associativity of @:^:@ is ignored.  For example,+--+-- * @'show' (Leaf 1 :^: Leaf 2 :^: Leaf 3)@ produces the string+--   @\"Leaf 1 :^: (Leaf 2 :^: Leaf 3)\"@.++class  Show a  where+    {-# MINIMAL showsPrec | show #-}++    -- | Convert a value to a readable 'String'.+    --+    -- 'showsPrec' should satisfy the law+    --+    -- > showsPrec d x r ++ s  ==  showsPrec d x (r ++ s)+    --+    -- Derived instances of 'Text.Read.Read' and 'Show' satisfy the following:+    --+    -- * @(x,\"\")@ is an element of+    --   @('Text.Read.readsPrec' d ('showsPrec' d x \"\"))@.+    --+    -- That is, 'Text.Read.readsPrec' parses the string produced by+    -- 'showsPrec', and delivers the value that 'showsPrec' started with.++    showsPrec :: Int    -- ^ the operator precedence of the enclosing+                        -- context (a number from @0@ to @11@).+                        -- Function application has precedence @10@.+              -> a      -- ^ the value to be converted to a 'String'+              -> ShowS++    -- | A specialised variant of 'showsPrec', using precedence context+    -- zero, and returning an ordinary 'String'.+    show      :: a   -> String++    -- | The method 'showList' is provided to allow the programmer to+    -- give a specialised way of showing lists of values.+    -- For example, this is used by the predefined 'Show' instance of+    -- the 'Char' type, where values of type 'String' should be shown+    -- in double quotes, rather than between square brackets.+    showList  :: [a] -> ShowS++    showsPrec _ x s = show x ++ s+    show x          = shows x ""+    showList ls   s = showList__ shows ls s++showList__ :: (a -> ShowS) ->  [a] -> ShowS+showList__ _     []     s = "[]" ++ s+showList__ showx (x:xs) s = '[' : showx x (showl xs)+  where+    showl []     = ']' : s+    showl (y:ys) = ',' : showx y (showl ys)++appPrec, appPrec1 :: Int+        -- Use unboxed stuff because we don't have overloaded numerics yet+appPrec = I# 10#        -- Precedence of application:+                        --   one more than the maximum operator precedence of 9+appPrec1 = I# 11#       -- appPrec + 1++--------------------------------------------------------------+-- Simple Instances+--------------------------------------------------------------++deriving instance Show ()++instance Show a => Show [a]  where+  {-# SPECIALISE instance Show [String] #-}+  {-# SPECIALISE instance Show [Char] #-}+  {-# SPECIALISE instance Show [Int] #-}+  showsPrec _         = showList++deriving instance Show Bool+deriving instance Show Ordering++instance  Show Char  where+    showsPrec _ '\'' = showString "'\\''"+    showsPrec _ c    = showChar '\'' . showLitChar c . showChar '\''++    showList cs = showChar '"' . showLitString cs . showChar '"'++instance Show Int where+    showsPrec = showSignedInt++instance Show Word where+    showsPrec _ (W# w) = showWord w++showWord :: Word# -> ShowS+showWord w# cs+ | isTrue# (w# `ltWord#` 10##) = C# (chr# (ord# '0'# +# word2Int# w#)) : cs+ | otherwise = case chr# (ord# '0'# +# word2Int# (w# `remWord#` 10##)) of+               c# ->+                   showWord (w# `quotWord#` 10##) (C# c# : cs)++deriving instance Show a => Show (Maybe a)++--------------------------------------------------------------+-- Show instances for the first few tuple+--------------------------------------------------------------++-- The explicit 's' parameters are important+-- Otherwise GHC thinks that "shows x" might take a lot of work to compute+-- and generates defns like+--      showsPrec _ (x,y) = let sx = shows x; sy = shows y in+--                          \s -> showChar '(' (sx (showChar ',' (sy (showChar ')' s))))++instance  (Show a, Show b) => Show (a,b)  where+  showsPrec _ (a,b) s = show_tuple [shows a, shows b] s++instance (Show a, Show b, Show c) => Show (a, b, c) where+  showsPrec _ (a,b,c) s = show_tuple [shows a, shows b, shows c] s++instance (Show a, Show b, Show c, Show d) => Show (a, b, c, d) where+  showsPrec _ (a,b,c,d) s = show_tuple [shows a, shows b, shows c, shows d] s++instance (Show a, Show b, Show c, Show d, Show e) => Show (a, b, c, d, e) where+  showsPrec _ (a,b,c,d,e) s = show_tuple [shows a, shows b, shows c, shows d, shows e] s++instance (Show a, Show b, Show c, Show d, Show e, Show f) => Show (a,b,c,d,e,f) where+  showsPrec _ (a,b,c,d,e,f) s = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f] s++instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g)+        => Show (a,b,c,d,e,f,g) where+  showsPrec _ (a,b,c,d,e,f,g) s+        = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g] s++instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h)+         => Show (a,b,c,d,e,f,g,h) where+  showsPrec _ (a,b,c,d,e,f,g,h) s+        = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h] s++instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i)+         => Show (a,b,c,d,e,f,g,h,i) where+  showsPrec _ (a,b,c,d,e,f,g,h,i) s+        = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h,+                      shows i] s++instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j)+         => Show (a,b,c,d,e,f,g,h,i,j) where+  showsPrec _ (a,b,c,d,e,f,g,h,i,j) s+        = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h,+                      shows i, shows j] s++instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k)+         => Show (a,b,c,d,e,f,g,h,i,j,k) where+  showsPrec _ (a,b,c,d,e,f,g,h,i,j,k) s+        = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h,+                      shows i, shows j, shows k] s++instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k,+          Show l)+         => Show (a,b,c,d,e,f,g,h,i,j,k,l) where+  showsPrec _ (a,b,c,d,e,f,g,h,i,j,k,l) s+        = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h,+                      shows i, shows j, shows k, shows l] s++instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k,+          Show l, Show m)+         => Show (a,b,c,d,e,f,g,h,i,j,k,l,m) where+  showsPrec _ (a,b,c,d,e,f,g,h,i,j,k,l,m) s+        = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h,+                      shows i, shows j, shows k, shows l, shows m] s++instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k,+          Show l, Show m, Show n)+         => Show (a,b,c,d,e,f,g,h,i,j,k,l,m,n) where+  showsPrec _ (a,b,c,d,e,f,g,h,i,j,k,l,m,n) s+        = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h,+                      shows i, shows j, shows k, shows l, shows m, shows n] s++instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k,+          Show l, Show m, Show n, Show o)+         => Show (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) where+  showsPrec _ (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) s+        = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h,+                      shows i, shows j, shows k, shows l, shows m, shows n, shows o] s++show_tuple :: [ShowS] -> ShowS+show_tuple ss = showChar '('+              . foldr1 (\s r -> s . showChar ',' . r) ss+              . showChar ')'++--------------------------------------------------------------+-- Support code for Show+--------------------------------------------------------------++-- | equivalent to 'showsPrec' with a precedence of 0.+shows           :: (Show a) => a -> ShowS+shows           =  showsPrec 0++-- | utility function converting a 'Char' to a show function that+-- simply prepends the character unchanged.+showChar        :: Char -> ShowS+showChar        =  (:)++-- | utility function converting a 'String' to a show function that+-- simply prepends the string unchanged.+showString      :: String -> ShowS+showString      =  (++)++-- | utility function that surrounds the inner show function with+-- parentheses when the 'Bool' parameter is 'True'.+showParen       :: Bool -> ShowS -> ShowS+showParen b p   =  if b then showChar '(' . p . showChar ')' else p++showSpace :: ShowS+showSpace = {-showChar ' '-} \ xs -> ' ' : xs++-- Code specific for characters++-- | Convert a character to a string using only printable characters,+-- using Haskell source-language escape conventions.  For example:+--+-- > showLitChar '\n' s  =  "\\n" ++ s+--+showLitChar                :: Char -> ShowS+showLitChar c s | c > '\DEL' =  showChar '\\' (protectEsc isDec (shows (ord c)) s)+showLitChar '\DEL'         s =  showString "\\DEL" s+showLitChar '\\'           s =  showString "\\\\" s+showLitChar c s | c >= ' '   =  showChar c s+showLitChar '\a'           s =  showString "\\a" s+showLitChar '\b'           s =  showString "\\b" s+showLitChar '\f'           s =  showString "\\f" s+showLitChar '\n'           s =  showString "\\n" s+showLitChar '\r'           s =  showString "\\r" s+showLitChar '\t'           s =  showString "\\t" s+showLitChar '\v'           s =  showString "\\v" s+showLitChar '\SO'          s =  protectEsc (== 'H') (showString "\\SO") s+showLitChar c              s =  showString ('\\' : asciiTab!!ord c) s+        -- I've done manual eta-expansion here, because otherwise it's+        -- impossible to stop (asciiTab!!ord) getting floated out as an MFE++showLitString :: String -> ShowS+-- | Same as 'showLitChar', but for strings+-- It converts the string to a string using Haskell escape conventions+-- for non-printable characters. Does not add double-quotes around the+-- whole thing; the caller should do that.+-- The main difference from showLitChar (apart from the fact that the+-- argument is a string not a list) is that we must escape double-quotes+showLitString []         s = s+showLitString ('"' : cs) s = showString "\\\"" (showLitString cs s)+showLitString (c   : cs) s = showLitChar c (showLitString cs s)+   -- Making 's' an explicit parameter makes it clear to GHC that+   -- showLitString has arity 2, which avoids it allocating an extra lambda+   -- The sticking point is the recursive call to (showLitString cs), which+   -- it can't figure out would be ok with arity 2.++showMultiLineString :: String -> [String]+-- | Like 'showLitString' (expand escape characters using Haskell+-- escape conventions), but+--   * break the string into multiple lines+--   * wrap the entire thing in double quotes+-- Example:  @showMultiLineString "hello\ngoodbye\nblah"@+-- returns   @["\"hello\\n\\", "\\goodbye\n\\", "\\blah\""]@+showMultiLineString str+  = go '\"' str+  where+    go ch s = case break (== '\n') s of+                (l, _:s'@(_:_)) -> (ch : showLitString l "\\n\\") : go '\\' s'+                (l, "\n")       -> [ch : showLitString l "\\n\""]+                (l, _)          -> [ch : showLitString l "\""]++isDec :: Char -> Bool+isDec c = c >= '0' && c <= '9'++protectEsc :: (Char -> Bool) -> ShowS -> ShowS+protectEsc p f             = f . cont+                             where cont s@(c:_) | p c = "\\&" ++ s+                                   cont s             = s+++asciiTab :: [String]+asciiTab = -- Using an array drags in the array module.  listArray ('\NUL', ' ')+           ["NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL",+            "BS",  "HT",  "LF",  "VT",  "FF",  "CR",  "SO",  "SI",+            "DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB",+            "CAN", "EM",  "SUB", "ESC", "FS",  "GS",  "RS",  "US",+            "SP"]++-- Code specific for Ints.++-- | Convert an 'Int' in the range @0@..@15@ to the corresponding single+-- digit 'Char'.  This function fails on other inputs, and generates+-- lower-case hexadecimal digits.+intToDigit :: Int -> Char+intToDigit (I# i)+    | isTrue# (i >=# 0#)  && isTrue# (i <=#  9#) = unsafeChr (ord '0' + I# i)+    | isTrue# (i >=# 10#) && isTrue# (i <=# 15#) = unsafeChr (ord 'a' + I# i - 10)+    | otherwise =  error ("Char.intToDigit: not a digit " ++ show (I# i))++showSignedInt :: Int -> Int -> ShowS+showSignedInt (I# p) (I# n) r+    | isTrue# (n <# 0#) && isTrue# (p ># 6#) = '(' : itos n (')' : r)+    | otherwise                              = itos n r++itos :: Int# -> String -> String+itos n# cs+    | isTrue# (n# <# 0#) =+        let !(I# minInt#) = minInt in+        if isTrue# (n# ==# minInt#)+                -- negateInt# minInt overflows, so we can't do that:+           then '-' : (case n# `quotRemInt#` 10# of+                       (# q, r #) ->+                           itos' (negateInt# q) (itos' (negateInt# r) cs))+           else '-' : itos' (negateInt# n#) cs+    | otherwise = itos' n# cs+    where+    itos' :: Int# -> String -> String+    itos' x# cs'+        | isTrue# (x# <# 10#) = C# (chr# (ord# '0'# +# x#)) : cs'+        | otherwise = case x# `quotRemInt#` 10# of+                      (# q, r #) ->+                          case chr# (ord# '0'# +# r) of+                          c# ->+                              itos' q (C# c# : cs')++--------------------------------------------------------------+-- The Integer instances for Show+--------------------------------------------------------------++instance Show Integer where+    showsPrec p n r+        | p > 6 && n < 0 = '(' : integerToString n (')' : r)+        -- Minor point: testing p first gives better code+        -- in the not-uncommon case where the p argument+        -- is a constant+        | otherwise = integerToString n r+    showList = showList__ (showsPrec 0)++-- Divide an conquer implementation of string conversion+integerToString :: Integer -> String -> String+integerToString n0 cs0+    | n0 < 0    = '-' : integerToString' (- n0) cs0+    | otherwise = integerToString' n0 cs0+    where+    integerToString' :: Integer -> String -> String+    integerToString' n cs+        | n < BASE  = jhead (fromInteger n) cs+        | otherwise = jprinth (jsplitf (BASE*BASE) n) cs++    -- Split n into digits in base p. We first split n into digits+    -- in base p*p and then split each of these digits into two.+    -- Note that the first 'digit' modulo p*p may have a leading zero+    -- in base p that we need to drop - this is what jsplith takes care of.+    -- jsplitb the handles the remaining digits.+    jsplitf :: Integer -> Integer -> [Integer]+    jsplitf p n+        | p > n     = [n]+        | otherwise = jsplith p (jsplitf (p*p) n)++    jsplith :: Integer -> [Integer] -> [Integer]+    jsplith p (n:ns) =+        case n `quotRemInteger` p of+        (# q, r #) ->+            if q > 0 then q : r : jsplitb p ns+                     else     r : jsplitb p ns+    jsplith _ [] = error "jsplith: []"++    jsplitb :: Integer -> [Integer] -> [Integer]+    jsplitb _ []     = []+    jsplitb p (n:ns) = case n `quotRemInteger` p of+                       (# q, r #) ->+                           q : r : jsplitb p ns++    -- Convert a number that has been split into digits in base BASE^2+    -- this includes a last splitting step and then conversion of digits+    -- that all fit into a machine word.+    jprinth :: [Integer] -> String -> String+    jprinth (n:ns) cs =+        case n `quotRemInteger` BASE of+        (# q', r' #) ->+            let q = fromInteger q'+                r = fromInteger r'+            in if q > 0 then jhead q $ jblock r $ jprintb ns cs+                        else jhead r $ jprintb ns cs+    jprinth [] _ = error "jprinth []"++    jprintb :: [Integer] -> String -> String+    jprintb []     cs = cs+    jprintb (n:ns) cs = case n `quotRemInteger` BASE of+                        (# q', r' #) ->+                            let q = fromInteger q'+                                r = fromInteger r'+                            in jblock q $ jblock r $ jprintb ns cs++    -- Convert an integer that fits into a machine word. Again, we have two+    -- functions, one that drops leading zeros (jhead) and one that doesn't+    -- (jblock)+    jhead :: Int -> String -> String+    jhead n cs+        | n < 10    = case unsafeChr (ord '0' + n) of+            c@(C# _) -> c : cs+        | otherwise = case unsafeChr (ord '0' + r) of+            c@(C# _) -> jhead q (c : cs)+        where+        (q, r) = n `quotRemInt` 10++    jblock = jblock' {- ' -} DIGITS++    jblock' :: Int -> Int -> String -> String+    jblock' d n cs+        | d == 1    = case unsafeChr (ord '0' + n) of+             c@(C# _) -> c : cs+        | otherwise = case unsafeChr (ord '0' + r) of+             c@(C# _) -> jblock' (d - 1) q (c : cs)+        where+        (q, r) = n `quotRemInt` 10
− GHC/Show.lhs
@@ -1,554 +0,0 @@-\begin{code}-{-# LANGUAGE Trustworthy #-}-{-# LANGUAGE CPP, NoImplicitPrelude, BangPatterns, StandaloneDeriving,-             MagicHash, UnboxedTuples #-}-{-# OPTIONS_HADDOCK hide #-}--#include "MachDeps.h"-#if SIZEOF_HSWORD == 4-#define DIGITS       9-#define BASE         1000000000-#elif SIZEOF_HSWORD == 8-#define DIGITS       18-#define BASE         1000000000000000000-#else-#error Please define DIGITS and BASE--- DIGITS should be the largest integer such that---     10^DIGITS < 2^(SIZEOF_HSWORD * 8 - 1)--- BASE should be 10^DIGITS. Note that ^ is not available yet.-#endif---------------------------------------------------------------------------------- |--- Module      :  GHC.Show--- Copyright   :  (c) The University of Glasgow, 1992-2002--- License     :  see libraries/base/LICENSE------ Maintainer  :  cvs-ghc@haskell.org--- Stability   :  internal--- Portability :  non-portable (GHC Extensions)------ The 'Show' class, and related operations.-----------------------------------------------------------------------------------module GHC.Show-        (-        Show(..), ShowS,--        -- Instances for Show: (), [], Bool, Ordering, Int, Char--        -- Show support code-        shows, showChar, showString, showMultiLineString,-        showParen, showList__, showSpace,-        showLitChar, showLitString, protectEsc,-        intToDigit, showSignedInt,-        appPrec, appPrec1,--        -- Character operations-        asciiTab,-  )-        where--import GHC.Base-import GHC.Num-import Data.Maybe-import GHC.List ((!!), foldr1, break)-\end{code}----%*********************************************************-%*                                                      *-\subsection{The @Show@ class}-%*                                                      *-%*********************************************************--\begin{code}--- | The @shows@ functions return a function that prepends the--- output 'String' to an existing 'String'.  This allows constant-time--- concatenation of results using function composition.-type ShowS = String -> String---- | Conversion of values to readable 'String's.------ Minimal complete definition: 'showsPrec' or 'show'.------ Derived instances of 'Show' have the following properties, which--- are compatible with derived instances of 'Text.Read.Read':------ * The result of 'show' is a syntactically correct Haskell---   expression containing only constants, given the fixity---   declarations in force at the point where the type is declared.---   It contains only the constructor names defined in the data type,---   parentheses, and spaces.  When labelled constructor fields are---   used, braces, commas, field names, and equal signs are also used.------ * If the constructor is defined to be an infix operator, then---   'showsPrec' will produce infix applications of the constructor.------ * the representation will be enclosed in parentheses if the---   precedence of the top-level constructor in @x@ is less than @d@---   (associativity is ignored).  Thus, if @d@ is @0@ then the result---   is never surrounded in parentheses; if @d@ is @11@ it is always---   surrounded in parentheses, unless it is an atomic expression.------ * If the constructor is defined using record syntax, then 'show'---   will produce the record-syntax form, with the fields given in the---   same order as the original declaration.------ For example, given the declarations------ > infixr 5 :^:--- > data Tree a =  Leaf a  |  Tree a :^: Tree a------ the derived instance of 'Show' is equivalent to------ > instance (Show a) => Show (Tree a) where--- >--- >        showsPrec d (Leaf m) = showParen (d > app_prec) $--- >             showString "Leaf " . showsPrec (app_prec+1) m--- >          where app_prec = 10--- >--- >        showsPrec d (u :^: v) = showParen (d > up_prec) $--- >             showsPrec (up_prec+1) u .--- >             showString " :^: "      .--- >             showsPrec (up_prec+1) v--- >          where up_prec = 5------ Note that right-associativity of @:^:@ is ignored.  For example,------ * @'show' (Leaf 1 :^: Leaf 2 :^: Leaf 3)@ produces the string---   @\"Leaf 1 :^: (Leaf 2 :^: Leaf 3)\"@.--class  Show a  where-    -- | Convert a value to a readable 'String'.-    ---    -- 'showsPrec' should satisfy the law-    ---    -- > showsPrec d x r ++ s  ==  showsPrec d x (r ++ s)-    ---    -- Derived instances of 'Text.Read.Read' and 'Show' satisfy the following:-    ---    -- * @(x,\"\")@ is an element of-    --   @('Text.Read.readsPrec' d ('showsPrec' d x \"\"))@.-    ---    -- That is, 'Text.Read.readsPrec' parses the string produced by-    -- 'showsPrec', and delivers the value that 'showsPrec' started with.--    showsPrec :: Int    -- ^ the operator precedence of the enclosing-                        -- context (a number from @0@ to @11@).-                        -- Function application has precedence @10@.-              -> a      -- ^ the value to be converted to a 'String'-              -> ShowS--    -- | A specialised variant of 'showsPrec', using precedence context-    -- zero, and returning an ordinary 'String'.-    show      :: a   -> String--    -- | The method 'showList' is provided to allow the programmer to-    -- give a specialised way of showing lists of values.-    -- For example, this is used by the predefined 'Show' instance of-    -- the 'Char' type, where values of type 'String' should be shown-    -- in double quotes, rather than between square brackets.-    showList  :: [a] -> ShowS--    showsPrec _ x s = show x ++ s-    show x          = shows x ""-    showList ls   s = showList__ shows ls s-    {-# MINIMAL showsPrec | show #-}--showList__ :: (a -> ShowS) ->  [a] -> ShowS-showList__ _     []     s = "[]" ++ s-showList__ showx (x:xs) s = '[' : showx x (showl xs)-  where-    showl []     = ']' : s-    showl (y:ys) = ',' : showx y (showl ys)--appPrec, appPrec1 :: Int-        -- Use unboxed stuff because we don't have overloaded numerics yet-appPrec = I# 10#        -- Precedence of application:-                        --   one more than the maximum operator precedence of 9-appPrec1 = I# 11#       -- appPrec + 1-\end{code}--%*********************************************************-%*                                                      *-\subsection{Simple Instances}-%*                                                      *-%*********************************************************--\begin{code}--instance  Show ()  where-    showsPrec _ () = showString "()"--instance Show a => Show [a]  where-    showsPrec _         = showList--instance Show Bool where-  showsPrec _ True  = showString "True"-  showsPrec _ False = showString "False"--instance Show Ordering where-  showsPrec _ LT = showString "LT"-  showsPrec _ EQ = showString "EQ"-  showsPrec _ GT = showString "GT"--instance  Show Char  where-    showsPrec _ '\'' = showString "'\\''"-    showsPrec _ c    = showChar '\'' . showLitChar c . showChar '\''--    showList cs = showChar '"' . showLitString cs . showChar '"'--instance Show Int where-    showsPrec = showSignedInt--instance Show Word where-    showsPrec _ (W# w) = showWord w--showWord :: Word# -> ShowS-showWord w# cs- | isTrue# (w# `ltWord#` 10##) = C# (chr# (ord# '0'# +# word2Int# w#)) : cs- | otherwise = case chr# (ord# '0'# +# word2Int# (w# `remWord#` 10##)) of-               c# ->-                   showWord (w# `quotWord#` 10##) (C# c# : cs)--instance Show a => Show (Maybe a) where-    showsPrec _p Nothing s = showString "Nothing" s-    showsPrec p (Just x) s-                          = (showParen (p > appPrec) $-                             showString "Just " .-                             showsPrec appPrec1 x) s-\end{code}---%*********************************************************-%*                                                      *-\subsection{Show instances for the first few tuples-%*                                                      *-%*********************************************************--\begin{code}--- The explicit 's' parameters are important--- Otherwise GHC thinks that "shows x" might take a lot of work to compute--- and generates defns like---      showsPrec _ (x,y) = let sx = shows x; sy = shows y in---                          \s -> showChar '(' (sx (showChar ',' (sy (showChar ')' s))))--instance  (Show a, Show b) => Show (a,b)  where-  showsPrec _ (a,b) s = show_tuple [shows a, shows b] s--instance (Show a, Show b, Show c) => Show (a, b, c) where-  showsPrec _ (a,b,c) s = show_tuple [shows a, shows b, shows c] s--instance (Show a, Show b, Show c, Show d) => Show (a, b, c, d) where-  showsPrec _ (a,b,c,d) s = show_tuple [shows a, shows b, shows c, shows d] s--instance (Show a, Show b, Show c, Show d, Show e) => Show (a, b, c, d, e) where-  showsPrec _ (a,b,c,d,e) s = show_tuple [shows a, shows b, shows c, shows d, shows e] s--instance (Show a, Show b, Show c, Show d, Show e, Show f) => Show (a,b,c,d,e,f) where-  showsPrec _ (a,b,c,d,e,f) s = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f] s--instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g)-        => Show (a,b,c,d,e,f,g) where-  showsPrec _ (a,b,c,d,e,f,g) s-        = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g] s--instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h)-         => Show (a,b,c,d,e,f,g,h) where-  showsPrec _ (a,b,c,d,e,f,g,h) s-        = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h] s--instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i)-         => Show (a,b,c,d,e,f,g,h,i) where-  showsPrec _ (a,b,c,d,e,f,g,h,i) s-        = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h,-                      shows i] s--instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j)-         => Show (a,b,c,d,e,f,g,h,i,j) where-  showsPrec _ (a,b,c,d,e,f,g,h,i,j) s-        = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h,-                      shows i, shows j] s--instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k)-         => Show (a,b,c,d,e,f,g,h,i,j,k) where-  showsPrec _ (a,b,c,d,e,f,g,h,i,j,k) s-        = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h,-                      shows i, shows j, shows k] s--instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k,-          Show l)-         => Show (a,b,c,d,e,f,g,h,i,j,k,l) where-  showsPrec _ (a,b,c,d,e,f,g,h,i,j,k,l) s-        = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h,-                      shows i, shows j, shows k, shows l] s--instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k,-          Show l, Show m)-         => Show (a,b,c,d,e,f,g,h,i,j,k,l,m) where-  showsPrec _ (a,b,c,d,e,f,g,h,i,j,k,l,m) s-        = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h,-                      shows i, shows j, shows k, shows l, shows m] s--instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k,-          Show l, Show m, Show n)-         => Show (a,b,c,d,e,f,g,h,i,j,k,l,m,n) where-  showsPrec _ (a,b,c,d,e,f,g,h,i,j,k,l,m,n) s-        = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h,-                      shows i, shows j, shows k, shows l, shows m, shows n] s--instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k,-          Show l, Show m, Show n, Show o)-         => Show (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) where-  showsPrec _ (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) s-        = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h,-                      shows i, shows j, shows k, shows l, shows m, shows n, shows o] s--show_tuple :: [ShowS] -> ShowS-show_tuple ss = showChar '('-              . foldr1 (\s r -> s . showChar ',' . r) ss-              . showChar ')'-\end{code}---%*********************************************************-%*                                                      *-\subsection{Support code for @Show@}-%*                                                      *-%*********************************************************--\begin{code}--- | equivalent to 'showsPrec' with a precedence of 0.-shows           :: (Show a) => a -> ShowS-shows           =  showsPrec 0---- | utility function converting a 'Char' to a show function that--- simply prepends the character unchanged.-showChar        :: Char -> ShowS-showChar        =  (:)---- | utility function converting a 'String' to a show function that--- simply prepends the string unchanged.-showString      :: String -> ShowS-showString      =  (++)---- | utility function that surrounds the inner show function with--- parentheses when the 'Bool' parameter is 'True'.-showParen       :: Bool -> ShowS -> ShowS-showParen b p   =  if b then showChar '(' . p . showChar ')' else p--showSpace :: ShowS-showSpace = {-showChar ' '-} \ xs -> ' ' : xs-\end{code}--Code specific for characters--\begin{code}--- | Convert a character to a string using only printable characters,--- using Haskell source-language escape conventions.  For example:------ > showLitChar '\n' s  =  "\\n" ++ s----showLitChar                :: Char -> ShowS-showLitChar c s | c > '\DEL' =  showChar '\\' (protectEsc isDec (shows (ord c)) s)-showLitChar '\DEL'         s =  showString "\\DEL" s-showLitChar '\\'           s =  showString "\\\\" s-showLitChar c s | c >= ' '   =  showChar c s-showLitChar '\a'           s =  showString "\\a" s-showLitChar '\b'           s =  showString "\\b" s-showLitChar '\f'           s =  showString "\\f" s-showLitChar '\n'           s =  showString "\\n" s-showLitChar '\r'           s =  showString "\\r" s-showLitChar '\t'           s =  showString "\\t" s-showLitChar '\v'           s =  showString "\\v" s-showLitChar '\SO'          s =  protectEsc (== 'H') (showString "\\SO") s-showLitChar c              s =  showString ('\\' : asciiTab!!ord c) s-        -- I've done manual eta-expansion here, because otherwise it's-        -- impossible to stop (asciiTab!!ord) getting floated out as an MFE--showLitString :: String -> ShowS--- | Same as 'showLitChar', but for strings--- It converts the string to a string using Haskell escape conventions--- for non-printable characters. Does not add double-quotes around the--- whole thing; the caller should do that.--- The main difference from showLitChar (apart from the fact that the--- argument is a string not a list) is that we must escape double-quotes-showLitString []         s = s-showLitString ('"' : cs) s = showString "\\\"" (showLitString cs s)-showLitString (c   : cs) s = showLitChar c (showLitString cs s)-   -- Making 's' an explicit parameter makes it clear to GHC that-   -- showLitString has arity 2, which avoids it allocating an extra lambda-   -- The sticking point is the recursive call to (showLitString cs), which-   -- it can't figure out would be ok with arity 2.--showMultiLineString :: String -> [String]--- | Like 'showLitString' (expand escape characters using Haskell--- escape conventions), but---   * break the string into multiple lines---   * wrap the entire thing in double quotes--- Example:  @showMultiLineString "hello\ngoodbye\nblah"@--- returns   @["\"hello\\n\\", "\\goodbye\n\\", "\\blah\""]@-showMultiLineString str-  = go '\"' str-  where-    go ch s = case break (== '\n') s of-                (l, _:s'@(_:_)) -> (ch : showLitString l "\\n\\") : go '\\' s'-                (l, _)          -> [ch : showLitString l "\""]--isDec :: Char -> Bool-isDec c = c >= '0' && c <= '9'--protectEsc :: (Char -> Bool) -> ShowS -> ShowS-protectEsc p f             = f . cont-                             where cont s@(c:_) | p c = "\\&" ++ s-                                   cont s             = s---asciiTab :: [String]-asciiTab = -- Using an array drags in the array module.  listArray ('\NUL', ' ')-           ["NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL",-            "BS",  "HT",  "LF",  "VT",  "FF",  "CR",  "SO",  "SI",-            "DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB",-            "CAN", "EM",  "SUB", "ESC", "FS",  "GS",  "RS",  "US",-            "SP"]-\end{code}--Code specific for Ints.--\begin{code}--- | Convert an 'Int' in the range @0@..@15@ to the corresponding single--- digit 'Char'.  This function fails on other inputs, and generates--- lower-case hexadecimal digits.-intToDigit :: Int -> Char-intToDigit (I# i)-    | isTrue# (i >=# 0#)  && isTrue# (i <=#  9#) = unsafeChr (ord '0' + I# i)-    | isTrue# (i >=# 10#) && isTrue# (i <=# 15#) = unsafeChr (ord 'a' + I# i - 10)-    | otherwise =  error ("Char.intToDigit: not a digit " ++ show (I# i))--showSignedInt :: Int -> Int -> ShowS-showSignedInt (I# p) (I# n) r-    | isTrue# (n <# 0#) && isTrue# (p ># 6#) = '(' : itos n (')' : r)-    | otherwise                              = itos n r--itos :: Int# -> String -> String-itos n# cs-    | isTrue# (n# <# 0#) =-        let !(I# minInt#) = minInt in-        if isTrue# (n# ==# minInt#)-                -- negateInt# minInt overflows, so we can't do that:-           then '-' : (case n# `quotRemInt#` 10# of-                       (# q, r #) ->-                           itos' (negateInt# q) (itos' (negateInt# r) cs))-           else '-' : itos' (negateInt# n#) cs-    | otherwise = itos' n# cs-    where-    itos' :: Int# -> String -> String-    itos' x# cs'-        | isTrue# (x# <# 10#) = C# (chr# (ord# '0'# +# x#)) : cs'-        | otherwise = case x# `quotRemInt#` 10# of-                      (# q, r #) ->-                          case chr# (ord# '0'# +# r) of-                          c# ->-                              itos' q (C# c# : cs')-\end{code}---%*********************************************************-%*                                                      *-\subsection{The @Integer@ instances for @Show@}-%*                                                      *-%*********************************************************--\begin{code}-instance Show Integer where-    showsPrec p n r-        | p > 6 && n < 0 = '(' : integerToString n (')' : r)-        -- Minor point: testing p first gives better code-        -- in the not-uncommon case where the p argument-        -- is a constant-        | otherwise = integerToString n r-    showList = showList__ (showsPrec 0)---- Divide an conquer implementation of string conversion-integerToString :: Integer -> String -> String-integerToString n0 cs0-    | n0 < 0    = '-' : integerToString' (- n0) cs0-    | otherwise = integerToString' n0 cs0-    where-    integerToString' :: Integer -> String -> String-    integerToString' n cs-        | n < BASE  = jhead (fromInteger n) cs-        | otherwise = jprinth (jsplitf (BASE*BASE) n) cs--    -- Split n into digits in base p. We first split n into digits-    -- in base p*p and then split each of these digits into two.-    -- Note that the first 'digit' modulo p*p may have a leading zero-    -- in base p that we need to drop - this is what jsplith takes care of.-    -- jsplitb the handles the remaining digits.-    jsplitf :: Integer -> Integer -> [Integer]-    jsplitf p n-        | p > n     = [n]-        | otherwise = jsplith p (jsplitf (p*p) n)--    jsplith :: Integer -> [Integer] -> [Integer]-    jsplith p (n:ns) =-        case n `quotRemInteger` p of-        (# q, r #) ->-            if q > 0 then q : r : jsplitb p ns-                     else     r : jsplitb p ns-    jsplith _ [] = error "jsplith: []"--    jsplitb :: Integer -> [Integer] -> [Integer]-    jsplitb _ []     = []-    jsplitb p (n:ns) = case n `quotRemInteger` p of-                       (# q, r #) ->-                           q : r : jsplitb p ns--    -- Convert a number that has been split into digits in base BASE^2-    -- this includes a last splitting step and then conversion of digits-    -- that all fit into a machine word.-    jprinth :: [Integer] -> String -> String-    jprinth (n:ns) cs =-        case n `quotRemInteger` BASE of-        (# q', r' #) ->-            let q = fromInteger q'-                r = fromInteger r'-            in if q > 0 then jhead q $ jblock r $ jprintb ns cs-                        else jhead r $ jprintb ns cs-    jprinth [] _ = error "jprinth []"--    jprintb :: [Integer] -> String -> String-    jprintb []     cs = cs-    jprintb (n:ns) cs = case n `quotRemInteger` BASE of-                        (# q', r' #) ->-                            let q = fromInteger q'-                                r = fromInteger r'-                            in jblock q $ jblock r $ jprintb ns cs--    -- Convert an integer that fits into a machine word. Again, we have two-    -- functions, one that drops leading zeros (jhead) and one that doesn't-    -- (jblock)-    jhead :: Int -> String -> String-    jhead n cs-        | n < 10    = case unsafeChr (ord '0' + n) of-            c@(C# _) -> c : cs-        | otherwise = case unsafeChr (ord '0' + r) of-            c@(C# _) -> jhead q (c : cs)-        where-        (q, r) = n `quotRemInt` 10--    jblock = jblock' {- ' -} DIGITS--    jblock' :: Int -> Int -> String -> String-    jblock' d n cs-        | d == 1    = case unsafeChr (ord '0' + n) of-             c@(C# _) -> c : cs-        | otherwise = case unsafeChr (ord '0' + r) of-             c@(C# _) -> jblock' (d - 1) q (c : cs)-        where-        (q, r) = n `quotRemInt` 10-\end{code}-
− GHC/Show.lhs-boot
@@ -1,11 +0,0 @@-\begin{code}-{-# LANGUAGE Trustworthy #-}-{-# LANGUAGE NoImplicitPrelude #-}--module GHC.Show (showSignedInt) where--import GHC.Types--showSignedInt :: Int -> Int -> [Char] -> [Char]-\end{code}-
+ GHC/Stable.hs view
@@ -0,0 +1,111 @@+{-# LANGUAGE Unsafe #-}+{-# LANGUAGE NoImplicitPrelude+           , DeriveDataTypeable+           , MagicHash+           , UnboxedTuples+  #-}+{-# OPTIONS_HADDOCK hide #-}++-----------------------------------------------------------------------------+-- |+-- Module      :  GHC.Stable+-- Copyright   :  (c) The University of Glasgow, 1992-2004+-- License     :  see libraries/base/LICENSE+--+-- Maintainer  :  ffi@haskell.org+-- Stability   :  internal+-- Portability :  non-portable (GHC Extensions)+--+-- Stable pointers.+--+-----------------------------------------------------------------------------++module GHC.Stable (+        StablePtr(..),+        newStablePtr,+        deRefStablePtr,+        freeStablePtr,+        castStablePtrToPtr,+        castPtrToStablePtr+    ) where++import GHC.Ptr+import GHC.Base+import Data.Typeable.Internal++-----------------------------------------------------------------------------+-- Stable Pointers++{- |+A /stable pointer/ is a reference to a Haskell expression that is+guaranteed not to be affected by garbage collection, i.e., it will neither be+deallocated nor will the value of the stable pointer itself change during+garbage collection (ordinary references may be relocated during garbage+collection).  Consequently, stable pointers can be passed to foreign code,+which can treat it as an opaque reference to a Haskell value.++A value of type @StablePtr a@ is a stable pointer to a Haskell+expression of type @a@.+-}+data {-# CTYPE "HsStablePtr" #-} StablePtr a = StablePtr (StablePtr# a)+  deriving( Typeable )++-- |+-- Create a stable pointer referring to the given Haskell value.+--+newStablePtr   :: a -> IO (StablePtr a)+newStablePtr a = IO $ \ s ->+    case makeStablePtr# a s of (# s', sp #) -> (# s', StablePtr sp #)++-- |+-- Obtain the Haskell value referenced by a stable pointer, i.e., the+-- same value that was passed to the corresponding call to+-- 'makeStablePtr'.  If the argument to 'deRefStablePtr' has+-- already been freed using 'freeStablePtr', the behaviour of+-- 'deRefStablePtr' is undefined.+--+deRefStablePtr :: StablePtr a -> IO a+deRefStablePtr (StablePtr sp) = IO $ \s -> deRefStablePtr# sp s++-- |+-- Dissolve the association between the stable pointer and the Haskell+-- value. Afterwards, if the stable pointer is passed to+-- 'deRefStablePtr' or 'freeStablePtr', the behaviour is+-- undefined.  However, the stable pointer may still be passed to+-- 'castStablePtrToPtr', but the @'Foreign.Ptr.Ptr' ()@ value returned+-- by 'castStablePtrToPtr', in this case, is undefined (in particular,+-- it may be 'Foreign.Ptr.nullPtr').  Nevertheless, the call+-- to 'castStablePtrToPtr' is guaranteed not to diverge.+--+foreign import ccall unsafe "hs_free_stable_ptr" freeStablePtr :: StablePtr a -> IO ()++-- |+-- Coerce a stable pointer to an address. No guarantees are made about+-- the resulting value, except that the original stable pointer can be+-- recovered by 'castPtrToStablePtr'.  In particular, the address may not+-- refer to an accessible memory location and any attempt to pass it to+-- the member functions of the class 'Foreign.Storable.Storable' leads to+-- undefined behaviour.+--+castStablePtrToPtr :: StablePtr a -> Ptr ()+castStablePtrToPtr (StablePtr s) = Ptr (unsafeCoerce# s)+++-- |+-- The inverse of 'castStablePtrToPtr', i.e., we have the identity+--+-- > sp == castPtrToStablePtr (castStablePtrToPtr sp)+--+-- for any stable pointer @sp@ on which 'freeStablePtr' has+-- not been executed yet.  Moreover, 'castPtrToStablePtr' may+-- only be applied to pointers that have been produced by+-- 'castStablePtrToPtr'.+--+castPtrToStablePtr :: Ptr () -> StablePtr a+castPtrToStablePtr (Ptr a) = StablePtr (unsafeCoerce# a)++instance Eq (StablePtr a) where+    (StablePtr sp1) == (StablePtr sp2) =+        case eqStablePtr# sp1 sp2 of+           0# -> False+           _  -> True
− GHC/Stable.lhs
@@ -1,113 +0,0 @@-\begin{code}-{-# LANGUAGE Unsafe, DeriveDataTypeable #-}-{-# LANGUAGE NoImplicitPrelude-           , MagicHash-           , UnboxedTuples-  #-}-{-# OPTIONS_HADDOCK hide #-}---------------------------------------------------------------------------------- |--- Module      :  GHC.Stable--- Copyright   :  (c) The University of Glasgow, 1992-2004--- License     :  see libraries/base/LICENSE--- --- Maintainer  :  ffi@haskell.org--- Stability   :  internal--- Portability :  non-portable (GHC Extensions)------ Stable pointers.-----------------------------------------------------------------------------------module GHC.Stable (-        StablePtr(..),-        newStablePtr,-        deRefStablePtr,-        freeStablePtr,-        castStablePtrToPtr,-        castPtrToStablePtr-    ) where--import GHC.Ptr-import GHC.Base-import Data.Typeable.Internal---------------------------------------------------------------------------------- Stable Pointers--{- |-A /stable pointer/ is a reference to a Haskell expression that is-guaranteed not to be affected by garbage collection, i.e., it will neither be-deallocated nor will the value of the stable pointer itself change during-garbage collection (ordinary references may be relocated during garbage-collection).  Consequently, stable pointers can be passed to foreign code,-which can treat it as an opaque reference to a Haskell value.--A value of type @StablePtr a@ is a stable pointer to a Haskell-expression of type @a@.--}-data {-# CTYPE "HsStablePtr" #-} StablePtr a = StablePtr (StablePtr# a)-  deriving( Typeable )---- |--- Create a stable pointer referring to the given Haskell value.----newStablePtr   :: a -> IO (StablePtr a)-newStablePtr a = IO $ \ s ->-    case makeStablePtr# a s of (# s', sp #) -> (# s', StablePtr sp #)---- |--- Obtain the Haskell value referenced by a stable pointer, i.e., the--- same value that was passed to the corresponding call to--- 'makeStablePtr'.  If the argument to 'deRefStablePtr' has--- already been freed using 'freeStablePtr', the behaviour of--- 'deRefStablePtr' is undefined.----deRefStablePtr :: StablePtr a -> IO a-deRefStablePtr (StablePtr sp) = IO $ \s -> deRefStablePtr# sp s---- |--- Dissolve the association between the stable pointer and the Haskell--- value. Afterwards, if the stable pointer is passed to--- 'deRefStablePtr' or 'freeStablePtr', the behaviour is--- undefined.  However, the stable pointer may still be passed to--- 'castStablePtrToPtr', but the @'Foreign.Ptr.Ptr' ()@ value returned--- by 'castStablePtrToPtr', in this case, is undefined (in particular,--- it may be 'Foreign.Ptr.nullPtr').  Nevertheless, the call--- to 'castStablePtrToPtr' is guaranteed not to diverge.----foreign import ccall unsafe "hs_free_stable_ptr" freeStablePtr :: StablePtr a -> IO ()---- |--- Coerce a stable pointer to an address. No guarantees are made about--- the resulting value, except that the original stable pointer can be--- recovered by 'castPtrToStablePtr'.  In particular, the address may not--- refer to an accessible memory location and any attempt to pass it to--- the member functions of the class 'Foreign.Storable.Storable' leads to--- undefined behaviour.----castStablePtrToPtr :: StablePtr a -> Ptr ()-castStablePtrToPtr (StablePtr s) = Ptr (unsafeCoerce# s)----- |--- The inverse of 'castStablePtrToPtr', i.e., we have the identity--- --- > sp == castPtrToStablePtr (castStablePtrToPtr sp)--- --- for any stable pointer @sp@ on which 'freeStablePtr' has--- not been executed yet.  Moreover, 'castPtrToStablePtr' may--- only be applied to pointers that have been produced by--- 'castStablePtrToPtr'.----castPtrToStablePtr :: Ptr () -> StablePtr a-castPtrToStablePtr (Ptr a) = StablePtr (unsafeCoerce# a)--instance Eq (StablePtr a) where -    (StablePtr sp1) == (StablePtr sp2) =-        case eqStablePtr# sp1 sp2 of-           0# -> False-           _  -> True--\end{code}
GHC/Stack.hsc view
@@ -1,19 +1,21 @@+{-# LANGUAGE Trustworthy #-}+ ----------------------------------------------------------------------------- -- | -- Module      :  GHC.Stack -- Copyright   :  (c) The University of Glasgow 2011 -- License     :  see libraries/base/LICENSE--- +-- -- Maintainer  :  cvs-ghc@haskell.org -- Stability   :  internal -- Portability :  non-portable (GHC Extensions) -- -- Access to GHC's call-stack simulation ----- /Since: 4.5.0.0/+-- @since 4.5.0.0 ----------------------------------------------------------------------------- -{-# LANGUAGE UnboxedTuples, MagicHash #-}+{-# LANGUAGE UnboxedTuples, MagicHash, NoImplicitPrelude #-} module GHC.Stack (     -- * Call stack     currentCallStack,@@ -43,6 +45,7 @@ import GHC.Foreign as GHC import GHC.IO.Encoding import GHC.Exception+import GHC.List ( concatMap, null, reverse )  #define PROFILING #include "Rts.h"@@ -84,7 +87,7 @@ -- Otherwise, the list returned is likely to be empty or -- uninformative. ----- /Since: 4.5.0.0/+-- @since 4.5.0.0  currentCallStack :: IO [String] currentCallStack = ccsToStrings =<< getCurrentCCS ()@@ -106,7 +109,7 @@  -- | Get the stack trace attached to an object. ----- /Since: 4.5.0.0/+-- @since 4.5.0.0 whoCreated :: a -> IO [String] whoCreated obj = do   ccs <- getCCSOf obj@@ -118,7 +121,7 @@ -- | Like the function 'error', but appends a stack trace to the error -- message if one is available. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 errorWithStackTrace :: String -> a errorWithStackTrace x = unsafeDupablePerformIO $ do    stack <- ccsToStrings =<< getCurrentCCS x
+ GHC/StaticPtr.hs view
@@ -0,0 +1,117 @@+{-# LANGUAGE DeriveDataTypeable        #-}+{-# LANGUAGE MagicHash                 #-}+{-# LANGUAGE UnboxedTuples             #-}+{-# LANGUAGE ExistentialQuantification #-}+-----------------------------------------------------------------------------+-- |+-- Module      :  GHC.StaticPtr+-- Copyright   :  (C) 2014 I/O Tweag+-- License     :  see libraries/base/LICENSE+--+-- Maintainer  :  cvs-ghc@haskell.org+-- Stability   :  internal+-- Portability :  non-portable (GHC Extensions)+--+-- Symbolic references to values.+--+-- References to values are usually implemented with memory addresses, and this+-- is practical when communicating values between the different pieces of a+-- single process.+--+-- When values are communicated across different processes running in possibly+-- different machines, though, addresses are no longer useful since each+-- process may use different addresses to store a given value.+--+-- To solve such concern, the references provided by this module offer a key+-- that can be used to locate the values on each process. Each process maintains+-- a global table of references which can be looked up with a given key. This+-- table is known as the Static Pointer Table. The reference can then be+-- dereferenced to obtain the value.+--+-----------------------------------------------------------------------------++module GHC.StaticPtr+  ( StaticPtr+  , deRefStaticPtr+  , StaticKey+  , staticKey+  , unsafeLookupStaticPtr+  , StaticPtrInfo(..)+  , staticPtrInfo+  , staticPtrKeys+  ) where++import Data.Typeable       (Typeable)+import Foreign.C.Types     (CInt(..))+import Foreign.Marshal     (allocaArray, peekArray, withArray)+import Foreign.Ptr         (castPtr)+import GHC.Exts            (addrToAny#)+import GHC.Ptr             (Ptr(..), nullPtr)+import GHC.Fingerprint     (Fingerprint(..))+++-- | A reference to a value of type 'a'.+data StaticPtr a = StaticPtr StaticKey StaticPtrInfo a+  deriving Typeable++-- | Dereferences a static pointer.+deRefStaticPtr :: StaticPtr a -> a+deRefStaticPtr (StaticPtr _ _ v) = v++-- | A key for `StaticPtrs` that can be serialized and used with+-- 'unsafeLookupStaticPtr'.+type StaticKey = Fingerprint++-- | The 'StaticKey' that can be used to look up the given 'StaticPtr'.+staticKey :: StaticPtr a -> StaticKey+staticKey (StaticPtr k _ _) = k++-- | Looks up a 'StaticPtr' by its 'StaticKey'.+--+-- If the 'StaticPtr' is not found returns @Nothing@.+--+-- This function is unsafe because the program behavior is undefined if the type+-- of the returned 'StaticPtr' does not match the expected one.+--+unsafeLookupStaticPtr :: StaticKey -> IO (Maybe (StaticPtr a))+unsafeLookupStaticPtr (Fingerprint w1 w2) = do+    ptr@(Ptr addr) <- withArray [w1,w2] (hs_spt_lookup . castPtr)+    if (ptr == nullPtr)+    then return Nothing+    else case addrToAny# addr of+           (# spe #) -> return (Just spe)++foreign import ccall unsafe hs_spt_lookup :: Ptr () -> IO (Ptr a)++-- | Miscelaneous information available for debugging purposes.+data StaticPtrInfo = StaticPtrInfo+    { -- | Package key of the package where the static pointer is defined+      spInfoPackageKey  :: String+      -- | Name of the module where the static pointer is defined+    , spInfoModuleName :: String+      -- | An internal name that is distinct for every static pointer defined in+      -- a given module.+    , spInfoName       :: String+      -- | Source location of the definition of the static pointer as a+      -- @(Line, Column)@ pair.+    , spInfoSrcLoc     :: (Int, Int)+    }+  deriving (Show, Typeable)++-- | 'StaticPtrInfo' of the given 'StaticPtr'.+staticPtrInfo :: StaticPtr a -> StaticPtrInfo+staticPtrInfo (StaticPtr _ n _) = n++-- | A list of all known keys.+staticPtrKeys :: IO [StaticKey]+staticPtrKeys = do+    keyCount <- hs_spt_key_count+    allocaArray (fromIntegral keyCount) $ \p -> do+      count <- hs_spt_keys p keyCount+      peekArray (fromIntegral count) p >>=+        mapM (\pa -> peekArray 2 pa >>= \[w1, w2] -> return $ Fingerprint w1 w2)+{-# NOINLINE staticPtrKeys #-}++foreign import ccall unsafe hs_spt_key_count :: IO CInt++foreign import ccall unsafe hs_spt_keys :: Ptr a -> CInt -> IO CInt
GHC/Stats.hsc view
@@ -1,4 +1,5 @@-{-# LANGUAGE Safe #-}+{-# LANGUAGE Trustworthy #-}+{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE RecordWildCards #-} {-# OPTIONS_GHC -funbox-strict-fields #-} @@ -9,7 +10,7 @@ -- -- This module is GHC-only and should not be considered portable. ----- /Since: 4.5.0.0/+-- @since 4.5.0.0 ----------------------------------------------------------------------------- module GHC.Stats     ( GCStats(..)@@ -19,6 +20,9 @@  import Control.Monad import Data.Int+import GHC.Base+import GHC.Read ( Read )+import GHC.Show ( Show ) import GHC.IO.Exception import Foreign.Marshal.Alloc import Foreign.Storable@@ -30,14 +34,14 @@  -- | Returns whether GC stats have been enabled (with @+RTS -T@, for example). ----- /Since: 4.6.0.0/+-- @since 4.6.0.0 foreign import ccall "getGCStatsEnabled" getGCStatsEnabled :: IO Bool  -- I'm probably violating a bucket of constraints here... oops.  -- | Global garbage collection and memory statistics. ----- /Since: 4.5.0.0/+-- @since 4.5.0.0 data GCStats = GCStats     { bytesAllocated :: !Int64 -- ^ Total number of bytes allocated     , numGcs :: !Int64 -- ^ Number of garbage collections performed@@ -85,7 +89,7 @@ -- garbage collection.  If you would like your statistics as recent as -- possible, first run a 'System.Mem.performGC'. ----- /Since: 4.5.0.0/+-- @since 4.5.0.0 getGCStats :: IO GCStats getGCStats = do   statsEnabled <- getGCStatsEnabled
+ GHC/Storable.hs view
@@ -0,0 +1,158 @@+{-# LANGUAGE Trustworthy #-}+{-# LANGUAGE NoImplicitPrelude, MagicHash, UnboxedTuples #-}+{-# OPTIONS_HADDOCK hide #-}++-----------------------------------------------------------------------------+-- |+-- Module      :  GHC.Storable+-- Copyright   :  (c) The FFI task force, 2000-2002+-- License     :  see libraries/base/LICENSE+--+-- Maintainer  :  ffi@haskell.org+-- Stability   :  internal+-- Portability :  non-portable (GHC Extensions)+--+-- Helper functions for "Foreign.Storable"+--+-----------------------------------------------------------------------------++module GHC.Storable+        ( readWideCharOffPtr+        , readIntOffPtr+        , readWordOffPtr+        , readPtrOffPtr+        , readFunPtrOffPtr+        , readFloatOffPtr+        , readDoubleOffPtr+        , readStablePtrOffPtr+        , readInt8OffPtr+        , readInt16OffPtr+        , readInt32OffPtr+        , readInt64OffPtr+        , readWord8OffPtr+        , readWord16OffPtr+        , readWord32OffPtr+        , readWord64OffPtr+        , writeWideCharOffPtr+        , writeIntOffPtr+        , writeWordOffPtr+        , writePtrOffPtr+        , writeFunPtrOffPtr+        , writeFloatOffPtr+        , writeDoubleOffPtr+        , writeStablePtrOffPtr+        , writeInt8OffPtr+        , writeInt16OffPtr+        , writeInt32OffPtr+        , writeInt64OffPtr+        , writeWord8OffPtr+        , writeWord16OffPtr+        , writeWord32OffPtr+        , writeWord64OffPtr+        ) where++import GHC.Stable ( StablePtr(..) )+import GHC.Int+import GHC.Word+import GHC.Ptr+import GHC.Base++readWideCharOffPtr  :: Ptr Char          -> Int -> IO Char+readIntOffPtr       :: Ptr Int           -> Int -> IO Int+readWordOffPtr      :: Ptr Word          -> Int -> IO Word+readPtrOffPtr       :: Ptr (Ptr a)       -> Int -> IO (Ptr a)+readFunPtrOffPtr    :: Ptr (FunPtr a)    -> Int -> IO (FunPtr a)+readFloatOffPtr     :: Ptr Float         -> Int -> IO Float+readDoubleOffPtr    :: Ptr Double        -> Int -> IO Double+readStablePtrOffPtr :: Ptr (StablePtr a) -> Int -> IO (StablePtr a)+readInt8OffPtr      :: Ptr Int8          -> Int -> IO Int8+readInt16OffPtr     :: Ptr Int16         -> Int -> IO Int16+readInt32OffPtr     :: Ptr Int32         -> Int -> IO Int32+readInt64OffPtr     :: Ptr Int64         -> Int -> IO Int64+readWord8OffPtr     :: Ptr Word8         -> Int -> IO Word8+readWord16OffPtr    :: Ptr Word16        -> Int -> IO Word16+readWord32OffPtr    :: Ptr Word32        -> Int -> IO Word32+readWord64OffPtr    :: Ptr Word64        -> Int -> IO Word64++readWideCharOffPtr (Ptr a) (I# i)+  = IO $ \s -> case readWideCharOffAddr# a i s  of (# s2, x #) -> (# s2, C# x #)+readIntOffPtr (Ptr a) (I# i)+  = IO $ \s -> case readIntOffAddr# a i s       of (# s2, x #) -> (# s2, I# x #)+readWordOffPtr (Ptr a) (I# i)+  = IO $ \s -> case readWordOffAddr# a i s      of (# s2, x #) -> (# s2, W# x #)+readPtrOffPtr (Ptr a) (I# i)+  = IO $ \s -> case readAddrOffAddr# a i s      of (# s2, x #) -> (# s2, Ptr x #)+readFunPtrOffPtr (Ptr a) (I# i)+  = IO $ \s -> case readAddrOffAddr# a i s      of (# s2, x #) -> (# s2, FunPtr x #)+readFloatOffPtr (Ptr a) (I# i)+  = IO $ \s -> case readFloatOffAddr# a i s     of (# s2, x #) -> (# s2, F# x #)+readDoubleOffPtr (Ptr a) (I# i)+  = IO $ \s -> case readDoubleOffAddr# a i s    of (# s2, x #) -> (# s2, D# x #)+readStablePtrOffPtr (Ptr a) (I# i)+  = IO $ \s -> case readStablePtrOffAddr# a i s of (# s2, x #) -> (# s2, StablePtr x #)+readInt8OffPtr (Ptr a) (I# i)+  = IO $ \s -> case readInt8OffAddr# a i s      of (# s2, x #) -> (# s2, I8# x #)+readWord8OffPtr (Ptr a) (I# i)+  = IO $ \s -> case readWord8OffAddr# a i s     of (# s2, x #) -> (# s2, W8# x #)+readInt16OffPtr (Ptr a) (I# i)+  = IO $ \s -> case readInt16OffAddr# a i s     of (# s2, x #) -> (# s2, I16# x #)+readWord16OffPtr (Ptr a) (I# i)+  = IO $ \s -> case readWord16OffAddr# a i s    of (# s2, x #) -> (# s2, W16# x #)+readInt32OffPtr (Ptr a) (I# i)+  = IO $ \s -> case readInt32OffAddr# a i s     of (# s2, x #) -> (# s2, I32# x #)+readWord32OffPtr (Ptr a) (I# i)+  = IO $ \s -> case readWord32OffAddr# a i s    of (# s2, x #) -> (# s2, W32# x #)+readInt64OffPtr (Ptr a) (I# i)+  = IO $ \s -> case readInt64OffAddr# a i s     of (# s2, x #) -> (# s2, I64# x #)+readWord64OffPtr (Ptr a) (I# i)+  = IO $ \s -> case readWord64OffAddr# a i s    of (# s2, x #) -> (# s2, W64# x #)++writeWideCharOffPtr  :: Ptr Char          -> Int -> Char        -> IO ()+writeIntOffPtr       :: Ptr Int           -> Int -> Int         -> IO ()+writeWordOffPtr      :: Ptr Word          -> Int -> Word        -> IO ()+writePtrOffPtr       :: Ptr (Ptr a)       -> Int -> Ptr a       -> IO ()+writeFunPtrOffPtr    :: Ptr (FunPtr a)    -> Int -> FunPtr a    -> IO ()+writeFloatOffPtr     :: Ptr Float         -> Int -> Float       -> IO ()+writeDoubleOffPtr    :: Ptr Double        -> Int -> Double      -> IO ()+writeStablePtrOffPtr :: Ptr (StablePtr a) -> Int -> StablePtr a -> IO ()+writeInt8OffPtr      :: Ptr Int8          -> Int -> Int8        -> IO ()+writeInt16OffPtr     :: Ptr Int16         -> Int -> Int16       -> IO ()+writeInt32OffPtr     :: Ptr Int32         -> Int -> Int32       -> IO ()+writeInt64OffPtr     :: Ptr Int64         -> Int -> Int64       -> IO ()+writeWord8OffPtr     :: Ptr Word8         -> Int -> Word8       -> IO ()+writeWord16OffPtr    :: Ptr Word16        -> Int -> Word16      -> IO ()+writeWord32OffPtr    :: Ptr Word32        -> Int -> Word32      -> IO ()+writeWord64OffPtr    :: Ptr Word64        -> Int -> Word64      -> IO ()++writeWideCharOffPtr (Ptr a) (I# i) (C# x)+  = IO $ \s -> case writeWideCharOffAddr# a i x s  of s2 -> (# s2, () #)+writeIntOffPtr (Ptr a) (I# i) (I# x)+  = IO $ \s -> case writeIntOffAddr# a i x s       of s2 -> (# s2, () #)+writeWordOffPtr (Ptr a) (I# i) (W# x)+  = IO $ \s -> case writeWordOffAddr# a i x s      of s2 -> (# s2, () #)+writePtrOffPtr (Ptr a) (I# i) (Ptr x)+  = IO $ \s -> case writeAddrOffAddr# a i x s      of s2 -> (# s2, () #)+writeFunPtrOffPtr (Ptr a) (I# i) (FunPtr x)+  = IO $ \s -> case writeAddrOffAddr# a i x s      of s2 -> (# s2, () #)+writeFloatOffPtr (Ptr a) (I# i) (F# x)+  = IO $ \s -> case writeFloatOffAddr# a i x s     of s2 -> (# s2, () #)+writeDoubleOffPtr (Ptr a) (I# i) (D# x)+  = IO $ \s -> case writeDoubleOffAddr# a i x s    of s2 -> (# s2, () #)+writeStablePtrOffPtr (Ptr a) (I# i) (StablePtr x)+  = IO $ \s -> case writeStablePtrOffAddr# a i x s of s2 -> (# s2 , () #)+writeInt8OffPtr (Ptr a) (I# i) (I8# x)+  = IO $ \s -> case writeInt8OffAddr# a i x s      of s2 -> (# s2, () #)+writeWord8OffPtr (Ptr a) (I# i) (W8# x)+  = IO $ \s -> case writeWord8OffAddr# a i x s     of s2 -> (# s2, () #)+writeInt16OffPtr (Ptr a) (I# i) (I16# x)+  = IO $ \s -> case writeInt16OffAddr# a i x s     of s2 -> (# s2, () #)+writeWord16OffPtr (Ptr a) (I# i) (W16# x)+  = IO $ \s -> case writeWord16OffAddr# a i x s    of s2 -> (# s2, () #)+writeInt32OffPtr (Ptr a) (I# i) (I32# x)+  = IO $ \s -> case writeInt32OffAddr# a i x s     of s2 -> (# s2, () #)+writeWord32OffPtr (Ptr a) (I# i) (W32# x)+  = IO $ \s -> case writeWord32OffAddr# a i x s    of s2 -> (# s2, () #)+writeInt64OffPtr (Ptr a) (I# i) (I64# x)+  = IO $ \s -> case writeInt64OffAddr# a i x s     of s2 -> (# s2, () #)+writeWord64OffPtr (Ptr a) (I# i) (W64# x)+  = IO $ \s -> case writeWord64OffAddr# a i x s    of s2 -> (# s2, () #)
− GHC/Storable.lhs
@@ -1,164 +0,0 @@-\begin{code}-{-# LANGUAGE Trustworthy #-}-{-# LANGUAGE NoImplicitPrelude, MagicHash, UnboxedTuples #-}-{-# OPTIONS_HADDOCK hide #-}---------------------------------------------------------------------------------- |--- Module      :  GHC.Storable--- Copyright   :  (c) The FFI task force, 2000-2002--- License     :  see libraries/base/LICENSE--- --- Maintainer  :  ffi@haskell.org--- Stability   :  internal--- Portability :  non-portable (GHC Extensions)------ Helper functions for "Foreign.Storable"-----------------------------------------------------------------------------------module GHC.Storable-        ( readWideCharOffPtr  -        , readIntOffPtr       -        , readWordOffPtr      -        , readPtrOffPtr       -        , readFunPtrOffPtr    -        , readFloatOffPtr     -        , readDoubleOffPtr    -        , readStablePtrOffPtr -        , readInt8OffPtr      -        , readInt16OffPtr     -        , readInt32OffPtr     -        , readInt64OffPtr     -        , readWord8OffPtr     -        , readWord16OffPtr    -        , readWord32OffPtr    -        , readWord64OffPtr    -        , writeWideCharOffPtr -        , writeIntOffPtr      -        , writeWordOffPtr     -        , writePtrOffPtr      -        , writeFunPtrOffPtr   -        , writeFloatOffPtr    -        , writeDoubleOffPtr   -        , writeStablePtrOffPtr-        , writeInt8OffPtr     -        , writeInt16OffPtr    -        , writeInt32OffPtr    -        , writeInt64OffPtr    -        , writeWord8OffPtr    -        , writeWord16OffPtr   -        , writeWord32OffPtr   -        , writeWord64OffPtr   -        ) where--import GHC.Stable ( StablePtr(..) )-import GHC.Int-import GHC.Word-import GHC.Ptr-import GHC.Base-\end{code}--\begin{code}--readWideCharOffPtr  :: Ptr Char          -> Int -> IO Char-readIntOffPtr       :: Ptr Int           -> Int -> IO Int-readWordOffPtr      :: Ptr Word          -> Int -> IO Word-readPtrOffPtr       :: Ptr (Ptr a)       -> Int -> IO (Ptr a)-readFunPtrOffPtr    :: Ptr (FunPtr a)    -> Int -> IO (FunPtr a)-readFloatOffPtr     :: Ptr Float         -> Int -> IO Float-readDoubleOffPtr    :: Ptr Double        -> Int -> IO Double-readStablePtrOffPtr :: Ptr (StablePtr a) -> Int -> IO (StablePtr a)-readInt8OffPtr      :: Ptr Int8          -> Int -> IO Int8-readInt16OffPtr     :: Ptr Int16         -> Int -> IO Int16-readInt32OffPtr     :: Ptr Int32         -> Int -> IO Int32-readInt64OffPtr     :: Ptr Int64         -> Int -> IO Int64-readWord8OffPtr     :: Ptr Word8         -> Int -> IO Word8-readWord16OffPtr    :: Ptr Word16        -> Int -> IO Word16-readWord32OffPtr    :: Ptr Word32        -> Int -> IO Word32-readWord64OffPtr    :: Ptr Word64        -> Int -> IO Word64--readWideCharOffPtr (Ptr a) (I# i)-  = IO $ \s -> case readWideCharOffAddr# a i s  of (# s2, x #) -> (# s2, C# x #)-readIntOffPtr (Ptr a) (I# i)-  = IO $ \s -> case readIntOffAddr# a i s       of (# s2, x #) -> (# s2, I# x #)-readWordOffPtr (Ptr a) (I# i)-  = IO $ \s -> case readWordOffAddr# a i s      of (# s2, x #) -> (# s2, W# x #)-readPtrOffPtr (Ptr a) (I# i)-  = IO $ \s -> case readAddrOffAddr# a i s      of (# s2, x #) -> (# s2, Ptr x #)-readFunPtrOffPtr (Ptr a) (I# i)-  = IO $ \s -> case readAddrOffAddr# a i s      of (# s2, x #) -> (# s2, FunPtr x #)-readFloatOffPtr (Ptr a) (I# i)-  = IO $ \s -> case readFloatOffAddr# a i s     of (# s2, x #) -> (# s2, F# x #)-readDoubleOffPtr (Ptr a) (I# i)-  = IO $ \s -> case readDoubleOffAddr# a i s    of (# s2, x #) -> (# s2, D# x #)-readStablePtrOffPtr (Ptr a) (I# i)-  = IO $ \s -> case readStablePtrOffAddr# a i s of (# s2, x #) -> (# s2, StablePtr x #)-readInt8OffPtr (Ptr a) (I# i)-  = IO $ \s -> case readInt8OffAddr# a i s      of (# s2, x #) -> (# s2, I8# x #)-readWord8OffPtr (Ptr a) (I# i)-  = IO $ \s -> case readWord8OffAddr# a i s     of (# s2, x #) -> (# s2, W8# x #)-readInt16OffPtr (Ptr a) (I# i)-  = IO $ \s -> case readInt16OffAddr# a i s     of (# s2, x #) -> (# s2, I16# x #)-readWord16OffPtr (Ptr a) (I# i)-  = IO $ \s -> case readWord16OffAddr# a i s    of (# s2, x #) -> (# s2, W16# x #)-readInt32OffPtr (Ptr a) (I# i)-  = IO $ \s -> case readInt32OffAddr# a i s     of (# s2, x #) -> (# s2, I32# x #)-readWord32OffPtr (Ptr a) (I# i)-  = IO $ \s -> case readWord32OffAddr# a i s    of (# s2, x #) -> (# s2, W32# x #)-readInt64OffPtr (Ptr a) (I# i)-  = IO $ \s -> case readInt64OffAddr# a i s     of (# s2, x #) -> (# s2, I64# x #)-readWord64OffPtr (Ptr a) (I# i)-  = IO $ \s -> case readWord64OffAddr# a i s    of (# s2, x #) -> (# s2, W64# x #)--writeWideCharOffPtr  :: Ptr Char          -> Int -> Char        -> IO ()-writeIntOffPtr       :: Ptr Int           -> Int -> Int         -> IO ()-writeWordOffPtr      :: Ptr Word          -> Int -> Word        -> IO ()-writePtrOffPtr       :: Ptr (Ptr a)       -> Int -> Ptr a       -> IO ()-writeFunPtrOffPtr    :: Ptr (FunPtr a)    -> Int -> FunPtr a    -> IO ()-writeFloatOffPtr     :: Ptr Float         -> Int -> Float       -> IO ()-writeDoubleOffPtr    :: Ptr Double        -> Int -> Double      -> IO ()-writeStablePtrOffPtr :: Ptr (StablePtr a) -> Int -> StablePtr a -> IO ()-writeInt8OffPtr      :: Ptr Int8          -> Int -> Int8        -> IO ()-writeInt16OffPtr     :: Ptr Int16         -> Int -> Int16       -> IO ()-writeInt32OffPtr     :: Ptr Int32         -> Int -> Int32       -> IO ()-writeInt64OffPtr     :: Ptr Int64         -> Int -> Int64       -> IO ()-writeWord8OffPtr     :: Ptr Word8         -> Int -> Word8       -> IO ()-writeWord16OffPtr    :: Ptr Word16        -> Int -> Word16      -> IO ()-writeWord32OffPtr    :: Ptr Word32        -> Int -> Word32      -> IO ()-writeWord64OffPtr    :: Ptr Word64        -> Int -> Word64      -> IO ()--writeWideCharOffPtr (Ptr a) (I# i) (C# x)-  = IO $ \s -> case writeWideCharOffAddr# a i x s  of s2 -> (# s2, () #)-writeIntOffPtr (Ptr a) (I# i) (I# x)-  = IO $ \s -> case writeIntOffAddr# a i x s       of s2 -> (# s2, () #)-writeWordOffPtr (Ptr a) (I# i) (W# x)-  = IO $ \s -> case writeWordOffAddr# a i x s      of s2 -> (# s2, () #)-writePtrOffPtr (Ptr a) (I# i) (Ptr x)-  = IO $ \s -> case writeAddrOffAddr# a i x s      of s2 -> (# s2, () #)-writeFunPtrOffPtr (Ptr a) (I# i) (FunPtr x)-  = IO $ \s -> case writeAddrOffAddr# a i x s      of s2 -> (# s2, () #)-writeFloatOffPtr (Ptr a) (I# i) (F# x)-  = IO $ \s -> case writeFloatOffAddr# a i x s     of s2 -> (# s2, () #)-writeDoubleOffPtr (Ptr a) (I# i) (D# x)-  = IO $ \s -> case writeDoubleOffAddr# a i x s    of s2 -> (# s2, () #)-writeStablePtrOffPtr (Ptr a) (I# i) (StablePtr x)-  = IO $ \s -> case writeStablePtrOffAddr# a i x s of s2 -> (# s2 , () #)-writeInt8OffPtr (Ptr a) (I# i) (I8# x)-  = IO $ \s -> case writeInt8OffAddr# a i x s      of s2 -> (# s2, () #)-writeWord8OffPtr (Ptr a) (I# i) (W8# x)-  = IO $ \s -> case writeWord8OffAddr# a i x s     of s2 -> (# s2, () #)-writeInt16OffPtr (Ptr a) (I# i) (I16# x)-  = IO $ \s -> case writeInt16OffAddr# a i x s     of s2 -> (# s2, () #)-writeWord16OffPtr (Ptr a) (I# i) (W16# x)-  = IO $ \s -> case writeWord16OffAddr# a i x s    of s2 -> (# s2, () #)-writeInt32OffPtr (Ptr a) (I# i) (I32# x)-  = IO $ \s -> case writeInt32OffAddr# a i x s     of s2 -> (# s2, () #)-writeWord32OffPtr (Ptr a) (I# i) (W32# x)-  = IO $ \s -> case writeWord32OffAddr# a i x s    of s2 -> (# s2, () #)-writeInt64OffPtr (Ptr a) (I# i) (I64# x)-  = IO $ \s -> case writeInt64OffAddr# a i x s     of s2 -> (# s2, () #)-writeWord64OffPtr (Ptr a) (I# i) (W64# x)-  = IO $ \s -> case writeWord64OffAddr# a i x s    of s2 -> (# s2, () #)--\end{code}
+ GHC/TopHandler.hs view
@@ -0,0 +1,222 @@+{-# LANGUAGE Trustworthy #-}+{-# LANGUAGE CPP+           , NoImplicitPrelude+           , MagicHash+           , UnboxedTuples+  #-}+{-# OPTIONS_HADDOCK hide #-}++-----------------------------------------------------------------------------+-- |+-- Module      :  GHC.TopHandler+-- Copyright   :  (c) The University of Glasgow, 2001-2002+-- License     :  see libraries/base/LICENSE+--+-- Maintainer  :  cvs-ghc@haskell.org+-- Stability   :  internal+-- Portability :  non-portable (GHC Extensions)+--+-- Support for catching exceptions raised during top-level computations+-- (e.g. @Main.main@, 'Control.Concurrent.forkIO', and foreign exports)+--+-----------------------------------------------------------------------------++module GHC.TopHandler (+        runMainIO, runIO, runIOFastExit, runNonIO,+        topHandler, topHandlerFastExit,+        reportStackOverflow, reportError,+        flushStdHandles+    ) where++#include "HsBaseConfig.h"++import Control.Exception+import Data.Maybe++import Foreign+import Foreign.C+import GHC.Base+import GHC.Conc hiding (throwTo)+import GHC.Real+import GHC.IO+import GHC.IO.Handle.FD+import GHC.IO.Handle+import GHC.IO.Exception+import GHC.Weak++#if defined(mingw32_HOST_OS)+import GHC.ConsoleHandler+#else+import Data.Dynamic (toDyn)+#endif++-- | 'runMainIO' is wrapped around 'Main.main' (or whatever main is+-- called in the program).  It catches otherwise uncaught exceptions,+-- and also flushes stdout\/stderr before exiting.+runMainIO :: IO a -> IO a+runMainIO main =+    do+      main_thread_id <- myThreadId+      weak_tid <- mkWeakThreadId main_thread_id+      install_interrupt_handler $ do+           m <- deRefWeak weak_tid+           case m of+               Nothing  -> return ()+               Just tid -> throwTo tid (toException UserInterrupt)+      main -- hs_exit() will flush+    `catch`+      topHandler++install_interrupt_handler :: IO () -> IO ()+#ifdef mingw32_HOST_OS+install_interrupt_handler handler = do+  _ <- GHC.ConsoleHandler.installHandler $+     Catch $ \event ->+        case event of+           ControlC -> handler+           Break    -> handler+           Close    -> handler+           _ -> return ()+  return ()+#else+#include "rts/Signals.h"+-- specialised version of System.Posix.Signals.installHandler, which+-- isn't available here.+install_interrupt_handler handler = do+   let sig = CONST_SIGINT :: CInt+   _ <- setHandler sig (Just (const handler, toDyn handler))+   _ <- stg_sig_install sig STG_SIG_RST nullPtr+     -- STG_SIG_RST: the second ^C kills us for real, just in case the+     -- RTS or program is unresponsive.+   return ()++foreign import ccall unsafe+  stg_sig_install+        :: CInt                         -- sig no.+        -> CInt                         -- action code (STG_SIG_HAN etc.)+        -> Ptr ()                       -- (in, out) blocked+        -> IO CInt                      -- (ret) old action code+#endif++-- | 'runIO' is wrapped around every @foreign export@ and @foreign+-- import \"wrapper\"@ to mop up any uncaught exceptions.  Thus, the+-- result of running 'System.Exit.exitWith' in a foreign-exported+-- function is the same as in the main thread: it terminates the+-- program.+--+runIO :: IO a -> IO a+runIO main = catch main topHandler++-- | Like 'runIO', but in the event of an exception that causes an exit,+-- we don't shut down the system cleanly, we just exit.  This is+-- useful in some cases, because the safe exit version will give other+-- threads a chance to clean up first, which might shut down the+-- system in a different way.  For example, try+--+--   main = forkIO (runIO (exitWith (ExitFailure 1))) >> threadDelay 10000+--+-- This will sometimes exit with "interrupted" and code 0, because the+-- main thread is given a chance to shut down when the child thread calls+-- safeExit.  There is a race to shut down between the main and child threads.+--+runIOFastExit :: IO a -> IO a+runIOFastExit main = catch main topHandlerFastExit+        -- NB. this is used by the testsuite driver++-- | The same as 'runIO', but for non-IO computations.  Used for+-- wrapping @foreign export@ and @foreign import \"wrapper\"@ when these+-- are used to export Haskell functions with non-IO types.+--+runNonIO :: a -> IO a+runNonIO a = catch (a `seq` return a) topHandler++topHandler :: SomeException -> IO a+topHandler err = catch (real_handler safeExit err) topHandler++topHandlerFastExit :: SomeException -> IO a+topHandlerFastExit err =+  catchException (real_handler fastExit err) topHandlerFastExit++-- Make sure we handle errors while reporting the error!+-- (e.g. evaluating the string passed to 'error' might generate+--  another error, etc.)+--+real_handler :: (Int -> IO a) -> SomeException -> IO a+real_handler exit se = do+  flushStdHandles -- before any error output+  case fromException se of+      Just StackOverflow -> do+           reportStackOverflow+           exit 2++      Just UserInterrupt  -> exitInterrupted++      _ -> case fromException se of+           -- only the main thread gets ExitException exceptions+           Just ExitSuccess     -> exit 0+           Just (ExitFailure n) -> exit n++           -- EPIPE errors received for stdout are ignored (#2699)+           _ -> case fromException se of+                Just IOError{ ioe_type = ResourceVanished,+                              ioe_errno = Just ioe,+                              ioe_handle = Just hdl }+                   | Errno ioe == ePIPE, hdl == stdout -> exit 0+                _ -> do reportError se+                        exit 1+++-- try to flush stdout/stderr, but don't worry if we fail+-- (these handles might have errors, and we don't want to go into+-- an infinite loop).+flushStdHandles :: IO ()+flushStdHandles = do+  hFlush stdout `catchAny` \_ -> return ()+  hFlush stderr `catchAny` \_ -> return ()++safeExit, fastExit :: Int -> IO a+safeExit = exitHelper useSafeExit+fastExit = exitHelper useFastExit++unreachable :: IO a+unreachable = fail "If you can read this, shutdownHaskellAndExit did not exit."++exitHelper :: CInt -> Int -> IO a+#ifdef mingw32_HOST_OS+exitHelper exitKind r =+  shutdownHaskellAndExit (fromIntegral r) exitKind >> unreachable+#else+-- On Unix we use an encoding for the ExitCode:+--      0 -- 255  normal exit code+--   -127 -- -1   exit by signal+-- For any invalid encoding we just use a replacement (0xff).+exitHelper exitKind r+  | r >= 0 && r <= 255+  = shutdownHaskellAndExit   (fromIntegral   r)  exitKind >> unreachable+  | r >= -127 && r <= -1+  = shutdownHaskellAndSignal (fromIntegral (-r)) exitKind >> unreachable+  | otherwise+  = shutdownHaskellAndExit   0xff                exitKind >> unreachable++foreign import ccall "shutdownHaskellAndSignal"+  shutdownHaskellAndSignal :: CInt -> CInt -> IO ()+#endif++exitInterrupted :: IO a+exitInterrupted =+#ifdef mingw32_HOST_OS+  safeExit 252+#else+  -- we must exit via the default action for SIGINT, so that the+  -- parent of this process can take appropriate action (see #2301)+  safeExit (-CONST_SIGINT)+#endif++-- NOTE: shutdownHaskellAndExit must be called "safe", because it *can*+-- re-enter Haskell land through finalizers.+foreign import ccall "Rts.h shutdownHaskellAndExit"+  shutdownHaskellAndExit :: CInt -> CInt -> IO ()++useFastExit, useSafeExit :: CInt+useFastExit = 1+useSafeExit = 0
− GHC/TopHandler.lhs
@@ -1,227 +0,0 @@-\begin{code}-{-# LANGUAGE Trustworthy #-}-{-# LANGUAGE CPP-           , NoImplicitPrelude-           , MagicHash-           , UnboxedTuples-  #-}-{-# OPTIONS_GHC -fno-warn-unused-imports #-}-{-# OPTIONS_HADDOCK hide #-}---------------------------------------------------------------------------------- |--- Module      :  GHC.TopHandler--- Copyright   :  (c) The University of Glasgow, 2001-2002--- License     :  see libraries/base/LICENSE--- --- Maintainer  :  cvs-ghc@haskell.org--- Stability   :  internal--- Portability :  non-portable (GHC Extensions)------ Support for catching exceptions raised during top-level computations--- (e.g. @Main.main@, 'Control.Concurrent.forkIO', and foreign exports)-----------------------------------------------------------------------------------module GHC.TopHandler (-        runMainIO, runIO, runIOFastExit, runNonIO,-        topHandler, topHandlerFastExit,-        reportStackOverflow, reportError,-        flushStdHandles-    ) where--#include "HsBaseConfig.h"--import Control.Exception-import Data.Maybe-import Data.Dynamic (toDyn)--import Foreign-import Foreign.C-import GHC.Base-import GHC.Conc hiding (throwTo)-import GHC.Num-import GHC.Real-import GHC.MVar-import GHC.IO-import GHC.IO.Handle.FD-import GHC.IO.Handle-import GHC.IO.Exception-import GHC.Weak-import Data.Typeable-#if defined(mingw32_HOST_OS)-import GHC.ConsoleHandler-#endif---- | 'runMainIO' is wrapped around 'Main.main' (or whatever main is--- called in the program).  It catches otherwise uncaught exceptions,--- and also flushes stdout\/stderr before exiting.-runMainIO :: IO a -> IO a-runMainIO main = -    do -      main_thread_id <- myThreadId-      weak_tid <- mkWeakThreadId main_thread_id-      install_interrupt_handler $ do-           m <- deRefWeak weak_tid -           case m of-               Nothing  -> return ()-               Just tid -> throwTo tid (toException UserInterrupt)-      main -- hs_exit() will flush-    `catch`-      topHandler--install_interrupt_handler :: IO () -> IO ()-#ifdef mingw32_HOST_OS-install_interrupt_handler handler = do-  _ <- GHC.ConsoleHandler.installHandler $-     Catch $ \event -> -        case event of-           ControlC -> handler-           Break    -> handler-           Close    -> handler-           _ -> return ()-  return ()-#else-#include "rts/Signals.h"--- specialised version of System.Posix.Signals.installHandler, which--- isn't available here.-install_interrupt_handler handler = do-   let sig = CONST_SIGINT :: CInt-   _ <- setHandler sig (Just (const handler, toDyn handler))-   _ <- stg_sig_install sig STG_SIG_RST nullPtr-     -- STG_SIG_RST: the second ^C kills us for real, just in case the-     -- RTS or program is unresponsive.-   return ()--foreign import ccall unsafe-  stg_sig_install-	:: CInt				-- sig no.-	-> CInt				-- action code (STG_SIG_HAN etc.)-	-> Ptr ()			-- (in, out) blocked-	-> IO CInt			-- (ret) old action code-#endif---- | 'runIO' is wrapped around every @foreign export@ and @foreign--- import \"wrapper\"@ to mop up any uncaught exceptions.  Thus, the--- result of running 'System.Exit.exitWith' in a foreign-exported--- function is the same as in the main thread: it terminates the--- program.----runIO :: IO a -> IO a-runIO main = catch main topHandler---- | Like 'runIO', but in the event of an exception that causes an exit,--- we don't shut down the system cleanly, we just exit.  This is--- useful in some cases, because the safe exit version will give other--- threads a chance to clean up first, which might shut down the--- system in a different way.  For example, try ------   main = forkIO (runIO (exitWith (ExitFailure 1))) >> threadDelay 10000------ This will sometimes exit with "interrupted" and code 0, because the--- main thread is given a chance to shut down when the child thread calls--- safeExit.  There is a race to shut down between the main and child threads.----runIOFastExit :: IO a -> IO a-runIOFastExit main = catch main topHandlerFastExit-        -- NB. this is used by the testsuite driver---- | The same as 'runIO', but for non-IO computations.  Used for--- wrapping @foreign export@ and @foreign import \"wrapper\"@ when these--- are used to export Haskell functions with non-IO types.----runNonIO :: a -> IO a-runNonIO a = catch (a `seq` return a) topHandler--topHandler :: SomeException -> IO a-topHandler err = catch (real_handler safeExit err) topHandler--topHandlerFastExit :: SomeException -> IO a-topHandlerFastExit err = -  catchException (real_handler fastExit err) topHandlerFastExit---- Make sure we handle errors while reporting the error!--- (e.g. evaluating the string passed to 'error' might generate---  another error, etc.)----real_handler :: (Int -> IO a) -> SomeException -> IO a-real_handler exit se = do-  flushStdHandles -- before any error output-  case fromException se of-      Just StackOverflow -> do-           reportStackOverflow-           exit 2--      Just UserInterrupt  -> exitInterrupted--      _ -> case fromException se of-           -- only the main thread gets ExitException exceptions-           Just ExitSuccess     -> exit 0-           Just (ExitFailure n) -> exit n--           -- EPIPE errors received for stdout are ignored (#2699)-           _ -> case fromException se of-                Just IOError{ ioe_type = ResourceVanished,-                              ioe_errno = Just ioe,-                              ioe_handle = Just hdl }-                   | Errno ioe == ePIPE, hdl == stdout -> exit 0-                _ -> do reportError se-                        exit 1-           ---- try to flush stdout/stderr, but don't worry if we fail--- (these handles might have errors, and we don't want to go into--- an infinite loop).-flushStdHandles :: IO ()-flushStdHandles = do-  hFlush stdout `catchAny` \_ -> return ()-  hFlush stderr `catchAny` \_ -> return ()--safeExit, fastExit :: Int -> IO a-safeExit = exitHelper useSafeExit-fastExit = exitHelper useFastExit--unreachable :: IO a-unreachable = fail "If you can read this, shutdownHaskellAndExit did not exit."--exitHelper :: CInt -> Int -> IO a-#ifdef mingw32_HOST_OS-exitHelper exitKind r =-  shutdownHaskellAndExit (fromIntegral r) exitKind >> unreachable-#else--- On Unix we use an encoding for the ExitCode:---      0 -- 255  normal exit code---   -127 -- -1   exit by signal--- For any invalid encoding we just use a replacement (0xff).-exitHelper exitKind r-  | r >= 0 && r <= 255-  = shutdownHaskellAndExit   (fromIntegral   r)  exitKind >> unreachable-  | r >= -127 && r <= -1-  = shutdownHaskellAndSignal (fromIntegral (-r)) exitKind >> unreachable-  | otherwise-  = shutdownHaskellAndExit   0xff                exitKind >> unreachable--foreign import ccall "shutdownHaskellAndSignal"-  shutdownHaskellAndSignal :: CInt -> CInt -> IO ()-#endif--exitInterrupted :: IO a-exitInterrupted = -#ifdef mingw32_HOST_OS-  safeExit 252-#else-  -- we must exit via the default action for SIGINT, so that the-  -- parent of this process can take appropriate action (see #2301)-  safeExit (-CONST_SIGINT)-#endif---- NOTE: shutdownHaskellAndExit must be called "safe", because it *can*--- re-enter Haskell land through finalizers.-foreign import ccall "Rts.h shutdownHaskellAndExit"-  shutdownHaskellAndExit :: CInt -> CInt -> IO ()--useFastExit, useSafeExit :: CInt-useFastExit = 1-useSafeExit = 0--\end{code}
GHC/TypeLits.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE Trustworthy #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE KindSignatures #-} {-# LANGUAGE TypeFamilies #-}@@ -9,12 +10,14 @@ {-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE UndecidableInstances #-}  -- for compiling instances of (==)-{-# OPTIONS_GHC -XNoImplicitPrelude #-}+{-# LANGUAGE NoImplicitPrelude #-}+{-# LANGUAGE MagicHash #-}+ {-| This module is an internal GHC module.  It declares the constants used in the implementation of type-level natural numbers.  The programmer interface for working with type-level naturals should be defined in a separate library. -/Since: 4.6.0.0/+@since 4.6.0.0 -}  module GHC.TypeLits@@ -22,8 +25,8 @@     Nat, Symbol      -- * Linking type and value level-  , KnownNat, natVal-  , KnownSymbol, symbolVal+  , KnownNat, natVal, natVal'+  , KnownSymbol, symbolVal, symbolVal'   , SomeNat(..), SomeSymbol(..)   , someNatVal, someSymbolVal   , sameNat, sameSymbol@@ -40,9 +43,9 @@ import GHC.Base(String) import GHC.Show(Show(..)) import GHC.Read(Read(..))-import GHC.Prim(magicDict)+import GHC.Prim(magicDict, Proxy#) import Data.Maybe(Maybe(..))-import Data.Proxy(Proxy(..))+import Data.Proxy (Proxy(..)) import Data.Type.Equality(type (==), (:~:)(Refl)) import Unsafe.Coerce(unsafeCoerce) @@ -58,40 +61,50 @@ -- | This class gives the integer associated with a type-level natural. -- There are instances of the class for every concrete literal: 0, 1, 2, etc. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 class KnownNat (n :: Nat) where   natSing :: SNat n --- | This class gives the integer associated with a type-level symbol.+-- | This class gives the string associated with a type-level symbol. -- There are instances of the class for every concrete literal: "hello", etc. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 class KnownSymbol (n :: Symbol) where   symbolSing :: SSymbol n --- | /Since: 4.7.0.0/+-- | @since 4.7.0.0 natVal :: forall n proxy. KnownNat n => proxy n -> Integer natVal _ = case natSing :: SNat n of              SNat x -> x --- | /Since: 4.7.0.0/+-- | @since 4.7.0.0 symbolVal :: forall n proxy. KnownSymbol n => proxy n -> String symbolVal _ = case symbolSing :: SSymbol n of                 SSymbol x -> x +-- | @since 4.8.0.0+natVal' :: forall n. KnownNat n => Proxy# n -> Integer+natVal' _ = case natSing :: SNat n of+             SNat x -> x +-- | @since 4.8.0.0+symbolVal' :: forall n. KnownSymbol n => Proxy# n -> String+symbolVal' _ = case symbolSing :: SSymbol n of+                SSymbol x -> x ++ -- | This type represents unknown type-level natural numbers. data SomeNat    = forall n. KnownNat n    => SomeNat    (Proxy n)-                  -- ^ /Since: 4.7.0.0/+                  -- ^ @since 4.7.0.0  -- | This type represents unknown type-level symbols. data SomeSymbol = forall n. KnownSymbol n => SomeSymbol (Proxy n)-                  -- ^ /Since: 4.7.0.0/+                  -- ^ @since 4.7.0.0  -- | Convert an integer into an unknown type-level natural. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 someNatVal :: Integer -> Maybe SomeNat someNatVal n   | n >= 0        = Just (withSNat SomeNat (SNat n) Proxy)@@ -99,7 +112,7 @@  -- | Convert a string into an unknown type-level symbol. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 someSymbolVal :: String -> SomeSymbol someSymbolVal n   = withSSymbol SomeSymbol (SSymbol n) Proxy @@ -134,13 +147,13 @@   readsPrec p xs = [ (someSymbolVal a, ys) | (a,ys) <- readsPrec p xs ]  type family EqNat (a :: Nat) (b :: Nat) where-  EqNat a a = True-  EqNat a b = False+  EqNat a a = 'True+  EqNat a b = 'False type instance a == b = EqNat a b  type family EqSymbol (a :: Symbol) (b :: Symbol) where-  EqSymbol a a = True-  EqSymbol a b = False+  EqSymbol a a = 'True+  EqSymbol a b = 'False type instance a == b = EqSymbol a b  --------------------------------------------------------------------------------@@ -151,16 +164,16 @@ infixr 8 ^  -- | Comparison of type-level naturals, as a constraint.-type x <= y = (x <=? y) ~ True+type x <= y = (x <=? y) ~ 'True  -- | Comparison of type-level symbols, as a function. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 type family CmpSymbol (m :: Symbol) (n :: Symbol) :: Ordering  -- | Comparison of type-level naturals, as a function. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 type family CmpNat    (m :: Nat)    (n :: Nat)    :: Ordering  {- | Comparison of type-level naturals, as a function.@@ -180,7 +193,7 @@  -- | Subtraction of type-level naturals. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 type family (m :: Nat) - (n :: Nat) :: Nat  @@ -189,7 +202,7 @@ -- | We either get evidence that this function was instantiated with the -- same type-level numbers, or 'Nothing'. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 sameNat :: (KnownNat a, KnownNat b) =>            Proxy a -> Proxy b -> Maybe (a :~: b) sameNat x y@@ -199,7 +212,7 @@ -- | We either get evidence that this function was instantiated with the -- same type-level symbols, or 'Nothing'. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 sameSymbol :: (KnownSymbol a, KnownSymbol b) =>               Proxy a -> Proxy b -> Maybe (a :~: b) sameSymbol x y
GHC/Unicode.hs view
@@ -29,9 +29,9 @@     ) where  import GHC.Base-import GHC.Char-import GHC.Real        (fromIntegral)-import Foreign.C.Types (CInt(..))+import GHC.Char        (chr)+import GHC.Real+import GHC.Num  #include "HsBaseConfig.h" @@ -67,16 +67,16 @@ -- characters @\\t@, @\\n@, @\\r@, @\\f@, @\\v@. isSpace                 :: Char -> Bool -- isSpace includes non-breaking space--- Done with explicit equalities both for efficiency, and to avoid a tiresome--- recursion with GHC.List elem-isSpace c               =  c == ' '     ||-                           c == '\t'    ||-                           c == '\n'    ||-                           c == '\r'    ||-                           c == '\f'    ||-                           c == '\v'    ||-                           c == '\xa0'  ||-                           iswspace (fromIntegral (ord c)) /= 0+-- The magic 0x377 isn't really that magical. As of 2014, all the codepoints+-- at or below 0x377 have been assigned, so we shouldn't have to worry about+-- any new spaces appearing below there. It would probably be best to+-- use branchless ||, but currently the eqLit transformation will undo that,+-- so we'll do it like this until there's a way around that.+isSpace c+  | uc <= 0x377 = uc == 32 || uc - 0x9 <= 4 || uc == 0xa0+  | otherwise = iswspace (ord c) /= 0+  where+    uc = fromIntegral (ord c) :: Word  -- | Selects upper-case or title-case alphabetic Unicode characters (letters). -- Title case is used by a small number of letter ligatures like the@@ -100,17 +100,23 @@  -- | Selects ASCII digits, i.e. @\'0\'@..@\'9\'@. isDigit                 :: Char -> Bool-isDigit c               =  c >= '0' && c <= '9'+isDigit c               =  (fromIntegral (ord c - ord '0') :: Word) <= 9 +-- We use an addition and an unsigned comparison instead of two signed+-- comparisons because it's usually faster and puts less strain on branch+-- prediction. It likely also enables some CSE when combined with functions+-- that follow up with an actual conversion.+ -- | Selects ASCII octal digits, i.e. @\'0\'@..@\'7\'@. isOctDigit              :: Char -> Bool-isOctDigit c            =  c >= '0' && c <= '7'+isOctDigit c            =  (fromIntegral (ord c - ord '0') :: Word) <= 7  -- | Selects ASCII hexadecimal digits, -- i.e. @\'0\'@..@\'9\'@, @\'a\'@..@\'f\'@, @\'A\'@..@\'F\'@. isHexDigit              :: Char -> Bool-isHexDigit c            =  isDigit c || c >= 'A' && c <= 'F' ||-                                        c >= 'a' && c <= 'f'+isHexDigit c            =  isDigit c ||+                           (fromIntegral (ord c - ord 'A')::Word) <= 5 ||+                           (fromIntegral (ord c - ord 'a')::Word) <= 5  -- | Convert a letter to the corresponding upper-case letter, if any. -- Any other character is returned unchanged.@@ -132,48 +138,47 @@  -- Regardless of the O/S and Library, use the functions contained in WCsubst.c -isAlpha    c = iswalpha (fromIntegral (ord c)) /= 0-isAlphaNum c = iswalnum (fromIntegral (ord c)) /= 0---isSpace    c = iswspace (fromIntegral (ord c)) /= 0-isControl  c = iswcntrl (fromIntegral (ord c)) /= 0-isPrint    c = iswprint (fromIntegral (ord c)) /= 0-isUpper    c = iswupper (fromIntegral (ord c)) /= 0-isLower    c = iswlower (fromIntegral (ord c)) /= 0+isAlpha    c = iswalpha (ord c) /= 0+isAlphaNum c = iswalnum (ord c) /= 0+isControl  c = iswcntrl (ord c) /= 0+isPrint    c = iswprint (ord c) /= 0+isUpper    c = iswupper (ord c) /= 0+isLower    c = iswlower (ord c) /= 0 -toLower c = chr (fromIntegral (towlower (fromIntegral (ord c))))-toUpper c = chr (fromIntegral (towupper (fromIntegral (ord c))))-toTitle c = chr (fromIntegral (towtitle (fromIntegral (ord c))))+toLower c = chr (towlower (ord c))+toUpper c = chr (towupper (ord c))+toTitle c = chr (towtitle (ord c))  foreign import ccall unsafe "u_iswalpha"-  iswalpha :: CInt -> CInt+  iswalpha :: Int -> Int  foreign import ccall unsafe "u_iswalnum"-  iswalnum :: CInt -> CInt+  iswalnum :: Int -> Int  foreign import ccall unsafe "u_iswcntrl"-  iswcntrl :: CInt -> CInt+  iswcntrl :: Int -> Int  foreign import ccall unsafe "u_iswspace"-  iswspace :: CInt -> CInt+  iswspace :: Int -> Int  foreign import ccall unsafe "u_iswprint"-  iswprint :: CInt -> CInt+  iswprint :: Int -> Int  foreign import ccall unsafe "u_iswlower"-  iswlower :: CInt -> CInt+  iswlower :: Int -> Int  foreign import ccall unsafe "u_iswupper"-  iswupper :: CInt -> CInt+  iswupper :: Int -> Int  foreign import ccall unsafe "u_towlower"-  towlower :: CInt -> CInt+  towlower :: Int -> Int  foreign import ccall unsafe "u_towupper"-  towupper :: CInt -> CInt+  towupper :: Int -> Int  foreign import ccall unsafe "u_towtitle"-  towtitle :: CInt -> CInt+  towtitle :: Int -> Int  foreign import ccall unsafe "u_gencat"-  wgencat :: CInt -> CInt+  wgencat :: Int -> Int 
− GHC/Unicode.hs-boot
@@ -1,20 +0,0 @@-{-# LANGUAGE Trustworthy #-}-{-# LANGUAGE NoImplicitPrelude #-}--module GHC.Unicode where--import GHC.Types--isAscii         :: Char -> Bool-isLatin1        :: Char -> Bool-isControl       :: Char -> Bool-isPrint         :: Char -> Bool-isSpace         :: Char -> Bool-isUpper         :: Char -> Bool-isLower         :: Char -> Bool-isAlpha         :: Char -> Bool-isDigit         :: Char -> Bool-isOctDigit      :: Char -> Bool-isHexDigit      :: Char -> Bool-isAlphaNum      :: Char -> Bool-
+ GHC/Weak.hs view
@@ -0,0 +1,157 @@+{-# LANGUAGE Unsafe #-}+{-# LANGUAGE NoImplicitPrelude+           , BangPatterns+           , MagicHash+           , UnboxedTuples+           , DeriveDataTypeable+           , StandaloneDeriving+  #-}+{-# OPTIONS_HADDOCK hide #-}++-----------------------------------------------------------------------------+-- |+-- Module      :  GHC.Weak+-- Copyright   :  (c) The University of Glasgow, 1998-2002+-- License     :  see libraries/base/LICENSE+--+-- Maintainer  :  cvs-ghc@haskell.org+-- Stability   :  internal+-- Portability :  non-portable (GHC Extensions)+--+-- Weak pointers.+--+-----------------------------------------------------------------------------++module GHC.Weak (+        Weak(..),+        mkWeak,+        deRefWeak,+        finalize,+        runFinalizerBatch+    ) where++import GHC.Base+import Data.Typeable++{-|+A weak pointer object with a key and a value.  The value has type @v@.++A weak pointer expresses a relationship between two objects, the+/key/ and the /value/:  if the key is considered to be alive by the+garbage collector, then the value is also alive.  A reference from+the value to the key does /not/ keep the key alive.++A weak pointer may also have a finalizer of type @IO ()@; if it does,+then the finalizer will be run at most once, at a time after the key+has become unreachable by the program (\"dead\").  The storage manager+attempts to run the finalizer(s) for an object soon after the object+dies, but promptness is not guaranteed.++It is not guaranteed that a finalizer will eventually run, and no+attempt is made to run outstanding finalizers when the program exits.+Therefore finalizers should not be relied on to clean up resources -+other methods (eg. exception handlers) should be employed, possibly in+addition to finalizers.++References from the finalizer to the key are treated in the same way+as references from the value to the key: they do not keep the key+alive.  A finalizer may therefore ressurrect the key, perhaps by+storing it in the same data structure.++The finalizer, and the relationship between the key and the value,+exist regardless of whether the program keeps a reference to the+'Weak' object or not.++There may be multiple weak pointers with the same key.  In this+case, the finalizers for each of these weak pointers will all be+run in some arbitrary order, or perhaps concurrently, when the key+dies.  If the programmer specifies a finalizer that assumes it has+the only reference to an object (for example, a file that it wishes+to close), then the programmer must ensure that there is only one+such finalizer.++If there are no other threads to run, the runtime system will check+for runnable finalizers before declaring the system to be deadlocked.++WARNING: weak pointers to ordinary non-primitive Haskell types are+particularly fragile, because the compiler is free to optimise away or+duplicate the underlying data structure.  Therefore attempting to+place a finalizer on an ordinary Haskell type may well result in the+finalizer running earlier than you expected.  This is not a problem+for caches and memo tables where early finalization is benign.++Finalizers /can/ be used reliably for types that are created explicitly+and have identity, such as @IORef@ and @MVar@.  However, to place a+finalizer on one of these types, you should use the specific operation+provided for that type, e.g. @mkWeakIORef@ and @addMVarFinalizer@+respectively (the non-uniformity is accidental).  These operations+attach the finalizer to the primitive object inside the box+(e.g. @MutVar#@ in the case of @IORef@), because attaching the+finalizer to the box itself fails when the outer box is optimised away+by the compiler.++-}+data Weak v = Weak (Weak# v) deriving Typeable++-- | Establishes a weak pointer to @k@, with value @v@ and a finalizer.+--+-- This is the most general interface for building a weak pointer.+--+mkWeak  :: k                            -- ^ key+        -> v                            -- ^ value+        -> Maybe (IO ())                -- ^ finalizer+        -> IO (Weak v)                  -- ^ returns: a weak pointer object++mkWeak key val (Just finalizer) = IO $ \s ->+   case mkWeak# key val finalizer s of { (# s1, w #) -> (# s1, Weak w #) }+mkWeak key val Nothing = IO $ \s ->+   case mkWeakNoFinalizer# key val s of { (# s1, w #) -> (# s1, Weak w #) }++{-|+Dereferences a weak pointer.  If the key is still alive, then+@'Just' v@ is returned (where @v@ is the /value/ in the weak pointer), otherwise+'Nothing' is returned.++The return value of 'deRefWeak' depends on when the garbage collector+runs, hence it is in the 'IO' monad.+-}+deRefWeak :: Weak v -> IO (Maybe v)+deRefWeak (Weak w) = IO $ \s ->+   case deRefWeak# w s of+        (# s1, flag, p #) -> case flag of+                                0# -> (# s1, Nothing #)+                                _  -> (# s1, Just p #)++-- | Causes a the finalizer associated with a weak pointer to be run+-- immediately.+finalize :: Weak v -> IO ()+finalize (Weak w) = IO $ \s ->+   case finalizeWeak# w s of+        (# s1, 0#, _ #) -> (# s1, () #) -- already dead, or no finalizer+        (# s1, _,  f #) -> f s1++{-+Instance Eq (Weak v) where+  (Weak w1) == (Weak w2) = w1 `sameWeak#` w2+-}+++-- run a batch of finalizers from the garbage collector.  We're given+-- an array of finalizers and the length of the array, and we just+-- call each one in turn.+--+-- the IO primitives are inlined by hand here to get the optimal+-- code (sigh) --SDM.++runFinalizerBatch :: Int -> Array# (IO ()) -> IO ()+runFinalizerBatch (I# n) arr =+   let  go m  = IO $ \s ->+                  case m of+                  0# -> (# s, () #)+                  _  -> let !m' = m -# 1# in+                        case indexArray# arr m' of { (# io #) ->+                        case unIO io s of          { (# s', _ #) ->+                        unIO (go m') s'+                        }}+   in+        go n
− GHC/Weak.lhs
@@ -1,161 +0,0 @@-\begin{code}-{-# LANGUAGE Unsafe #-}-{-# LANGUAGE NoImplicitPrelude-           , BangPatterns-           , MagicHash-           , UnboxedTuples-           , DeriveDataTypeable-           , StandaloneDeriving-  #-}-{-# OPTIONS_HADDOCK hide #-}---------------------------------------------------------------------------------- |--- Module      :  GHC.Weak--- Copyright   :  (c) The University of Glasgow, 1998-2002--- License     :  see libraries/base/LICENSE--- --- Maintainer  :  cvs-ghc@haskell.org--- Stability   :  internal--- Portability :  non-portable (GHC Extensions)------ Weak pointers.-----------------------------------------------------------------------------------module GHC.Weak (-        Weak(..),-        mkWeak,-        deRefWeak,-        finalize,-        runFinalizerBatch-    ) where--import GHC.Base-import Data.Maybe-import Data.Typeable--{-|-A weak pointer object with a key and a value.  The value has type @v@.--A weak pointer expresses a relationship between two objects, the-/key/ and the /value/:  if the key is considered to be alive by the-garbage collector, then the value is also alive.  A reference from-the value to the key does /not/ keep the key alive.--A weak pointer may also have a finalizer of type @IO ()@; if it does,-then the finalizer will be run at most once, at a time after the key-has become unreachable by the program (\"dead\").  The storage manager-attempts to run the finalizer(s) for an object soon after the object-dies, but promptness is not guaranteed.  --It is not guaranteed that a finalizer will eventually run, and no-attempt is made to run outstanding finalizers when the program exits.-Therefore finalizers should not be relied on to clean up resources --other methods (eg. exception handlers) should be employed, possibly in-addition to finalizers.--References from the finalizer to the key are treated in the same way-as references from the value to the key: they do not keep the key-alive.  A finalizer may therefore ressurrect the key, perhaps by-storing it in the same data structure.--The finalizer, and the relationship between the key and the value,-exist regardless of whether the program keeps a reference to the-'Weak' object or not.--There may be multiple weak pointers with the same key.  In this-case, the finalizers for each of these weak pointers will all be-run in some arbitrary order, or perhaps concurrently, when the key-dies.  If the programmer specifies a finalizer that assumes it has-the only reference to an object (for example, a file that it wishes-to close), then the programmer must ensure that there is only one-such finalizer.--If there are no other threads to run, the runtime system will check-for runnable finalizers before declaring the system to be deadlocked.--WARNING: weak pointers to ordinary non-primitive Haskell types are-particularly fragile, because the compiler is free to optimise away or-duplicate the underlying data structure.  Therefore attempting to-place a finalizer on an ordinary Haskell type may well result in the-finalizer running earlier than you expected.  This is not a problem-for caches and memo tables where early finalization is benign.--Finalizers /can/ be used reliably for types that are created explicitly-and have identity, such as @IORef@ and @MVar@.  However, to place a-finalizer on one of these types, you should use the specific operation-provided for that type, e.g. @mkWeakIORef@ and @addMVarFinalizer@-respectively (the non-uniformity is accidental).  These operations-attach the finalizer to the primitive object inside the box-(e.g. @MutVar#@ in the case of @IORef@), because attaching the-finalizer to the box itself fails when the outer box is optimised away-by the compiler.---}-data Weak v = Weak (Weak# v) deriving Typeable---- | Establishes a weak pointer to @k@, with value @v@ and a finalizer.------ This is the most general interface for building a weak pointer.----mkWeak  :: k                            -- ^ key-        -> v                            -- ^ value-        -> Maybe (IO ())                -- ^ finalizer-        -> IO (Weak v)                  -- ^ returns: a weak pointer object--mkWeak key val (Just finalizer) = IO $ \s ->-   case mkWeak# key val finalizer s of { (# s1, w #) -> (# s1, Weak w #) }-mkWeak key val Nothing = IO $ \s ->-   case mkWeakNoFinalizer# key val s of { (# s1, w #) -> (# s1, Weak w #) }--{-|-Dereferences a weak pointer.  If the key is still alive, then-@'Just' v@ is returned (where @v@ is the /value/ in the weak pointer), otherwise-'Nothing' is returned.--The return value of 'deRefWeak' depends on when the garbage collector-runs, hence it is in the 'IO' monad.--}-deRefWeak :: Weak v -> IO (Maybe v)-deRefWeak (Weak w) = IO $ \s ->-   case deRefWeak# w s of-        (# s1, flag, p #) -> case flag of-                                0# -> (# s1, Nothing #)-                                _  -> (# s1, Just p #)---- | Causes a the finalizer associated with a weak pointer to be run--- immediately.-finalize :: Weak v -> IO ()-finalize (Weak w) = IO $ \s ->-   case finalizeWeak# w s of-        (# s1, 0#, _ #) -> (# s1, () #) -- already dead, or no finalizer-        (# s1, _,  f #) -> f s1--{--Instance Eq (Weak v) where-  (Weak w1) == (Weak w2) = w1 `sameWeak#` w2--}----- run a batch of finalizers from the garbage collector.  We're given --- an array of finalizers and the length of the array, and we just--- call each one in turn.------ the IO primitives are inlined by hand here to get the optimal--- code (sigh) --SDM.--runFinalizerBatch :: Int -> Array# (IO ()) -> IO ()-runFinalizerBatch (I# n) arr = -   let  go m  = IO $ \s ->-                  case m of -                  0# -> (# s, () #)-                  _  -> let !m' = m -# 1# in-                        case indexArray# arr m' of { (# io #) -> -                        case unIO io s of          { (# s', _ #) -> -                        unIO (go m') s'-                        }}-   in-        go n--\end{code}
GHC/Windows.hs view
@@ -1,12 +1,13 @@ {-# LANGUAGE Trustworthy #-} {-# LANGUAGE CPP #-} {-# LANGUAGE NoImplicitPrelude #-}+ ----------------------------------------------------------------------------- -- | -- Module      :  GHC.Windows -- Copyright   :  (c) The University of Glasgow, 2009 -- License     :  see libraries/base/LICENSE--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  internal -- Portability :  non-portable@@ -58,7 +59,7 @@     ) where  import Data.Char-import Data.List+import Data.OldList import Data.Maybe import Data.Word import Foreign.C.Error@@ -120,7 +121,7 @@     -- XXX we should really do this directly.     let errno = c_maperrno_func err_code -    let msg' = reverse $ dropWhile isSpace $ reverse msg -- drop trailing \n+    let msg' = dropWhileEnd isSpace msg -- drop trailing \n         ioerror = errnoToIOError fn_name errno Nothing Nothing                     `ioeSetErrorString` msg'     return ioerror
GHC/Word.hs view
@@ -35,7 +35,6 @@ import GHC.IntWord64 #endif --- import {-# SOURCE #-} GHC.Exception import GHC.Base import GHC.Enum import GHC.Num@@ -43,7 +42,6 @@ import GHC.Read import GHC.Arr import GHC.Show-import GHC.Float ()     -- for RealFrac methods  ------------------------------------------------------------------------ -- type Word8@@ -154,6 +152,8 @@  instance FiniteBits Word8 where     finiteBitSize _ = 8+    countLeadingZeros  (W8# x#) = I# (word2Int# (clz8# x#))+    countTrailingZeros (W8# x#) = I# (word2Int# (ctz8# x#))  {-# RULES "fromIntegral/Word8->Word8"   fromIntegral = id :: Word8 -> Word8@@ -301,10 +301,12 @@  instance FiniteBits Word16 where     finiteBitSize _ = 16+    countLeadingZeros  (W16# x#) = I# (word2Int# (clz16# x#))+    countTrailingZeros (W16# x#) = I# (word2Int# (ctz16# x#))  -- | Swap bytes in 'Word16'. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 byteSwap16 :: Word16 -> Word16 byteSwap16 (W16# w#) = W16# (narrow16Word# (byteSwap16# w#)) @@ -495,6 +497,8 @@  instance FiniteBits Word32 where     finiteBitSize _ = 32+    countLeadingZeros  (W32# x#) = I# (word2Int# (clz32# x#))+    countTrailingZeros (W32# x#) = I# (word2Int# (ctz32# x#))  {-# RULES "fromIntegral/Word8->Word32"   fromIntegral = \(W8# x#) -> W32# x#@@ -534,7 +538,7 @@  -- | Reverse order of bytes in 'Word32'. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 byteSwap32 :: Word32 -> Word32 byteSwap32 (W32# w#) = W32# (narrow32Word# (byteSwap32# w#)) @@ -767,6 +771,8 @@  instance FiniteBits Word64 where     finiteBitSize _ = 64+    countLeadingZeros  (W64# x#) = I# (word2Int# (clz64# x#))+    countTrailingZeros (W64# x#) = I# (word2Int# (ctz64# x#))  instance Show Word64 where     showsPrec p x = showsPrec p (toInteger x)@@ -788,7 +794,7 @@  -- | Reverse order of bytes in 'Word64'. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 #if WORD_SIZE_IN_BITS < 64 byteSwap64 :: Word64 -> Word64 byteSwap64 (W64# w#) = W64# (byteSwap64# w#)
Numeric.hs view
@@ -65,7 +65,6 @@ import GHC.Float import GHC.Num import GHC.Show-import Data.Maybe import Text.ParserCombinators.ReadP( ReadP, readP_to_S, pfail ) import qualified Text.Read.Lex as L @@ -188,7 +187,7 @@ -- This behaves as 'showFFloat', except that a decimal point -- is always guaranteed, even if not needed. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 showFFloatAlt    :: (RealFloat a) => Maybe Int -> a -> ShowS  -- | Show a signed 'RealFloat' value@@ -198,7 +197,7 @@ -- This behaves as 'showFFloat', except that a decimal point -- is always guaranteed, even if not needed. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 showGFloatAlt    :: (RealFloat a) => Maybe Int -> a -> ShowS  showFFloatAlt d x =  showString (formatRealFloatAlt FFFixed d True x)
+ Numeric/Natural.hs view
@@ -0,0 +1,24 @@+{-# LANGUAGE NoImplicitPrelude #-}+{-# LANGUAGE Trustworthy #-}++-----------------------------------------------------------------------------+-- |+-- Module      :  Numeric.Natural+-- Copyright   :  (C) 2014 Herbert Valerio Riedel,+--                (C) 2011 Edward Kmett+-- License     :  see libraries/base/LICENSE+--+-- Maintainer  :  libraries@haskell.org+-- Stability   :  provisional+-- Portability :  portable+--+-- The arbitrary-precision 'Natural' number type.+--+-- @since 4.8.0.0+-----------------------------------------------------------------------------++module Numeric.Natural+    ( Natural+    ) where++import GHC.Natural
Prelude.hs view
@@ -1,12 +1,12 @@ {-# LANGUAGE Trustworthy #-}-{-# LANGUAGE CPP, NoImplicitPrelude, BangPatterns #-}+{-# LANGUAGE NoImplicitPrelude #-}  ----------------------------------------------------------------------------- -- | -- Module      :  Prelude -- Copyright   :  (c) The University of Glasgow 2001 -- License     :  BSD-style (see the file libraries/base/LICENSE)--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  stable -- Portability :  portable@@ -48,7 +48,7 @@      -- *** Numeric types     Int, Integer, Float, Double,-    Rational,+    Rational, Word,      -- *** Numeric type classes     Num((+), (-), (*), negate, abs, signum, fromInteger),@@ -66,11 +66,33 @@     subtract, even, odd, gcd, lcm, (^), (^^),     fromIntegral, realToFrac, +    -- ** Monoids+    Monoid(mempty, mappend, mconcat),+     -- ** Monads and functors+    Functor(fmap, (<$)), (<$>),+    Applicative(pure, (<*>), (*>), (<*)),     Monad((>>=), (>>), return, fail),-    Functor(fmap),-    mapM, mapM_, sequence, sequence_, (=<<),+    mapM_, sequence_, (=<<), +    -- ** Folds and traversals+    Foldable(elem,      -- :: (Foldable t, Eq a) => a -> t a -> Bool+             -- fold,   -- :: Monoid m => t m -> m+             foldMap,   -- :: Monoid m => (a -> m) -> t a -> m+             foldr,     -- :: (a -> b -> b) -> b -> t a -> b+             -- foldr', -- :: (a -> b -> b) -> b -> t a -> b+             foldl,     -- :: (b -> a -> b) -> b -> t a -> b+             -- foldl', -- :: (b -> a -> b) -> b -> t a -> b+             foldr1,    -- :: (a -> a -> a) -> t a -> a+             foldl1,    -- :: (a -> a -> a) -> t a -> a+             maximum,   -- :: (Foldable t, Ord a) => t a -> a+             minimum,   -- :: (Foldable t, Ord a) => t a -> a+             product,   -- :: (Foldable t, Num a) => t a -> a+             sum),      -- :: Num a => t a -> a+             -- toList) -- :: Foldable t => t a -> [a]++    Traversable(traverse, sequenceA, mapM, sequence),+     -- ** Miscellaneous functions     id, const, (.), flip, ($), until,     asTypeOf, error, undefined,@@ -80,13 +102,9 @@     map, (++), filter,     head, last, tail, init, null, length, (!!),     reverse,-    -- ** Reducing lists (folds)-    foldl, foldl1, foldr, foldr1,     -- *** Special folds     and, or, any, all,-    sum, product,     concat, concatMap,-    maximum, minimum,     -- ** Building lists     -- *** Scans     scanl, scanl1, scanr, scanr1,@@ -95,7 +113,7 @@     -- ** Sublists     take, drop, splitAt, takeWhile, dropWhile, span, break,     -- ** Searching lists-    elem, notElem, lookup,+    notElem, lookup,     -- ** Zipping and unzipping lists     zip, zip3, zipWith, zipWith3, unzip, unzip3,     -- ** Functions on strings@@ -139,30 +157,16 @@ import System.IO.Error import Data.List import Data.Either+import Data.Foldable    ( Foldable(..) )+import Data.Functor     ( (<$>) ) import Data.Maybe+import Data.Traversable ( Traversable(..) ) import Data.Tuple -import GHC.Base+import GHC.Base hiding ( foldr, mapM, sequence ) import Text.Read import GHC.Enum import GHC.Num import GHC.Real import GHC.Float import GHC.Show--infixr 0 $!---- -------------------------------------------------------------------------------- Miscellaneous functions---- | Strict (call-by-value) application, defined in terms of 'seq'.-($!)    :: (a -> b) -> a -> b-f $! x  = let !vx = x in f vx  -- see #2273--#ifdef __HADDOCK__--- | The value of @'seq' a b@ is bottom if @a@ is bottom, and otherwise--- equal to @b@.  'seq' is usually introduced to improve performance by--- avoiding unneeded laziness.-seq :: a -> b -> b-seq _ y = y-#endif
Setup.hs view
@@ -3,4 +3,4 @@ import Distribution.Simple  main :: IO ()-main = defaultMainWithHooks defaultUserHooks+main = defaultMainWithHooks autoconfUserHooks
System/CPUTime.hsc view
@@ -24,11 +24,9 @@          cpuTimePrecision  -- :: Integer         ) where -import Prelude- import Data.Ratio -import Foreign.Safe+import Foreign import Foreign.C  -- For struct rusage
System/Console/GetOpt.hs view
@@ -62,8 +62,6 @@    -- $example2 ) where -import Prelude -- necessary to get dependencies right- import Data.List ( isPrefixOf, find )  -- |What to do with options following non-options
System/Environment.hs view
@@ -29,9 +29,7 @@       getEnvironment,   ) where -import Prelude--import Foreign.Safe+import Foreign import Foreign.C import System.IO.Error (mkIOError) import Control.Exception.Base (bracket, throwIO)@@ -214,7 +212,7 @@ -- -- For POSIX users, this is equivalent to 'System.Posix.Env.getEnv'. ----- /Since: 4.6.0.0/+-- @since 4.6.0.0 lookupEnv :: String -> IO (Maybe String) #ifdef mingw32_HOST_OS lookupEnv name = withCWString name $ \s -> try_size s 256@@ -269,7 +267,7 @@ -- Throws `Control.Exception.IOException` if @name@ is the empty string or -- contains an equals sign. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 setEnv :: String -> String -> IO () setEnv key_ value_   | null key       = throwIO (mkIOError InvalidArgument "setEnv" Nothing Nothing)@@ -313,7 +311,7 @@ -- Throws `Control.Exception.IOException` if @name@ is the empty string or -- contains an equals sign. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 unsetEnv :: String -> IO () #ifdef mingw32_HOST_OS unsetEnv key = withCWString key $ \k -> do
System/Environment/ExecutablePath.hsc view
@@ -13,7 +13,7 @@ -- -- Function to retrieve the absolute filepath of the current executable. ----- /Since: 4.6.0.0/+-- @since 4.6.0.0 -----------------------------------------------------------------------------  module System.Environment.ExecutablePath ( getExecutablePath ) where@@ -54,7 +54,7 @@ -- Note that for scripts and interactive sessions, this is the path to -- the interpreter (e.g. ghci.) ----- /Since: 4.6.0.0/+-- @since 4.6.0.0 getExecutablePath :: IO FilePath  --------------------------------------------------------------------------------
System/Exit.hs view
@@ -5,7 +5,7 @@ -- Module      :  System.Exit -- Copyright   :  (c) The University of Glasgow 2001 -- License     :  BSD-style (see the file libraries/base/LICENSE)--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  provisional -- Portability :  portable@@ -20,9 +20,10 @@     , exitWith     , exitFailure     , exitSuccess+    , die   ) where -import Prelude+import System.IO  import GHC.IO import GHC.IO.Exception@@ -74,3 +75,8 @@ exitSuccess :: IO a exitSuccess = exitWith ExitSuccess +-- | Write given error message to `stderr` and terminate with `exitFailure`.+--+-- @since 4.8.0.0+die :: String -> IO a+die err = hPutStrLn stderr err >> exitFailure
System/IO.hs view
@@ -6,7 +6,7 @@ -- Module      :  System.IO -- Copyright   :  (c) The University of Glasgow 2001 -- License     :  BSD-style (see the file libraries/base/LICENSE)--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  stable -- Portability :  portable@@ -181,21 +181,21 @@     -- 'readFile'), where a decoding error merely results in     -- termination of the character stream, as with other I/O errors. -    hSetEncoding, +    hSetEncoding,     hGetEncoding,      -- ** Unicode encodings-    TextEncoding, +    TextEncoding,     latin1,     utf8, utf8_bom,     utf16, utf16le, utf16be,-    utf32, utf32le, utf32be, +    utf32, utf32le, utf32be,     localeEncoding,     char8,     mkTextEncoding,      -- * Newline conversion-    +     -- | In Haskell, a newline is always represented by the character     -- '\n'.  However, in files and external character streams, a     -- newline may be represented by another character sequence, such@@ -213,16 +213,15 @@     --     -- Binary-mode 'Handle's do no newline translation at all.     ---    hSetNewlineMode, -    Newline(..), nativeNewline, -    NewlineMode(..), +    hSetNewlineMode,+    Newline(..), nativeNewline,+    NewlineMode(..),     noNewlineTranslation, universalNewlineMode, nativeNewlineMode,   ) where  import Control.Exception.Base  import Data.Bits-import Data.List import Data.Maybe import Foreign.C.Error #ifdef mingw32_HOST_OS@@ -233,6 +232,7 @@ import System.Posix.Types  import GHC.Base+import GHC.List import GHC.IO hiding ( bracket, onException ) import GHC.IO.IOMode import GHC.IO.Handle.FD@@ -241,7 +241,6 @@ import GHC.IO.Handle.Text ( hGetBufSome, hPutStrLn ) import GHC.IO.Exception ( userError ) import GHC.IO.Encoding-import GHC.Num import Text.Read import GHC.Show import GHC.MVar@@ -359,7 +358,7 @@  -- | Computation 'hReady' @hdl@ indicates whether at least one item is -- available for input from handle @hdl@.--- +-- -- This operation may fail with: -- --  * 'System.IO.Error.isEOFError' if the end of file has been reached.@@ -464,9 +463,7 @@  openTempFile' :: String -> FilePath -> String -> Bool -> CMode               -> IO (FilePath, Handle)-openTempFile' loc tmp_dir template binary mode = do-  pid <- c_getpid-  findTempName pid+openTempFile' loc tmp_dir template binary mode = findTempName   where     -- We split off the last extension, so we can use .foo.ext files     -- for temporary files (hidden on Unix OSes). Unfortunately we're@@ -485,10 +482,13 @@          -- beginning with '.' as the second component.          _                      -> error "bug in System.IO.openTempFile" -    findTempName x = do+    findTempName = do+      rs <- rand_string+      let filename = prefix ++ rs ++ suffix+          filepath = tmp_dir `combine` filename       r <- openNewFile filepath binary mode       case r of-        FileExists -> findTempName (x + 1)+        FileExists -> findTempName         OpenNewError errno -> ioError (errnoToIOError loc errno Nothing (Just tmp_dir))         NewFileCreated fd -> do           (fD,fd_type) <- FD.mkFD fd ReadWriteMode Nothing{-no stat-}@@ -501,15 +501,22 @@           return (filepath, h)        where-        filename        = prefix ++ show x ++ suffix-        filepath        = tmp_dir `combine` filename-         -- XXX bits copied from System.FilePath, since that's not available here         combine a b                   | null b = a                   | null a = b                   | last a == pathSeparator = a ++ b                   | otherwise = a ++ [pathSeparator] ++ b++-- int rand(void) from <stdlib.h>, limited by RAND_MAX (small value, 32768)+foreign import ccall "rand" c_rand :: IO CInt++-- build large digit-alike number+rand_string :: IO String+rand_string = do+  r1 <- c_rand+  r2 <- c_rand+  return $ show r1 ++ show r2  data OpenNewFileResult   = NewFileCreated CInt
System/IO/Error.hs view
@@ -6,7 +6,7 @@ -- Module      :  System.IO.Error -- Copyright   :  (c) The University of Glasgow 2001 -- License     :  BSD-style (see the file libraries/base/LICENSE)--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  provisional -- Portability :  portable@@ -30,9 +30,9 @@     isAlreadyExistsError,     isDoesNotExistError,     isAlreadyInUseError,-    isFullError, +    isFullError,     isEOFError,-    isIllegalOperation, +    isIllegalOperation,     isPermissionError,     isUserError, @@ -57,7 +57,7 @@     alreadyInUseErrorType,     fullErrorType,     eofErrorType,-    illegalOperationErrorType, +    illegalOperationErrorType,     permissionErrorType,     userErrorType, @@ -65,11 +65,11 @@     isAlreadyExistsErrorType,     isDoesNotExistErrorType,     isAlreadyInUseErrorType,-    isFullErrorType, +    isFullErrorType,     isEOFErrorType,-    isIllegalOperationErrorType, +    isIllegalOperationErrorType,     isPermissionErrorType,-    isUserErrorType, +    isUserErrorType,      -- * Throwing and catching I\/O errors @@ -98,7 +98,7 @@ -- Non-I\/O exceptions are not caught by this variant; to catch all -- exceptions, use 'Control.Exception.try' from "Control.Exception". ----- /Since: 4.4.0.0/+-- @since 4.4.0.0 tryIOError     :: IO a -> IO (Either IOError a) tryIOError f   =  catch (do r <- f                             return (Right r))@@ -113,11 +113,11 @@ -- error if applicable. mkIOError :: IOErrorType -> String -> Maybe Handle -> Maybe FilePath -> IOError mkIOError t location maybe_hdl maybe_filename =-               IOError{ ioe_type = t, +               IOError{ ioe_type = t,                         ioe_location = location,                         ioe_description = "",                         ioe_errno = Nothing,-                        ioe_handle = maybe_hdl, +                        ioe_handle = maybe_hdl,                         ioe_filename = maybe_filename                         } @@ -302,18 +302,14 @@ -- | Adds a location description and maybe a file path and file handle -- to an 'IOError'.  If any of the file handle or file path is not given -- the corresponding value in the 'IOError' remains unaltered.-annotateIOError :: IOError -              -> String -              -> Maybe Handle -              -> Maybe FilePath -              -> IOError -annotateIOError ioe loc hdl path = +annotateIOError :: IOError+              -> String+              -> Maybe Handle+              -> Maybe FilePath+              -> IOError+annotateIOError ioe loc hdl path =   ioe{ ioe_handle = hdl `mplus` ioe_handle ioe,        ioe_location = loc, ioe_filename = path `mplus` ioe_filename ioe }-  where-    mplus :: Maybe a -> Maybe a -> Maybe a-    Nothing `mplus` ys = ys-    xs      `mplus` _  = xs  -- | The 'catchIOError' function establishes a handler that receives any -- 'IOError' raised in the action protected by 'catchIOError'.@@ -336,6 +332,6 @@ -- Non-I\/O exceptions are not caught by this variant; to catch all -- exceptions, use 'Control.Exception.catch' from "Control.Exception". ----- /Since: 4.4.0.0/+-- @since 4.4.0.0 catchIOError :: IO a -> (IOError -> IO a) -> IO a catchIOError = catch
System/IO/Unsafe.hs view
@@ -40,7 +40,7 @@ -- In this case, the child thread will receive a @NonTermination@ -- exception instead of waiting for the value of @r@ to be computed. ----- /Since: 4.5.0.0/+-- @since 4.5.0.0 unsafeFixIO :: (a -> IO a) -> IO a unsafeFixIO k = do   ref <- newIORef (throw NonTermination)
System/Info.hs view
@@ -24,13 +24,12 @@        compilerVersion    ) where -import Prelude import Data.Version  -- | The version of 'compilerName' with which the program was compiled -- or is being interpreted. compilerVersion :: Version-compilerVersion = Version {versionBranch=[major, minor], versionTags=[]}+compilerVersion = Version [major, minor] []   where (major, minor) = compilerVersionRaw `divMod` 100  #include "ghcplatform.h"
System/Mem.hs view
@@ -19,7 +19,6 @@        , performMajorGC        , performMinorGC        ) where-import Prelude  -- | Triggers an immediate garbage collection. performGC :: IO ()@@ -27,10 +26,10 @@  -- | Triggers an immediate garbage collection. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 foreign import ccall "performMajorGC" performMajorGC :: IO ()  -- | Triggers an immediate minor garbage collection. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 foreign import ccall "performGC" performMinorGC :: IO ()
System/Mem/StableName.hs view
@@ -1,6 +1,6 @@ {-# LANGUAGE Trustworthy #-} {-# LANGUAGE CPP #-}-{-# LANGUAGE DeriveDataTypeable, StandaloneDeriving #-}+{-# LANGUAGE AutoDeriveTypeable, StandaloneDeriving #-} {-# LANGUAGE MagicHash #-} #if !defined(__PARALLEL_HASKELL__) {-# LANGUAGE UnboxedTuples #-}@@ -11,14 +11,14 @@ -- Module      :  System.Mem.StableName -- Copyright   :  (c) The University of Glasgow 2001 -- License     :  BSD-style (see the file libraries/base/LICENSE)--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  experimental -- Portability :  non-portable -- -- Stable names are a way of performing fast (O(1)), not-quite-exact -- comparison between objects.--- +-- -- Stable names solve the following problem: suppose you want to build -- a hash table with Haskell objects as keys, but you want to use -- pointer equality for comparison; maybe because the keys are large@@ -38,13 +38,11 @@   eqStableName   ) where -import Prelude- import Data.Typeable  import GHC.IO           ( IO(..) )-import GHC.Base		( Int(..), StableName#, makeStableName#-			, eqStableName#, stableNameToInt# )+import GHC.Base         ( Int(..), StableName#, makeStableName#+                        , eqStableName#, stableNameToInt# )  ----------------------------------------------------------------------------- -- Stable Names@@ -55,7 +53,7 @@   Stable names have the following property:    * If @sn1 :: StableName@ and @sn2 :: StableName@ and @sn1 == sn2@-   then @sn1@ and @sn2@ were created by calls to @makeStableName@ on +   then @sn1@ and @sn2@ were created by calls to @makeStableName@ on    the same object.    The reverse is not necessarily true: if two stable names are not@@ -84,7 +82,7 @@ -- the first argument is not evaluated by 'makeStableName'. makeStableName  :: a -> IO (StableName a) #if defined(__PARALLEL_HASKELL__)-makeStableName a = +makeStableName a =   error "makeStableName not implemented in parallel Haskell" #else makeStableName a = IO $ \ s ->@@ -97,32 +95,32 @@ -- of 'hashStableName' makes a good hash key). hashStableName :: StableName a -> Int #if defined(__PARALLEL_HASKELL__)-hashStableName (StableName sn) = +hashStableName (StableName sn) =   error "hashStableName not implemented in parallel Haskell" #else hashStableName (StableName sn) = I# (stableNameToInt# sn) #endif -instance Eq (StableName a) where +instance Eq (StableName a) where #if defined(__PARALLEL_HASKELL__)-    (StableName sn1) == (StableName sn2) = +    (StableName sn1) == (StableName sn2) =       error "eqStableName not implemented in parallel Haskell" #else-    (StableName sn1) == (StableName sn2) = +    (StableName sn1) == (StableName sn2) =        case eqStableName# sn1 sn2 of-	 0# -> False-	 _  -> True+         0# -> False+         _  -> True #endif  -- | Equality on 'StableName' that does not require that the types of -- the arguments match. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 eqStableName :: StableName a -> StableName b -> Bool eqStableName (StableName sn1) (StableName sn2) =        case eqStableName# sn1 sn2 of-	 0# -> False-	 _  -> True+         0# -> False+         _  -> True   -- Requested by Emil Axelsson on glasgow-haskell-users, who wants to   -- use it for implementing observable sharing. 
System/Mem/Weak.hs view
@@ -5,7 +5,7 @@ -- Module      :  System.Mem.Weak -- Copyright   :  (c) The University of Glasgow 2001 -- License     :  BSD-style (see the file libraries/base/LICENSE)--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  experimental -- Portability :  non-portable@@ -16,9 +16,9 @@ -- object.  A weak pointer can be de-referenced to find out -- whether the object it refers to is still alive or not, and if so -- to return the object itself.--- +-- -- Weak pointers are particularly useful for caches and memo tables.--- To build a memo table, you build a data structure +-- To build a memo table, you build a data structure -- mapping from the function argument (the key) to its result (the -- value).  When you apply the function to a new argument you first -- check whether the key\/value pair is already in the memo table.@@ -26,47 +26,47 @@ -- key and value alive.  So the table should contain a weak pointer -- to the key, not an ordinary pointer.  The pointer to the value must -- not be weak, because the only reference to the value might indeed be--- from the memo table.   --- +-- from the memo table.+-- -- So it looks as if the memo table will keep all its values -- alive for ever.  One way to solve this is to purge the table -- occasionally, by deleting entries whose keys have died.--- +-- -- The weak pointers in this library -- support another approach, called /finalization/. -- When the key referred to by a weak pointer dies, the storage manager -- arranges to run a programmer-specified finalizer.  In the case of memo -- tables, for example, the finalizer could remove the key\/value pair--- from the memo table.  --- +-- from the memo table.+-- -- Another difficulty with the memo table is that the value of a -- key\/value pair might itself contain a pointer to the key. -- So the memo table keeps the value alive, which keeps the key alive, -- even though there may be no other references to the key so both should--- die.  The weak pointers in this library provide a slight +-- die.  The weak pointers in this library provide a slight -- generalisation of the basic weak-pointer idea, in which each -- weak pointer actually contains both a key and a value. -- -----------------------------------------------------------------------------  module System.Mem.Weak (-	-- * The @Weak@ type-	Weak,	    		-- abstract+        -- * The @Weak@ type+        Weak,                   -- abstract -	-- * The general interface-	mkWeak,-	deRefWeak,-	finalize,+        -- * The general interface+        mkWeak,+        deRefWeak,+        finalize, -	-- * Specialised versions-	mkWeakPtr,-	addFinalizer,-	mkWeakPair,-	-- replaceFinaliser+        -- * Specialised versions+        mkWeakPtr,+        addFinalizer,+        mkWeakPair,+        -- replaceFinaliser -	-- * A precise semantics-	-	-- $precise+        -- * A precise semantics++        -- $precise    ) where  import GHC.Weak
System/Posix/Internals.hs view
@@ -7,7 +7,7 @@ -- Module      :  System.Posix.Internals -- Copyright   :  (c) The University of Glasgow, 1992-2002 -- License     :  see libraries/base/LICENSE--- +-- -- Maintainer  :  cvs-ghc@haskell.org -- Stability   :  internal -- Portability :  non-portable (requires POSIX)@@ -24,9 +24,6 @@  #include "HsBaseConfig.h" -#if ! (defined(mingw32_HOST_OS) || defined(__MINGW32__))-import Control.Monad-#endif import System.Posix.Types  import Foreign@@ -66,7 +63,7 @@ -- Types  type CFLock     = ()-type CGroup     = ()+data {-# CTYPE "struct group" #-} CGroup type CLconv     = () type CPasswd    = () type CSigaction = ()@@ -84,11 +81,11 @@ -- stat()-related stuff  fdFileSize :: FD -> IO Integer-fdFileSize fd = +fdFileSize fd =   allocaBytes sizeof_stat $ \ p_stat -> do     throwErrnoIfMinus1Retry_ "fileSize" $         c_fstat fd p_stat-    c_mode <- st_mode p_stat :: IO CMode +    c_mode <- st_mode p_stat :: IO CMode     if not (s_isreg c_mode)         then return (-1)         else do@@ -106,7 +103,7 @@ -- NOTE: On Win32 platforms, this will only work with file descriptors -- referring to file handles. i.e., it'll fail for socket FDs. fdStat :: FD -> IO (IODeviceType, CDev, CIno)-fdStat fd = +fdStat fd =   allocaBytes sizeof_stat $ \ p_stat -> do     throwErrnoIfMinus1Retry_ "fdType" $         c_fstat fd p_stat@@ -114,7 +111,7 @@     dev <- st_dev p_stat     ino <- st_ino p_stat     return (ty,dev,ino)-    + fdType :: FD -> IO IODeviceType fdType fd = do (ty,_,_) <- fdStat fd; return ty @@ -129,7 +126,7 @@          -- Q: map char devices to RawDevice too?         | s_isblk c_mode        -> return RawDevice         | otherwise             -> ioError ioe_unknownfiletype-    + ioe_unknownfiletype :: IOException ioe_unknownfiletype = IOError Nothing UnsupportedOperation "fdType"                         "unknown file type"@@ -144,7 +141,7 @@     let flags = o_RDWR #else fdGetMode fd = do-    flags <- throwErrnoIfMinus1Retry "fdGetMode" +    flags <- throwErrnoIfMinus1Retry "fdGetMode"                 (c_fcntl_read fd const_f_getfl) #endif     let@@ -157,7 +154,7 @@          | wH        = WriteMode          | rwH       = ReadWriteMode          | otherwise = ReadMode-          +     return mode  #ifdef mingw32_HOST_OS@@ -204,7 +201,7 @@     return ((lflag .&. fromIntegral const_echo) /= 0)  setCooked :: FD -> Bool -> IO ()-setCooked fd cooked = +setCooked fd cooked =   tcSetAttr fd $ \ p_tios -> do      -- turn on/off ICANON@@ -280,7 +277,7 @@    else return ()  ioe_unk_error :: String -> String -> IOException-ioe_unk_error loc msg +ioe_unk_error loc msg  = ioeSetErrorString (mkIOError OtherError loc Nothing Nothing) msg  -- Note: echoing goes hand in hand with enabling 'line input' / raw-ness@@ -323,7 +320,7 @@                  (c_fcntl_read fd const_f_getfl)   let flags' | set       = flags .|. o_NONBLOCK              | otherwise = flags .&. complement o_NONBLOCK-  unless (flags == flags') $ do+  when (flags /= flags') $ do     -- An error when setting O_NONBLOCK isn't fatal: on some systems     -- there are certain file handles on which this will fail (eg. /dev/null     -- on FreeBSD) so we throw away the return code from fcntl_write.@@ -441,7 +438,7 @@    c_fcntl_lock  :: CInt -> CInt -> Ptr CFLock -> IO CInt  foreign import ccall unsafe "HsBase.h fork"-   c_fork :: IO CPid +   c_fork :: IO CPid  foreign import ccall unsafe "HsBase.h link"    c_link :: CString -> CString -> IO CInt
System/Posix/Types.hs view
@@ -4,7 +4,7 @@            , MagicHash            , GeneralizedNewtypeDeriving   #-}-{-# LANGUAGE DeriveDataTypeable, StandaloneDeriving #-}+{-# LANGUAGE AutoDeriveTypeable, StandaloneDeriving #-}  ----------------------------------------------------------------------------- -- |
System/Timeout.hs view
@@ -1,6 +1,6 @@-{-# LANGUAGE Trustworthy #-}+{-# LANGUAGE Safe #-} {-# LANGUAGE CPP #-}-{-# LANGUAGE DeriveDataTypeable, StandaloneDeriving #-}+{-# LANGUAGE AutoDeriveTypeable, StandaloneDeriving #-}  ------------------------------------------------------------------------------- -- |
Text/ParserCombinators/ReadP.hs view
@@ -2,19 +2,20 @@ {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE MagicHash #-}+{-# LANGUAGE DeriveFunctor #-}  ----------------------------------------------------------------------------- -- | -- Module      :  Text.ParserCombinators.ReadP -- Copyright   :  (c) The University of Glasgow 2002 -- License     :  BSD-style (see the file libraries/base/LICENSE)--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  provisional -- Portability :  non-portable (local universal quantification) -- -- This is a library of parser combinators, originally written by Koen Claessen.--- It parses all alternatives in parallel, so it never keeps hold of +-- It parses all alternatives in parallel, so it never keeps hold of -- the beginning of the input string, a common source of space leaks with -- other parsers.  The '(+++)' choice combinator is genuinely commutative; -- it makes no difference which branch is \"shorter\".@@ -22,17 +23,17 @@ -----------------------------------------------------------------------------  module Text.ParserCombinators.ReadP-  ( +  (   -- * The 'ReadP' type   ReadP,-  +   -- * Primitive operations   get,   look,   (+++),   (<++),   gather,-  +   -- * Other operations   pfail,   eof,@@ -60,22 +61,20 @@   chainl1,   chainr1,   manyTill,-  +   -- * Running a parser   ReadS,   readP_to_S,   readS_to_P,-  +   -- * Properties   -- $properties   )  where -import Control.Monad( MonadPlus(..), sequence, liftM2 )--import {-# SOURCE #-} GHC.Unicode ( isSpace  )+import GHC.Unicode ( isSpace ) import GHC.List ( replicate, null )-import GHC.Base+import GHC.Base hiding ( many )  infixr 5 +++, <++ @@ -99,48 +98,57 @@   | Fail   | Result a (P a)   | Final [(a,String)] -- invariant: list is non-empty!+  deriving Functor  -- Monad, MonadPlus +instance Applicative P where+  pure  = return+  (<*>) = ap++instance MonadPlus P where+  mzero = empty+  mplus = (<|>)+ instance Monad P where   return x = Result x Fail    (Get f)      >>= k = Get (\c -> f c >>= k)   (Look f)     >>= k = Look (\s -> f s >>= k)   Fail         >>= _ = Fail-  (Result x p) >>= k = k x `mplus` (p >>= k)+  (Result x p) >>= k = k x <|> (p >>= k)   (Final r)    >>= k = final [ys' | (x,s) <- r, ys' <- run (k x) s]    fail _ = Fail -instance MonadPlus P where-  mzero = Fail+instance Alternative P where+  empty = Fail    -- most common case: two gets are combined-  Get f1     `mplus` Get f2     = Get (\c -> f1 c `mplus` f2 c)-  +  Get f1     <|> Get f2     = Get (\c -> f1 c <|> f2 c)+   -- results are delivered as soon as possible-  Result x p `mplus` q          = Result x (p `mplus` q)-  p          `mplus` Result x q = Result x (p `mplus` q)+  Result x p <|> q          = Result x (p <|> q)+  p          <|> Result x q = Result x (p <|> q)    -- fail disappears-  Fail       `mplus` p          = p-  p          `mplus` Fail       = p+  Fail       <|> p          = p+  p          <|> Fail       = p    -- two finals are combined   -- final + look becomes one look and one final (=optimization)   -- final + sthg else becomes one look and one final-  Final r    `mplus` Final t    = Final (r ++ t)-  Final r    `mplus` Look f     = Look (\s -> Final (r ++ run (f s) s))-  Final r    `mplus` p          = Look (\s -> Final (r ++ run p s))-  Look f     `mplus` Final r    = Look (\s -> Final (run (f s) s ++ r))-  p          `mplus` Final r    = Look (\s -> Final (run p s ++ r))+  Final r    <|> Final t    = Final (r ++ t)+  Final r    <|> Look f     = Look (\s -> Final (r ++ run (f s) s))+  Final r    <|> p          = Look (\s -> Final (r ++ run p s))+  Look f     <|> Final r    = Look (\s -> Final (run (f s) s ++ r))+  p          <|> Final r    = Look (\s -> Final (run p s ++ r))    -- two looks are combined (=optimization)   -- look + sthg else floats upwards-  Look f     `mplus` Look g     = Look (\s -> f s `mplus` g s)-  Look f     `mplus` p          = Look (\s -> f s `mplus` p)-  p          `mplus` Look f     = Look (\s -> p `mplus` f s)+  Look f     <|> Look g     = Look (\s -> f s <|> g s)+  Look f     <|> p          = Look (\s -> f s <|> p)+  p          <|> Look f     = Look (\s -> p <|> f s)  -- --------------------------------------------------------------------------- -- The ReadP type@@ -152,11 +160,19 @@ instance Functor ReadP where   fmap h (R f) = R (\k -> f (k . h)) +instance Applicative ReadP where+    pure = return+    (<*>) = ap+ instance Monad ReadP where   return x  = R (\k -> k x)   fail _    = R (\_ -> Fail)   R m >>= f = R (\k -> m (\a -> let R m' = f a in m' k)) +instance Alternative ReadP where+    empty = mzero+    (<|>) = mplus+ instance MonadPlus ReadP where   mzero = pfail   mplus = (+++)@@ -195,7 +211,7 @@  (+++) :: ReadP a -> ReadP a -> ReadP a -- ^ Symmetric choice.-R f1 +++ R f2 = R (\k -> f1 k `mplus` f2 k)+R f1 +++ R f2 = R (\k -> f1 k <|> f2 k)  (<++) :: ReadP a -> ReadP a -> ReadP a -- ^ Local, exclusive, left-biased choice: If left parser@@ -218,15 +234,15 @@ -- ^ Transforms a parser into one that does the same, but --   in addition returns the exact characters read. --   IMPORTANT NOTE: 'gather' gives a runtime error if its first argument---   is built using any occurrences of readS_to_P. +--   is built using any occurrences of readS_to_P. gather (R m)-  = R (\k -> gath id (m (\a -> return (\s -> k (s,a)))))  +  = R (\k -> gath id (m (\a -> return (\s -> k (s,a)))))  where   gath :: (String -> String) -> P (String -> P b) -> P b   gath l (Get f)      = Get (\c -> gath (l.(c:)) (f c))   gath _ Fail         = Fail   gath l (Look f)     = Look (\s -> gath l (f s))-  gath l (Result k p) = k (l []) `mplus` gath l p+  gath l (Result k p) = k (l []) <|> gath l p   gath _ (Final _)    = error "do not use readS_to_P in gather!"  -- ---------------------------------------------------------------------------@@ -243,8 +259,8 @@  eof :: ReadP () -- ^ Succeeds iff we are at the end of input-eof = do { s <- look -         ; if null s then return () +eof = do { s <- look+         ; if null s then return ()                      else pfail }  string :: String -> ReadP String@@ -461,12 +477,12 @@ >    xs +<+ _  = xs > >  prop_Gather s =->    forAll readPWithoutReadS $ \p -> +>    forAll readPWithoutReadS $ \p -> >      readP_to_S (gather p) s =~->	 [ ((pre,x::Int),s')->	 | (x,s') <- readP_to_S p s->	 , let pre = take (length s - length s') s->	 ]+>        [ ((pre,x::Int),s')+>        | (x,s') <- readP_to_S p s+>        , let pre = take (length s - length s') s+>        ] > >  prop_String_Yes this s = >    readP_to_S (string this) (this ++ s) =~
Text/ParserCombinators/ReadPrec.hs view
@@ -6,7 +6,7 @@ -- Module      :  Text.ParserCombinators.ReadPrec -- Copyright   :  (c) The University of Glasgow 2002 -- License     :  BSD-style (see the file libraries/base/LICENSE)--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  provisional -- Portability :  non-portable (uses Text.ParserCombinators.ReadP)@@ -16,9 +16,9 @@ -----------------------------------------------------------------------------  module Text.ParserCombinators.ReadPrec-  ( +  (   ReadPrec,-  +   -- * Precedences   Prec,   minPrec,@@ -61,7 +61,6 @@   , pfail   ) -import Control.Monad( MonadPlus(..) ) import GHC.Num( Num(..) ) import GHC.Base @@ -75,17 +74,24 @@ instance Functor ReadPrec where   fmap h (P f) = P (\n -> fmap h (f n)) +instance Applicative ReadPrec where+    pure = return+    (<*>) = ap+ instance Monad ReadPrec where   return x  = P (\_ -> return x)   fail s    = P (\_ -> fail s)   P f >>= k = P (\n -> do a <- f n; let P f' = k a in f' n)-  + instance MonadPlus ReadPrec where   mzero = pfail   mplus = (+++) +instance Alternative ReadPrec where+    empty = mzero+    (<|>) = mplus+ -- precedences-   type Prec = Int  minPrec :: Prec@@ -107,7 +113,7 @@ reset (P f) = P (\_ -> f minPrec)  prec :: Prec -> ReadPrec a -> ReadPrec a--- ^ @(prec n p)@ checks whether the precedence context is +-- ^ @(prec n p)@ checks whether the precedence context is --   less than or equal to @n@, and -- --   * if not, fails
Text/Printf.hs view
@@ -1,8 +1,5 @@ {-# LANGUAGE Safe #-}-{-# LANGUAGE CPP #-}-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >=  700 {-# LANGUAGE GADTs #-}-#endif  ----------------------------------------------------------------------------- -- |@@ -94,12 +91,12 @@   IsChar(..) ) where -import Prelude import Data.Char import Data.Int import Data.List import Data.Word import Numeric+import Numeric.Natural import System.IO  -------------------@@ -250,7 +247,7 @@ -- * Haskell 'printf' will place a zero after a decimal point when --   possible. ----- Examples:+-- ==== __Examples__ -- -- >   > printf "%d\n" (23::Int) -- >   23@@ -292,8 +289,6 @@ -- type system won't readily let us say that without -- bringing the GADTs. So we go conditional for these defs. -#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >=  700- instance (a ~ ()) => PrintfType (IO a) where     spr fmts args =         putStr $ map fromChar $ uprintf fmts $ reverse args@@ -302,21 +297,6 @@     hspr hdl fmts args = do         hPutStr hdl (uprintf fmts (reverse args)) -#else--instance PrintfType (IO a) where-    spr fmts args = do-        putStr $ map fromChar $ uprintf fmts $ reverse args-        return (error "PrintfType (IO a): result should not be used.")--instance HPrintfType (IO a) where-    hspr hdl fmts args = do-        hPutStr hdl (uprintf fmts (reverse args))-        return (error "HPrintfType (IO a): result should not be used.")--#endif-- instance (PrintfArg a, PrintfType r) => PrintfType (a -> r) where     spr fmts args = \ a -> spr fmts                              ((parseFormat a, formatArg a) : args)@@ -331,9 +311,9 @@ -- default 'parseFormat' expects no modifiers: this is the normal -- case. Minimal instance: 'formatArg'. class PrintfArg a where-    -- | /Since: 4.7.0.0/+    -- | @since 4.7.0.0     formatArg :: a -> FieldFormatter-    -- | /Since: 4.7.0.0/+    -- | @since 4.7.0.0     parseFormat :: a -> ModifierParser     parseFormat _ (c : cs) = FormatParse "" c cs     parseFormat _ "" = errorShortFormat@@ -389,6 +369,10 @@     formatArg = formatInteger     parseFormat = parseIntFormat +instance PrintfArg Natural where+    formatArg = formatInteger . toInteger+    parseFormat = parseIntFormat+ instance PrintfArg Float where     formatArg = formatRealFloat @@ -400,9 +384,9 @@ -- type, is not allowable as a typeclass instance. 'IsChar' -- is exported for backward-compatibility. class IsChar c where-    -- | /Since: 4.7.0.0/+    -- | @since 4.7.0.0     toChar :: c -> Char-    -- | /Since: 4.7.0.0/+    -- | @since 4.7.0.0     fromChar :: Char -> c  instance IsChar Char where@@ -414,19 +398,19 @@ -- | Whether to left-adjust or zero-pad a field. These are -- mutually exclusive, with 'LeftAdjust' taking precedence. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 data FormatAdjustment = LeftAdjust | ZeroPad  -- | How to handle the sign of a numeric field.  These are -- mutually exclusive, with 'SignPlus' taking precedence. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 data FormatSign = SignPlus | SignSpace  -- | Description of field formatting for 'formatArg'. See UNIX `printf`(3) -- for a description of how field formatting works. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 data FieldFormat = FieldFormat {   fmtWidth :: Maybe Int,       -- ^ Total width of the field.   fmtPrecision :: Maybe Int,   -- ^ Secondary field width specifier.@@ -460,7 +444,7 @@ -- modifier characters to find the primary format character. -- This is the type of its result. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 data FormatParse = FormatParse {   fpModifiers :: String,   -- ^ Any modifiers found.   fpChar :: Char,          -- ^ Primary format character.@@ -502,13 +486,13 @@ -- | This is the type of a field formatter reified over its -- argument. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 type FieldFormatter = FieldFormat -> ShowS  -- | Type of a function that will parse modifier characters -- from the format string. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 type ModifierParser = String -> FormatParse  -- | Substitute a \'v\' format character with the given@@ -516,21 +500,21 @@ -- convenience for user-implemented types, which should -- support \"%v\". ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 vFmt :: Char -> FieldFormat -> FieldFormat vFmt c ufmt@(FieldFormat {fmtChar = 'v'}) = ufmt {fmtChar = c} vFmt _ ufmt = ufmt  -- | Formatter for 'Char' values. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 formatChar :: Char -> FieldFormatter formatChar x ufmt =   formatIntegral (Just 0) (toInteger $ ord x) $ vFmt 'c' ufmt  -- | Formatter for 'String' values. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 formatString :: IsChar a => [a] -> FieldFormatter formatString x ufmt =   case fmtChar $ vFmt 's' ufmt of@@ -555,7 +539,7 @@  -- | Formatter for 'Int' values. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 formatInt :: (Integral a, Bounded a) => a -> FieldFormatter formatInt x ufmt =   let lb = toInteger $ minBound `asTypeOf` x@@ -568,7 +552,7 @@  -- | Formatter for 'Integer' values. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 formatInteger :: Integer -> FieldFormatter formatInteger x ufmt =   let m = fixupMods ufmt Nothing in@@ -609,7 +593,7 @@  -- | Formatter for 'RealFloat' values. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 formatRealFloat :: RealFloat a => a -> FieldFormatter formatRealFloat x ufmt =   let c = fmtChar $ vFmt 'g' ufmt@@ -885,14 +869,14 @@ -- | Raises an 'error' with a printf-specific prefix on the -- message string. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 perror :: String -> a perror s = error $ "printf: " ++ s  -- | Calls 'perror' to indicate an unknown format letter for -- a given type. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 errorBadFormat :: Char -> a errorBadFormat c = perror $ "bad formatting char " ++ show c @@ -900,15 +884,15 @@ -- | Calls 'perror' to indicate that the format string ended -- early. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 errorShortFormat = perror "formatting string ended prematurely" -- | Calls 'perror' to indicate that there is a missing -- argument in the argument list. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 errorMissingArgument = perror "argument list ended prematurely" -- | Calls 'perror' to indicate that there is a type -- error or similar in the given argument. ----- /Since: 4.7.0.0/+-- @since 4.7.0.0 errorBadArgument = perror "bad argument"
Text/Read.hs view
@@ -6,7 +6,7 @@ -- Module      :  Text.Read -- Copyright   :  (c) The University of Glasgow 2001 -- License     :  BSD-style (see the file libraries/base/LICENSE)--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  provisional -- Portability :  non-portable (uses Text.ParserCombinators.ReadP)@@ -15,7 +15,7 @@ -- -- The "Text.Read" library is the canonical library to import for -- 'Read'-class facilities.  For GHC only, it offers an extended and much--- improved 'Read' class, which constitutes a proposed alternative to the +-- improved 'Read' class, which constitutes a proposed alternative to the -- Haskell 2010 'Read'.  In particular, writing parsers is easier, and -- the parsers are much more efficient. --@@ -47,7 +47,6 @@ import GHC.Base import GHC.Read import Data.Either-import Data.Maybe import Text.ParserCombinators.ReadP as P import Text.ParserCombinators.ReadPrec import qualified Text.Read.Lex as L@@ -63,7 +62,7 @@ -- Succeeds if there is exactly one valid result. -- A 'Left' value indicates a parse error. ----- /Since: 4.6.0.0/+-- @since 4.6.0.0 readEither :: Read a => String -> Either String a readEither s =   case [ x | (x,"") <- readPrec_to_S read' minPrec s ] of@@ -79,7 +78,7 @@ -- | Parse a string using the 'Read' instance. -- Succeeds if there is exactly one valid result. ----- /Since: 4.6.0.0/+-- @since 4.6.0.0 readMaybe :: Read a => String -> Maybe a readMaybe s = case readEither s of                 Left _  -> Nothing
Text/Read/Lex.hs view
@@ -39,14 +39,20 @@ import GHC.Char import GHC.Num( Num(..), Integer ) import GHC.Show( Show(..) )-import {-# SOURCE #-} GHC.Unicode ( isSpace, isAlpha, isAlphaNum )-import GHC.Real( Rational, (%), fromIntegral,-                 toInteger, (^) )+import GHC.Unicode( isSpace, isAlpha, isAlphaNum )+import GHC.Real( Rational, (%), fromIntegral, Integral,+                 toInteger, (^), quot, even ) import GHC.List import GHC.Enum( minBound, maxBound ) import Data.Maybe-import Control.Monad +-- local copy to break import-cycle+-- | @'guard' b@ is @'return' ()@ if @b@ is 'True',+-- and 'mzero' if @b@ is 'False'.+guard           :: (MonadPlus m) => Bool -> m ()+guard True      =  return ()+guard False     =  mzero+ -- ----------------------------------------------------------------------------- -- Lexing types @@ -57,11 +63,11 @@   | Punc   String       -- ^ Punctuation or reserved symbol, e.g. @(@, @::@   | Ident  String       -- ^ Haskell identifier, e.g. @foo@, @Baz@   | Symbol String       -- ^ Haskell symbol, e.g. @>>@, @:%@-  | Number Number       -- ^ /Since: 4.6.0.0/+  | Number Number       -- ^ @since 4.6.0.0   | EOF  deriving (Eq, Show) --- | /Since: 4.7.0.0/+-- | @since 4.7.0.0 data Number = MkNumber Int              -- Base                        Digits           -- Integral part             | MkDecimal Digits          -- Integral part@@ -69,19 +75,19 @@                         (Maybe Integer) -- Exponent  deriving (Eq, Show) --- | /Since: 4.5.1.0/+-- | @since 4.5.1.0 numberToInteger :: Number -> Maybe Integer-numberToInteger (MkNumber base iPart) = Just (val (fromIntegral base) 0 iPart)-numberToInteger (MkDecimal iPart Nothing Nothing) = Just (val 10 0 iPart)+numberToInteger (MkNumber base iPart) = Just (val (fromIntegral base) iPart)+numberToInteger (MkDecimal iPart Nothing Nothing) = Just (val 10 iPart) numberToInteger _ = Nothing --- | /Since: 4.7.0.0/+-- | @since 4.7.0.0 numberToFixed :: Integer -> Number -> Maybe (Integer, Integer)-numberToFixed _ (MkNumber base iPart) = Just (val (fromIntegral base) 0 iPart, 0)-numberToFixed _ (MkDecimal iPart Nothing Nothing) = Just (val 10 0 iPart, 0)+numberToFixed _ (MkNumber base iPart) = Just (val (fromIntegral base) iPart, 0)+numberToFixed _ (MkDecimal iPart Nothing Nothing) = Just (val 10 iPart, 0) numberToFixed p (MkDecimal iPart (Just fPart) Nothing)-    = let i = val 10 0 iPart-          f = val 10 0 (integerTake p (fPart ++ repeat 0))+    = let i = val 10 iPart+          f = val 10 (integerTake p (fPart ++ repeat 0))           -- Sigh, we really want genericTake, but that's above us in           -- the hierarchy, so we define our own version here (actually           -- specialised to Integer)@@ -103,7 +109,7 @@ -- * We only worry about numbers that have an exponent. If they don't --   have an exponent then the Rational won't be much larger than the --   Number, so there is no problem--- | /Since: 4.5.1.0/+-- | @since 4.5.1.0 numberToRangedRational :: (Int, Int) -> Number                        -> Maybe Rational -- Nothing = Inf numberToRangedRational (neg, pos) n@(MkDecimal iPart mFPart (Just exp))@@ -133,11 +139,11 @@                 else Just (numberToRational n) numberToRangedRational _ n = Just (numberToRational n) --- | /Since: 4.6.0.0/+-- | @since 4.6.0.0 numberToRational :: Number -> Rational-numberToRational (MkNumber base iPart) = val (fromIntegral base) 0 iPart % 1+numberToRational (MkNumber base iPart) = val (fromIntegral base) iPart % 1 numberToRational (MkDecimal iPart mFPart mExp)- = let i = val 10 0 iPart+ = let i = val 10 iPart    in case (mFPart, mExp) of       (Nothing, Nothing)     -> i % 1       (Nothing, Just exp)@@ -156,9 +162,9 @@ lex :: ReadP Lexeme lex = skipSpaces >> lexToken --- | /Since: 4.7.0.0/+-- | @since 4.7.0.0 expect :: Lexeme -> ReadP ()-expect lexeme = do { skipSpaces +expect lexeme = do { skipSpaces                    ; thing <- lexToken                    ; if thing == lexeme then return () else pfail } @@ -444,15 +450,51 @@ lexInteger :: Base -> ReadP Integer lexInteger base =   do xs <- lexDigits base-     return (val (fromIntegral base) 0 xs)+     return (val (fromIntegral base) xs) -val :: Num a => a -> a -> Digits -> a--- val base y [d1,..,dn] = y ++ [d1,..,dn], as it were-val _    y []     = y-val base y (x:xs) = y' `seq` val base y' xs- where-  y' = y * base + fromIntegral x+val :: Num a => a -> Digits -> a+val = valSimple+{-# RULES+"val/Integer" val = valInteger+  #-}+{-# INLINE [1] val #-} +-- The following algorithm is only linear for types whose Num operations+-- are in constant time.+valSimple :: (Num a, Integral d) => a -> [d] -> a+valSimple base = go 0+  where+    go r [] = r+    go r (d : ds) = r' `seq` go r' ds+      where+        r' = r * base + fromIntegral d+{-# INLINE valSimple #-}++-- A sub-quadratic algorithm for Integer. Pairs of adjacent radix b+-- digits are combined into a single radix b^2 digit. This process is+-- repeated until we are left with a single digit. This algorithm+-- performs well only on large inputs, so we use the simple algorithm+-- for smaller inputs.+valInteger :: Integer -> Digits -> Integer+valInteger b0 ds0 = go b0 (length ds0) $ map fromIntegral ds0+  where+    go _ _ []  = 0+    go _ _ [d] = d+    go b l ds+        | l > 40 = b' `seq` go b' l' (combine b ds')+        | otherwise = valSimple b ds+      where+        -- ensure that we have an even number of digits+        -- before we call combine:+        ds' = if even l then ds else 0 : ds+        b' = b * b+        l' = (l + 1) `quot` 2+    combine b (d1 : d2 : ds) = d `seq` (d : combine b ds)+      where+        d = d1 * b + d2+    combine _ []  = []+    combine _ [_] = error "this should not happen"+ -- Calculate a Rational from the exponent [of 10 to multiply with], -- the integral part of the mantissa and the digits of the fractional -- part. Leaving the calculation of the power of 10 until the end,@@ -496,16 +538,21 @@ readIntP :: Num a => a -> (Char -> Bool) -> (Char -> Int) -> ReadP a readIntP base isDigit valDigit =   do s <- munch1 isDigit-     return (val base 0 (map valDigit s))+     return (val base (map valDigit s))+{-# SPECIALISE readIntP+        :: Integer -> (Char -> Bool) -> (Char -> Int) -> ReadP Integer #-}  readIntP' :: (Eq a, Num a) => a -> ReadP a readIntP' base = readIntP base isDigit valDigit  where   isDigit  c = maybe False (const True) (valDig base c)   valDigit c = maybe 0     id           (valDig base c)+{-# SPECIALISE readIntP' :: Integer -> ReadP Integer #-}  readOctP, readDecP, readHexP :: (Eq a, Num a) => ReadP a readOctP = readIntP' 8 readDecP = readIntP' 10 readHexP = readIntP' 16-+{-# SPECIALISE readOctP :: ReadP Integer #-}+{-# SPECIALISE readDecP :: ReadP Integer #-}+{-# SPECIALISE readHexP :: ReadP Integer #-}
Text/Show/Functions.hs view
@@ -7,7 +7,7 @@ -- Module      :  Text.Show.Functions -- Copyright   :  (c) The University of Glasgow 2001 -- License     :  BSD-style (see the file libraries/base/LICENSE)--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  provisional -- Portability :  portable@@ -15,14 +15,12 @@ -- Optional instance of 'Text.Show.Show' for functions: -- -- > instance Show (a -> b) where--- > 	showsPrec _ _ = showString \"\<function\>\"+-- >    showsPrec _ _ = showString \"\<function\>\" -- -----------------------------------------------------------------------------  module Text.Show.Functions () where -import Prelude- instance Show (a -> b) where-	showsPrec _ _ = showString "<function>"+        showsPrec _ _ = showString "<function>" 
base.cabal view
@@ -1,6 +1,6 @@ name:           base-version:        4.7.0.2--- GHC 7.6.3 released with 4.7.0.0+version:        4.8.0.0+-- NOTE: Don't forget to update ./changelog.md license:        BSD3 license-file:   LICENSE maintainer:     libraries@haskell.org@@ -39,14 +39,28 @@  source-repository head     type:     git-    location: http://git.haskell.org/packages/base.git+    location: http://git.haskell.org/ghc.git+    subdir:   libraries/base  Flag integer-simple     Description: Use integer-simple+    Manual: True+    Default: False +Flag integer-gmp+    Description: Use integer-gmp+    Manual: True+    Default: False++Flag integer-gmp2+    Description: Use integer-gmp2+    Manual: True+    Default: False+ Library     default-language: Haskell2010     other-extensions:+        AutoDeriveTypeable         BangPatterns         CApiFFI         CPP@@ -67,7 +81,6 @@         NegativeLiterals         NoImplicitPrelude         NondecreasingIndentation-        OverlappingInstances         OverloadedStrings         ParallelArrays         PolyKinds@@ -86,13 +99,18 @@         UnliftedFFITypes         Unsafe -    build-depends: rts == 1.0.*, ghc-prim >= 0.3.1 && < 0.4+    build-depends: rts == 1.0.*, ghc-prim == 0.4.*     if flag(integer-simple)         build-depends: integer-simple >= 0.1.1 && < 0.2-    else++    if flag(integer-gmp)         build-depends: integer-gmp >= 0.5.1 && < 0.6         cpp-options: -DOPTIMISE_INTEGER_GCD_LCM +    if flag(integer-gmp2)+        build-depends: integer-gmp >= 1.0 && < 1.1+        cpp-options: -DOPTIMISE_INTEGER_GCD_LCM+     exposed-modules:         Control.Applicative         Control.Arrow@@ -115,6 +133,7 @@         Control.Monad.ST.Strict         Control.Monad.ST.Unsafe         Control.Monad.Zip+        Data.Bifunctor         Data.Bits         Data.Bool         Data.Char@@ -128,14 +147,13 @@         Data.Foldable         Data.Function         Data.Functor+        Data.Functor.Identity         Data.IORef         Data.Int         Data.Ix         Data.List         Data.Maybe         Data.Monoid-        Data.OldTypeable-        Data.OldTypeable.Internal         Data.Ord         Data.Proxy         Data.Ratio@@ -152,6 +170,7 @@         Data.Typeable.Internal         Data.Unique         Data.Version+        Data.Void         Data.Word         Debug.Trace         Foreign@@ -226,14 +245,18 @@         GHC.Int         GHC.List         GHC.MVar+        GHC.Natural         GHC.Num+        GHC.OldList         GHC.PArr         GHC.Pack         GHC.Profiling         GHC.Ptr         GHC.Read         GHC.Real+        GHC.RTS.Flags         GHC.ST+        GHC.StaticPtr         GHC.STRef         GHC.Show         GHC.Stable@@ -246,6 +269,7 @@         GHC.Weak         GHC.Word         Numeric+        Numeric.Natural         Prelude         System.CPUTime         System.Console.GetOpt@@ -273,6 +297,7 @@     other-modules:         Control.Monad.ST.Imp         Control.Monad.ST.Lazy.Imp+        Data.OldList         Foreign.ForeignPtr.Imp         System.Environment.ExecutablePath @@ -287,6 +312,7 @@         cbits/inputReady.c         cbits/md5.c         cbits/primFloat.c+        cbits/rts.c         cbits/sysconf.c      include-dirs: include@@ -297,7 +323,6 @@         WCsubst.h         consUtils.h         Typeable.h-        OldTypeable.h      -- OS Specific     if os(windows)@@ -326,6 +351,6 @@             GHC.Event.TimerManager             GHC.Event.Unique -    -- We need to set the package name to base (without a version number)+    -- We need to set the package key to base (without a version number)     -- as it's magic.-    ghc-options: -package-name base+    ghc-options: -this-package-key base
cbits/PrelIOUtils.c view
@@ -1,19 +1,14 @@-/* +/*  * (c) The University of Glasgow 2002  *- * static versions of the inline functions in HsCore.h+ * static versions of the inline functions in HsBase.h  */  #define INLINE -#ifdef __GLASGOW_HASKELL__-# include "Rts.h"-#endif-+#include "Rts.h" #include "HsBase.h" -#ifdef __GLASGOW_HASKELL__- void errorBelch2(const char*s, char *t) {     errorBelch(s,t);@@ -48,5 +43,3 @@ #endif } #endif--#endif /* __GLASGOW_HASKELL__ */
cbits/WCsubst.c view
@@ -1,4397 +1,4747 @@ /*------------------------------------------------------------------------- This is an automatically generated file: do not edit-Generated by ubconfc at Mon Feb  7 20:26:56 CET 2011--------------------------------------------------------------------------*/--#include "WCsubst.h"--/* Unicode general categories, listed in the same order as in the Unicode- * standard -- this must be the same order as in GHC.Unicode.- */--enum {-    NUMCAT_LU,  /* Letter, Uppercase */-    NUMCAT_LL,  /* Letter, Lowercase */-    NUMCAT_LT,  /* Letter, Titlecase */-    NUMCAT_LM,  /* Letter, Modifier */-    NUMCAT_LO,  /* Letter, Other */-    NUMCAT_MN,  /* Mark, Non-Spacing */-    NUMCAT_MC,  /* Mark, Spacing Combining */-    NUMCAT_ME,  /* Mark, Enclosing */-    NUMCAT_ND,  /* Number, Decimal */-    NUMCAT_NL,  /* Number, Letter */-    NUMCAT_NO,  /* Number, Other */-    NUMCAT_PC,  /* Punctuation, Connector */-    NUMCAT_PD,  /* Punctuation, Dash */-    NUMCAT_PS,  /* Punctuation, Open */-    NUMCAT_PE,  /* Punctuation, Close */-    NUMCAT_PI,  /* Punctuation, Initial quote */-    NUMCAT_PF,  /* Punctuation, Final quote */-    NUMCAT_PO,  /* Punctuation, Other */-    NUMCAT_SM,  /* Symbol, Math */-    NUMCAT_SC,  /* Symbol, Currency */-    NUMCAT_SK,  /* Symbol, Modifier */-    NUMCAT_SO,  /* Symbol, Other */-    NUMCAT_ZS,  /* Separator, Space */-    NUMCAT_ZL,  /* Separator, Line */-    NUMCAT_ZP,  /* Separator, Paragraph */-    NUMCAT_CC,  /* Other, Control */-    NUMCAT_CF,  /* Other, Format */-    NUMCAT_CS,  /* Other, Surrogate */-    NUMCAT_CO,  /* Other, Private Use */-    NUMCAT_CN   /* Other, Not Assigned */-};--struct _convrule_ -{ -	unsigned int category;-	unsigned int catnumber;-	int possible;-	int updist;-	int lowdist; -	int titledist;-};--struct _charblock_ -{ -	int start;-	int length;-	const struct _convrule_ *rule;-};--#define GENCAT_LO 262144-#define GENCAT_PC 2048-#define GENCAT_PD 128-#define GENCAT_MN 2097152-#define GENCAT_PE 32-#define GENCAT_NL 16777216-#define GENCAT_PF 131072-#define GENCAT_LT 524288-#define GENCAT_NO 65536-#define GENCAT_LU 512-#define GENCAT_PI 16384-#define GENCAT_SC 8-#define GENCAT_PO 4-#define GENCAT_PS 16-#define GENCAT_SK 1024-#define GENCAT_SM 64-#define GENCAT_SO 8192-#define GENCAT_CC 1-#define GENCAT_CF 32768-#define GENCAT_CO 268435456-#define GENCAT_ZL 33554432-#define GENCAT_CS 134217728-#define GENCAT_ZP 67108864-#define GENCAT_ZS 2-#define GENCAT_MC 8388608-#define GENCAT_ME 4194304-#define GENCAT_ND 256-#define GENCAT_LL 4096-#define GENCAT_LM 1048576-#define MAX_UNI_CHAR 1114109-#define NUM_BLOCKS 2783-#define NUM_CONVBLOCKS 1230-#define NUM_SPACEBLOCKS 8-#define NUM_LAT1BLOCKS 63-#define NUM_RULES 167-static const struct _convrule_ rule160={GENCAT_LL, NUMCAT_LL, 1, -7264, 0, -7264};-static const struct _convrule_ rule36={GENCAT_LU, NUMCAT_LU, 1, 0, 211, 0};-static const struct _convrule_ rule25={GENCAT_LU, NUMCAT_LU, 1, 0, -121, 0};-static const struct _convrule_ rule18={GENCAT_LL, NUMCAT_LL, 1, 743, 0, 743};-static const struct _convrule_ rule108={GENCAT_LU, NUMCAT_LU, 1, 0, 80, 0};-static const struct _convrule_ rule50={GENCAT_LL, NUMCAT_LL, 1, -79, 0, -79};-static const struct _convrule_ rule106={GENCAT_LL, NUMCAT_LL, 1, -96, 0, -96};-static const struct _convrule_ rule79={GENCAT_LL, NUMCAT_LL, 1, -69, 0, -69};-static const struct _convrule_ rule126={GENCAT_LL, NUMCAT_LL, 1, 128, 0, 128};-static const struct _convrule_ rule119={GENCAT_LL, NUMCAT_LL, 1, -59, 0, -59};-static const struct _convrule_ rule102={GENCAT_LL, NUMCAT_LL, 1, -86, 0, -86};-static const struct _convrule_ rule38={GENCAT_LL, NUMCAT_LL, 1, 163, 0, 163};-static const struct _convrule_ rule113={GENCAT_LL, NUMCAT_LL, 1, -48, 0, -48};-static const struct _convrule_ rule133={GENCAT_LL, NUMCAT_LL, 1, -7205, 0, -7205};-static const struct _convrule_ rule128={GENCAT_LL, NUMCAT_LL, 1, 126, 0, 126};-static const struct _convrule_ rule97={GENCAT_LL, NUMCAT_LL, 1, -57, 0, -57};-static const struct _convrule_ rule161={GENCAT_LU, NUMCAT_LU, 1, 0, -35332, 0};-static const struct _convrule_ rule136={GENCAT_LU, NUMCAT_LU, 1, 0, -112, 0};-static const struct _convrule_ rule99={GENCAT_LL, NUMCAT_LL, 1, -47, 0, -47};-static const struct _convrule_ rule90={GENCAT_LL, NUMCAT_LL, 1, -38, 0, -38};-static const struct _convrule_ rule32={GENCAT_LU, NUMCAT_LU, 1, 0, 202, 0};-static const struct _convrule_ rule145={GENCAT_LL, NUMCAT_LL, 1, -28, 0, -28};-static const struct _convrule_ rule93={GENCAT_LL, NUMCAT_LL, 1, -64, 0, -64};-static const struct _convrule_ rule91={GENCAT_LL, NUMCAT_LL, 1, -37, 0, -37};-static const struct _convrule_ rule60={GENCAT_LU, NUMCAT_LU, 1, 0, 71, 0};-static const struct _convrule_ rule100={GENCAT_LL, NUMCAT_LL, 1, -54, 0, -54};-static const struct _convrule_ rule94={GENCAT_LL, NUMCAT_LL, 1, -63, 0, -63};-static const struct _convrule_ rule35={GENCAT_LL, NUMCAT_LL, 1, 97, 0, 97};-static const struct _convrule_ rule149={GENCAT_SO, NUMCAT_SO, 1, -26, 0, -26};-static const struct _convrule_ rule103={GENCAT_LL, NUMCAT_LL, 1, -80, 0, -80};-static const struct _convrule_ rule96={GENCAT_LL, NUMCAT_LL, 1, -62, 0, -62};-static const struct _convrule_ rule81={GENCAT_LL, NUMCAT_LL, 1, -71, 0, -71};-static const struct _convrule_ rule9={GENCAT_LU, NUMCAT_LU, 1, 0, 32, 0};-static const struct _convrule_ rule147={GENCAT_NL, NUMCAT_NL, 1, -16, 0, -16};-static const struct _convrule_ rule143={GENCAT_LU, NUMCAT_LU, 1, 0, -8262, 0};-static const struct _convrule_ rule127={GENCAT_LL, NUMCAT_LL, 1, 112, 0, 112};-static const struct _convrule_ rule124={GENCAT_LL, NUMCAT_LL, 1, 86, 0, 86};-static const struct _convrule_ rule40={GENCAT_LL, NUMCAT_LL, 1, 130, 0, 130};-static const struct _convrule_ rule20={GENCAT_LL, NUMCAT_LL, 1, 121, 0, 121};-static const struct _convrule_ rule158={GENCAT_LU, NUMCAT_LU, 1, 0, -10782, 0};-static const struct _convrule_ rule111={GENCAT_LL, NUMCAT_LL, 1, -15, 0, -15};-static const struct _convrule_ rule12={GENCAT_LL, NUMCAT_LL, 1, -32, 0, -32};-static const struct _convrule_ rule85={GENCAT_MN, NUMCAT_MN, 1, 84, 0, 84};-static const struct _convrule_ rule166={GENCAT_LL, NUMCAT_LL, 1, -40, 0, -40};-static const struct _convrule_ rule125={GENCAT_LL, NUMCAT_LL, 1, 100, 0, 100};-static const struct _convrule_ rule123={GENCAT_LL, NUMCAT_LL, 1, 74, 0, 74};-static const struct _convrule_ rule92={GENCAT_LL, NUMCAT_LL, 1, -31, 0, -31};-static const struct _convrule_ rule56={GENCAT_LU, NUMCAT_LU, 1, 0, 10792, 0};-static const struct _convrule_ rule46={GENCAT_LL, NUMCAT_LL, 1, 56, 0, 56};-static const struct _convrule_ rule33={GENCAT_LU, NUMCAT_LU, 1, 0, 203, 0};-static const struct _convrule_ rule150={GENCAT_LU, NUMCAT_LU, 1, 0, -10743, 0};-static const struct _convrule_ rule39={GENCAT_LU, NUMCAT_LU, 1, 0, 213, 0};-static const struct _convrule_ rule57={GENCAT_LL, NUMCAT_LL, 1, 10815, 0, 10815};-static const struct _convrule_ rule157={GENCAT_LU, NUMCAT_LU, 1, 0, -10783, 0};-static const struct _convrule_ rule55={GENCAT_LU, NUMCAT_LU, 1, 0, -163, 0};-static const struct _convrule_ rule151={GENCAT_LU, NUMCAT_LU, 1, 0, -3814, 0};-static const struct _convrule_ rule142={GENCAT_LU, NUMCAT_LU, 1, 0, -8383, 0};-static const struct _convrule_ rule101={GENCAT_LL, NUMCAT_LL, 1, -8, 0, -8};-static const struct _convrule_ rule89={GENCAT_LU, NUMCAT_LU, 1, 0, 63, 0};-static const struct _convrule_ rule41={GENCAT_LU, NUMCAT_LU, 1, 0, 214, 0};-static const struct _convrule_ rule118={GENCAT_LL, NUMCAT_LL, 1, 3814, 0, 3814};-static const struct _convrule_ rule26={GENCAT_LL, NUMCAT_LL, 1, -300, 0, -300};-static const struct _convrule_ rule159={GENCAT_LU, NUMCAT_LU, 1, 0, -10815, 0};-static const struct _convrule_ rule115={GENCAT_LU, NUMCAT_LU, 1, 0, 7264, 0};-static const struct _convrule_ rule22={GENCAT_LL, NUMCAT_LL, 1, -1, 0, -1};-static const struct _convrule_ rule120={GENCAT_LU, NUMCAT_LU, 1, 0, -7615, 0};-static const struct _convrule_ rule49={GENCAT_LL, NUMCAT_LL, 1, -2, 0, -1};-static const struct _convrule_ rule131={GENCAT_LU, NUMCAT_LU, 1, 0, -74, 0};-static const struct _convrule_ rule88={GENCAT_LU, NUMCAT_LU, 1, 0, 64, 0};-static const struct _convrule_ rule30={GENCAT_LU, NUMCAT_LU, 1, 0, 205, 0};-static const struct _convrule_ rule117={GENCAT_LL, NUMCAT_LL, 1, 35332, 0, 35332};-static const struct _convrule_ rule110={GENCAT_LU, NUMCAT_LU, 1, 0, 15, 0};-static const struct _convrule_ rule130={GENCAT_LL, NUMCAT_LL, 1, 9, 0, 9};-static const struct _convrule_ rule121={GENCAT_LL, NUMCAT_LL, 1, 8, 0, 8};-static const struct _convrule_ rule95={GENCAT_LU, NUMCAT_LU, 1, 0, 8, 0};-static const struct _convrule_ rule54={GENCAT_LU, NUMCAT_LU, 1, 0, 10795, 0};-static const struct _convrule_ rule29={GENCAT_LU, NUMCAT_LU, 1, 0, 206, 0};-static const struct _convrule_ rule138={GENCAT_LU, NUMCAT_LU, 1, 0, -126, 0};-static const struct _convrule_ rule104={GENCAT_LL, NUMCAT_LL, 1, 7, 0, 7};-static const struct _convrule_ rule58={GENCAT_LU, NUMCAT_LU, 1, 0, -195, 0};-static const struct _convrule_ rule146={GENCAT_NL, NUMCAT_NL, 1, 0, 16, 0};-static const struct _convrule_ rule148={GENCAT_SO, NUMCAT_SO, 1, 0, 26, 0};-static const struct _convrule_ rule70={GENCAT_LL, NUMCAT_LL, 1, 42280, 0, 42280};-static const struct _convrule_ rule107={GENCAT_LU, NUMCAT_LU, 1, 0, -7, 0};-static const struct _convrule_ rule52={GENCAT_LU, NUMCAT_LU, 1, 0, -56, 0};-static const struct _convrule_ rule153={GENCAT_LL, NUMCAT_LL, 1, -10795, 0, -10795};-static const struct _convrule_ rule152={GENCAT_LU, NUMCAT_LU, 1, 0, -10727, 0};-static const struct _convrule_ rule141={GENCAT_LU, NUMCAT_LU, 1, 0, -7517, 0};-static const struct _convrule_ rule34={GENCAT_LU, NUMCAT_LU, 1, 0, 207, 0};-static const struct _convrule_ rule164={GENCAT_CO, NUMCAT_CO, 0, 0, 0, 0};-static const struct _convrule_ rule84={GENCAT_MN, NUMCAT_MN, 0, 0, 0, 0};-static const struct _convrule_ rule16={GENCAT_CF, NUMCAT_CF, 0, 0, 0, 0};-static const struct _convrule_ rule45={GENCAT_LO, NUMCAT_LO, 0, 0, 0, 0};-static const struct _convrule_ rule13={GENCAT_SO, NUMCAT_SO, 0, 0, 0, 0};-static const struct _convrule_ rule17={GENCAT_NO, NUMCAT_NO, 0, 0, 0, 0};-static const struct _convrule_ rule8={GENCAT_ND, NUMCAT_ND, 0, 0, 0, 0};-static const struct _convrule_ rule14={GENCAT_LL, NUMCAT_LL, 0, 0, 0, 0};-static const struct _convrule_ rule98={GENCAT_LU, NUMCAT_LU, 0, 0, 0, 0};-static const struct _convrule_ rule6={GENCAT_SM, NUMCAT_SM, 0, 0, 0, 0};-static const struct _convrule_ rule114={GENCAT_MC, NUMCAT_MC, 0, 0, 0, 0};-static const struct _convrule_ rule2={GENCAT_PO, NUMCAT_PO, 0, 0, 0, 0};-static const struct _convrule_ rule116={GENCAT_NL, NUMCAT_NL, 0, 0, 0, 0};-static const struct _convrule_ rule3={GENCAT_SC, NUMCAT_SC, 0, 0, 0, 0};-static const struct _convrule_ rule10={GENCAT_SK, NUMCAT_SK, 0, 0, 0, 0};-static const struct _convrule_ rule83={GENCAT_LM, NUMCAT_LM, 0, 0, 0, 0};-static const struct _convrule_ rule5={GENCAT_PE, NUMCAT_PE, 0, 0, 0, 0};-static const struct _convrule_ rule4={GENCAT_PS, NUMCAT_PS, 0, 0, 0, 0};-static const struct _convrule_ rule11={GENCAT_PC, NUMCAT_PC, 0, 0, 0, 0};-static const struct _convrule_ rule7={GENCAT_PD, NUMCAT_PD, 0, 0, 0, 0};-static const struct _convrule_ rule163={GENCAT_CS, NUMCAT_CS, 0, 0, 0, 0};-static const struct _convrule_ rule109={GENCAT_ME, NUMCAT_ME, 0, 0, 0, 0};-static const struct _convrule_ rule1={GENCAT_ZS, NUMCAT_ZS, 0, 0, 0, 0};-static const struct _convrule_ rule19={GENCAT_PF, NUMCAT_PF, 0, 0, 0, 0};-static const struct _convrule_ rule15={GENCAT_PI, NUMCAT_PI, 0, 0, 0, 0};-static const struct _convrule_ rule140={GENCAT_ZP, NUMCAT_ZP, 0, 0, 0, 0};-static const struct _convrule_ rule139={GENCAT_ZL, NUMCAT_ZL, 0, 0, 0, 0};-static const struct _convrule_ rule134={GENCAT_LU, NUMCAT_LU, 1, 0, -86, 0};-static const struct _convrule_ rule43={GENCAT_LU, NUMCAT_LU, 1, 0, 217, 0};-static const struct _convrule_ rule0={GENCAT_CC, NUMCAT_CC, 0, 0, 0, 0};-static const struct _convrule_ rule154={GENCAT_LL, NUMCAT_LL, 1, -10792, 0, -10792};-static const struct _convrule_ rule74={GENCAT_LL, NUMCAT_LL, 1, 10749, 0, 10749};-static const struct _convrule_ rule87={GENCAT_LU, NUMCAT_LU, 1, 0, 37, 0};-static const struct _convrule_ rule61={GENCAT_LL, NUMCAT_LL, 1, 10783, 0, 10783};-static const struct _convrule_ rule122={GENCAT_LU, NUMCAT_LU, 1, 0, -8, 0};-static const struct _convrule_ rule129={GENCAT_LT, NUMCAT_LT, 1, 0, -8, 0};-static const struct _convrule_ rule63={GENCAT_LL, NUMCAT_LL, 1, 10782, 0, 10782};-static const struct _convrule_ rule82={GENCAT_LL, NUMCAT_LL, 1, -219, 0, -219};-static const struct _convrule_ rule77={GENCAT_LL, NUMCAT_LL, 1, 10727, 0, 10727};-static const struct _convrule_ rule78={GENCAT_LL, NUMCAT_LL, 1, -218, 0, -218};-static const struct _convrule_ rule71={GENCAT_LL, NUMCAT_LL, 1, -209, 0, -209};-static const struct _convrule_ rule62={GENCAT_LL, NUMCAT_LL, 1, 10780, 0, 10780};-static const struct _convrule_ rule48={GENCAT_LT, NUMCAT_LT, 1, -1, 1, 0};-static const struct _convrule_ rule21={GENCAT_LU, NUMCAT_LU, 1, 0, 1, 0};-static const struct _convrule_ rule137={GENCAT_LU, NUMCAT_LU, 1, 0, -128, 0};-static const struct _convrule_ rule80={GENCAT_LL, NUMCAT_LL, 1, -217, 0, -217};-static const struct _convrule_ rule73={GENCAT_LL, NUMCAT_LL, 1, 10743, 0, 10743};-static const struct _convrule_ rule42={GENCAT_LU, NUMCAT_LU, 1, 0, 218, 0};-static const struct _convrule_ rule69={GENCAT_LL, NUMCAT_LL, 1, -207, 0, -207};-static const struct _convrule_ rule51={GENCAT_LU, NUMCAT_LU, 1, 0, -97, 0};-static const struct _convrule_ rule144={GENCAT_LU, NUMCAT_LU, 1, 0, 28, 0};-static const struct _convrule_ rule65={GENCAT_LL, NUMCAT_LL, 1, -206, 0, -206};-static const struct _convrule_ rule86={GENCAT_LU, NUMCAT_LU, 1, 0, 38, 0};-static const struct _convrule_ rule76={GENCAT_LL, NUMCAT_LL, 1, -214, 0, -214};-static const struct _convrule_ rule66={GENCAT_LL, NUMCAT_LL, 1, -205, 0, -205};-static const struct _convrule_ rule24={GENCAT_LL, NUMCAT_LL, 1, -232, 0, -232};-static const struct _convrule_ rule112={GENCAT_LU, NUMCAT_LU, 1, 0, 48, 0};-static const struct _convrule_ rule132={GENCAT_LT, NUMCAT_LT, 1, 0, -9, 0};-static const struct _convrule_ rule75={GENCAT_LL, NUMCAT_LL, 1, -213, 0, -213};-static const struct _convrule_ rule68={GENCAT_LL, NUMCAT_LL, 1, -203, 0, -203};-static const struct _convrule_ rule135={GENCAT_LU, NUMCAT_LU, 1, 0, -100, 0};-static const struct _convrule_ rule72={GENCAT_LL, NUMCAT_LL, 1, -211, 0, -211};-static const struct _convrule_ rule67={GENCAT_LL, NUMCAT_LL, 1, -202, 0, -202};-static const struct _convrule_ rule47={GENCAT_LU, NUMCAT_LU, 1, 0, 2, 1};-static const struct _convrule_ rule37={GENCAT_LU, NUMCAT_LU, 1, 0, 209, 0};-static const struct _convrule_ rule156={GENCAT_LU, NUMCAT_LU, 1, 0, -10749, 0};-static const struct _convrule_ rule64={GENCAT_LL, NUMCAT_LL, 1, -210, 0, -210};-static const struct _convrule_ rule44={GENCAT_LU, NUMCAT_LU, 1, 0, 219, 0};-static const struct _convrule_ rule28={GENCAT_LU, NUMCAT_LU, 1, 0, 210, 0};-static const struct _convrule_ rule53={GENCAT_LU, NUMCAT_LU, 1, 0, -130, 0};-static const struct _convrule_ rule165={GENCAT_LU, NUMCAT_LU, 1, 0, 40, 0};-static const struct _convrule_ rule162={GENCAT_LU, NUMCAT_LU, 1, 0, -42280, 0};-static const struct _convrule_ rule155={GENCAT_LU, NUMCAT_LU, 1, 0, -10780, 0};-static const struct _convrule_ rule105={GENCAT_LU, NUMCAT_LU, 1, 0, -60, 0};-static const struct _convrule_ rule59={GENCAT_LU, NUMCAT_LU, 1, 0, 69, 0};-static const struct _convrule_ rule31={GENCAT_LU, NUMCAT_LU, 1, 0, 79, 0};-static const struct _convrule_ rule27={GENCAT_LL, NUMCAT_LL, 1, 195, 0, 195};-static const struct _convrule_ rule23={GENCAT_LU, NUMCAT_LU, 1, 0, -199, 0};-static const struct _charblock_ allchars[]={-	{0, 32, &rule0},-	{32, 1, &rule1},-	{33, 3, &rule2},-	{36, 1, &rule3},-	{37, 3, &rule2},-	{40, 1, &rule4},-	{41, 1, &rule5},-	{42, 1, &rule2},-	{43, 1, &rule6},-	{44, 1, &rule2},-	{45, 1, &rule7},-	{46, 2, &rule2},-	{48, 10, &rule8},-	{58, 2, &rule2},-	{60, 3, &rule6},-	{63, 2, &rule2},-	{65, 26, &rule9},-	{91, 1, &rule4},-	{92, 1, &rule2},-	{93, 1, &rule5},-	{94, 1, &rule10},-	{95, 1, &rule11},-	{96, 1, &rule10},-	{97, 26, &rule12},-	{123, 1, &rule4},-	{124, 1, &rule6},-	{125, 1, &rule5},-	{126, 1, &rule6},-	{127, 33, &rule0},-	{160, 1, &rule1},-	{161, 1, &rule2},-	{162, 4, &rule3},-	{166, 2, &rule13},-	{168, 1, &rule10},-	{169, 1, &rule13},-	{170, 1, &rule14},-	{171, 1, &rule15},-	{172, 1, &rule6},-	{173, 1, &rule16},-	{174, 1, &rule13},-	{175, 1, &rule10},-	{176, 1, &rule13},-	{177, 1, &rule6},-	{178, 2, &rule17},-	{180, 1, &rule10},-	{181, 1, &rule18},-	{182, 1, &rule13},-	{183, 1, &rule2},-	{184, 1, &rule10},-	{185, 1, &rule17},-	{186, 1, &rule14},-	{187, 1, &rule19},-	{188, 3, &rule17},-	{191, 1, &rule2},-	{192, 23, &rule9},-	{215, 1, &rule6},-	{216, 7, &rule9},-	{223, 1, &rule14},-	{224, 23, &rule12},-	{247, 1, &rule6},-	{248, 7, &rule12},-	{255, 1, &rule20},-	{256, 1, &rule21},-	{257, 1, &rule22},-	{258, 1, &rule21},-	{259, 1, &rule22},-	{260, 1, &rule21},-	{261, 1, &rule22},-	{262, 1, &rule21},-	{263, 1, &rule22},-	{264, 1, &rule21},-	{265, 1, &rule22},-	{266, 1, &rule21},-	{267, 1, &rule22},-	{268, 1, &rule21},-	{269, 1, &rule22},-	{270, 1, &rule21},-	{271, 1, &rule22},-	{272, 1, &rule21},-	{273, 1, &rule22},-	{274, 1, &rule21},-	{275, 1, &rule22},-	{276, 1, &rule21},-	{277, 1, &rule22},-	{278, 1, &rule21},-	{279, 1, &rule22},-	{280, 1, &rule21},-	{281, 1, &rule22},-	{282, 1, &rule21},-	{283, 1, &rule22},-	{284, 1, &rule21},-	{285, 1, &rule22},-	{286, 1, &rule21},-	{287, 1, &rule22},-	{288, 1, &rule21},-	{289, 1, &rule22},-	{290, 1, &rule21},-	{291, 1, &rule22},-	{292, 1, &rule21},-	{293, 1, &rule22},-	{294, 1, &rule21},-	{295, 1, &rule22},-	{296, 1, &rule21},-	{297, 1, &rule22},-	{298, 1, &rule21},-	{299, 1, &rule22},-	{300, 1, &rule21},-	{301, 1, &rule22},-	{302, 1, &rule21},-	{303, 1, &rule22},-	{304, 1, &rule23},-	{305, 1, &rule24},-	{306, 1, &rule21},-	{307, 1, &rule22},-	{308, 1, &rule21},-	{309, 1, &rule22},-	{310, 1, &rule21},-	{311, 1, &rule22},-	{312, 1, &rule14},-	{313, 1, &rule21},-	{314, 1, &rule22},-	{315, 1, &rule21},-	{316, 1, &rule22},-	{317, 1, &rule21},-	{318, 1, &rule22},-	{319, 1, &rule21},-	{320, 1, &rule22},-	{321, 1, &rule21},-	{322, 1, &rule22},-	{323, 1, &rule21},-	{324, 1, &rule22},-	{325, 1, &rule21},-	{326, 1, &rule22},-	{327, 1, &rule21},-	{328, 1, &rule22},-	{329, 1, &rule14},-	{330, 1, &rule21},-	{331, 1, &rule22},-	{332, 1, &rule21},-	{333, 1, &rule22},-	{334, 1, &rule21},-	{335, 1, &rule22},-	{336, 1, &rule21},-	{337, 1, &rule22},-	{338, 1, &rule21},-	{339, 1, &rule22},-	{340, 1, &rule21},-	{341, 1, &rule22},-	{342, 1, &rule21},-	{343, 1, &rule22},-	{344, 1, &rule21},-	{345, 1, &rule22},-	{346, 1, &rule21},-	{347, 1, &rule22},-	{348, 1, &rule21},-	{349, 1, &rule22},-	{350, 1, &rule21},-	{351, 1, &rule22},-	{352, 1, &rule21},-	{353, 1, &rule22},-	{354, 1, &rule21},-	{355, 1, &rule22},-	{356, 1, &rule21},-	{357, 1, &rule22},-	{358, 1, &rule21},-	{359, 1, &rule22},-	{360, 1, &rule21},-	{361, 1, &rule22},-	{362, 1, &rule21},-	{363, 1, &rule22},-	{364, 1, &rule21},-	{365, 1, &rule22},-	{366, 1, &rule21},-	{367, 1, &rule22},-	{368, 1, &rule21},-	{369, 1, &rule22},-	{370, 1, &rule21},-	{371, 1, &rule22},-	{372, 1, &rule21},-	{373, 1, &rule22},-	{374, 1, &rule21},-	{375, 1, &rule22},-	{376, 1, &rule25},-	{377, 1, &rule21},-	{378, 1, &rule22},-	{379, 1, &rule21},-	{380, 1, &rule22},-	{381, 1, &rule21},-	{382, 1, &rule22},-	{383, 1, &rule26},-	{384, 1, &rule27},-	{385, 1, &rule28},-	{386, 1, &rule21},-	{387, 1, &rule22},-	{388, 1, &rule21},-	{389, 1, &rule22},-	{390, 1, &rule29},-	{391, 1, &rule21},-	{392, 1, &rule22},-	{393, 2, &rule30},-	{395, 1, &rule21},-	{396, 1, &rule22},-	{397, 1, &rule14},-	{398, 1, &rule31},-	{399, 1, &rule32},-	{400, 1, &rule33},-	{401, 1, &rule21},-	{402, 1, &rule22},-	{403, 1, &rule30},-	{404, 1, &rule34},-	{405, 1, &rule35},-	{406, 1, &rule36},-	{407, 1, &rule37},-	{408, 1, &rule21},-	{409, 1, &rule22},-	{410, 1, &rule38},-	{411, 1, &rule14},-	{412, 1, &rule36},-	{413, 1, &rule39},-	{414, 1, &rule40},-	{415, 1, &rule41},-	{416, 1, &rule21},-	{417, 1, &rule22},-	{418, 1, &rule21},-	{419, 1, &rule22},-	{420, 1, &rule21},-	{421, 1, &rule22},-	{422, 1, &rule42},-	{423, 1, &rule21},-	{424, 1, &rule22},-	{425, 1, &rule42},-	{426, 2, &rule14},-	{428, 1, &rule21},-	{429, 1, &rule22},-	{430, 1, &rule42},-	{431, 1, &rule21},-	{432, 1, &rule22},-	{433, 2, &rule43},-	{435, 1, &rule21},-	{436, 1, &rule22},-	{437, 1, &rule21},-	{438, 1, &rule22},-	{439, 1, &rule44},-	{440, 1, &rule21},-	{441, 1, &rule22},-	{442, 1, &rule14},-	{443, 1, &rule45},-	{444, 1, &rule21},-	{445, 1, &rule22},-	{446, 1, &rule14},-	{447, 1, &rule46},-	{448, 4, &rule45},-	{452, 1, &rule47},-	{453, 1, &rule48},-	{454, 1, &rule49},-	{455, 1, &rule47},-	{456, 1, &rule48},-	{457, 1, &rule49},-	{458, 1, &rule47},-	{459, 1, &rule48},-	{460, 1, &rule49},-	{461, 1, &rule21},-	{462, 1, &rule22},-	{463, 1, &rule21},-	{464, 1, &rule22},-	{465, 1, &rule21},-	{466, 1, &rule22},-	{467, 1, &rule21},-	{468, 1, &rule22},-	{469, 1, &rule21},-	{470, 1, &rule22},-	{471, 1, &rule21},-	{472, 1, &rule22},-	{473, 1, &rule21},-	{474, 1, &rule22},-	{475, 1, &rule21},-	{476, 1, &rule22},-	{477, 1, &rule50},-	{478, 1, &rule21},-	{479, 1, &rule22},-	{480, 1, &rule21},-	{481, 1, &rule22},-	{482, 1, &rule21},-	{483, 1, &rule22},-	{484, 1, &rule21},-	{485, 1, &rule22},-	{486, 1, &rule21},-	{487, 1, &rule22},-	{488, 1, &rule21},-	{489, 1, &rule22},-	{490, 1, &rule21},-	{491, 1, &rule22},-	{492, 1, &rule21},-	{493, 1, &rule22},-	{494, 1, &rule21},-	{495, 1, &rule22},-	{496, 1, &rule14},-	{497, 1, &rule47},-	{498, 1, &rule48},-	{499, 1, &rule49},-	{500, 1, &rule21},-	{501, 1, &rule22},-	{502, 1, &rule51},-	{503, 1, &rule52},-	{504, 1, &rule21},-	{505, 1, &rule22},-	{506, 1, &rule21},-	{507, 1, &rule22},-	{508, 1, &rule21},-	{509, 1, &rule22},-	{510, 1, &rule21},-	{511, 1, &rule22},-	{512, 1, &rule21},-	{513, 1, &rule22},-	{514, 1, &rule21},-	{515, 1, &rule22},-	{516, 1, &rule21},-	{517, 1, &rule22},-	{518, 1, &rule21},-	{519, 1, &rule22},-	{520, 1, &rule21},-	{521, 1, &rule22},-	{522, 1, &rule21},-	{523, 1, &rule22},-	{524, 1, &rule21},-	{525, 1, &rule22},-	{526, 1, &rule21},-	{527, 1, &rule22},-	{528, 1, &rule21},-	{529, 1, &rule22},-	{530, 1, &rule21},-	{531, 1, &rule22},-	{532, 1, &rule21},-	{533, 1, &rule22},-	{534, 1, &rule21},-	{535, 1, &rule22},-	{536, 1, &rule21},-	{537, 1, &rule22},-	{538, 1, &rule21},-	{539, 1, &rule22},-	{540, 1, &rule21},-	{541, 1, &rule22},-	{542, 1, &rule21},-	{543, 1, &rule22},-	{544, 1, &rule53},-	{545, 1, &rule14},-	{546, 1, &rule21},-	{547, 1, &rule22},-	{548, 1, &rule21},-	{549, 1, &rule22},-	{550, 1, &rule21},-	{551, 1, &rule22},-	{552, 1, &rule21},-	{553, 1, &rule22},-	{554, 1, &rule21},-	{555, 1, &rule22},-	{556, 1, &rule21},-	{557, 1, &rule22},-	{558, 1, &rule21},-	{559, 1, &rule22},-	{560, 1, &rule21},-	{561, 1, &rule22},-	{562, 1, &rule21},-	{563, 1, &rule22},-	{564, 6, &rule14},-	{570, 1, &rule54},-	{571, 1, &rule21},-	{572, 1, &rule22},-	{573, 1, &rule55},-	{574, 1, &rule56},-	{575, 2, &rule57},-	{577, 1, &rule21},-	{578, 1, &rule22},-	{579, 1, &rule58},-	{580, 1, &rule59},-	{581, 1, &rule60},-	{582, 1, &rule21},-	{583, 1, &rule22},-	{584, 1, &rule21},-	{585, 1, &rule22},-	{586, 1, &rule21},-	{587, 1, &rule22},-	{588, 1, &rule21},-	{589, 1, &rule22},-	{590, 1, &rule21},-	{591, 1, &rule22},-	{592, 1, &rule61},-	{593, 1, &rule62},-	{594, 1, &rule63},-	{595, 1, &rule64},-	{596, 1, &rule65},-	{597, 1, &rule14},-	{598, 2, &rule66},-	{600, 1, &rule14},-	{601, 1, &rule67},-	{602, 1, &rule14},-	{603, 1, &rule68},-	{604, 4, &rule14},-	{608, 1, &rule66},-	{609, 2, &rule14},-	{611, 1, &rule69},-	{612, 1, &rule14},-	{613, 1, &rule70},-	{614, 2, &rule14},-	{616, 1, &rule71},-	{617, 1, &rule72},-	{618, 1, &rule14},-	{619, 1, &rule73},-	{620, 3, &rule14},-	{623, 1, &rule72},-	{624, 1, &rule14},-	{625, 1, &rule74},-	{626, 1, &rule75},-	{627, 2, &rule14},-	{629, 1, &rule76},-	{630, 7, &rule14},-	{637, 1, &rule77},-	{638, 2, &rule14},-	{640, 1, &rule78},-	{641, 2, &rule14},-	{643, 1, &rule78},-	{644, 4, &rule14},-	{648, 1, &rule78},-	{649, 1, &rule79},-	{650, 2, &rule80},-	{652, 1, &rule81},-	{653, 5, &rule14},-	{658, 1, &rule82},-	{659, 1, &rule14},-	{660, 1, &rule45},-	{661, 27, &rule14},-	{688, 18, &rule83},-	{706, 4, &rule10},-	{710, 12, &rule83},-	{722, 14, &rule10},-	{736, 5, &rule83},-	{741, 7, &rule10},-	{748, 1, &rule83},-	{749, 1, &rule10},-	{750, 1, &rule83},-	{751, 17, &rule10},-	{768, 69, &rule84},-	{837, 1, &rule85},-	{838, 42, &rule84},-	{880, 1, &rule21},-	{881, 1, &rule22},-	{882, 1, &rule21},-	{883, 1, &rule22},-	{884, 1, &rule83},-	{885, 1, &rule10},-	{886, 1, &rule21},-	{887, 1, &rule22},-	{890, 1, &rule83},-	{891, 3, &rule40},-	{894, 1, &rule2},-	{900, 2, &rule10},-	{902, 1, &rule86},-	{903, 1, &rule2},-	{904, 3, &rule87},-	{908, 1, &rule88},-	{910, 2, &rule89},-	{912, 1, &rule14},-	{913, 17, &rule9},-	{931, 9, &rule9},-	{940, 1, &rule90},-	{941, 3, &rule91},-	{944, 1, &rule14},-	{945, 17, &rule12},-	{962, 1, &rule92},-	{963, 9, &rule12},-	{972, 1, &rule93},-	{973, 2, &rule94},-	{975, 1, &rule95},-	{976, 1, &rule96},-	{977, 1, &rule97},-	{978, 3, &rule98},-	{981, 1, &rule99},-	{982, 1, &rule100},-	{983, 1, &rule101},-	{984, 1, &rule21},-	{985, 1, &rule22},-	{986, 1, &rule21},-	{987, 1, &rule22},-	{988, 1, &rule21},-	{989, 1, &rule22},-	{990, 1, &rule21},-	{991, 1, &rule22},-	{992, 1, &rule21},-	{993, 1, &rule22},-	{994, 1, &rule21},-	{995, 1, &rule22},-	{996, 1, &rule21},-	{997, 1, &rule22},-	{998, 1, &rule21},-	{999, 1, &rule22},-	{1000, 1, &rule21},-	{1001, 1, &rule22},-	{1002, 1, &rule21},-	{1003, 1, &rule22},-	{1004, 1, &rule21},-	{1005, 1, &rule22},-	{1006, 1, &rule21},-	{1007, 1, &rule22},-	{1008, 1, &rule102},-	{1009, 1, &rule103},-	{1010, 1, &rule104},-	{1011, 1, &rule14},-	{1012, 1, &rule105},-	{1013, 1, &rule106},-	{1014, 1, &rule6},-	{1015, 1, &rule21},-	{1016, 1, &rule22},-	{1017, 1, &rule107},-	{1018, 1, &rule21},-	{1019, 1, &rule22},-	{1020, 1, &rule14},-	{1021, 3, &rule53},-	{1024, 16, &rule108},-	{1040, 32, &rule9},-	{1072, 32, &rule12},-	{1104, 16, &rule103},-	{1120, 1, &rule21},-	{1121, 1, &rule22},-	{1122, 1, &rule21},-	{1123, 1, &rule22},-	{1124, 1, &rule21},-	{1125, 1, &rule22},-	{1126, 1, &rule21},-	{1127, 1, &rule22},-	{1128, 1, &rule21},-	{1129, 1, &rule22},-	{1130, 1, &rule21},-	{1131, 1, &rule22},-	{1132, 1, &rule21},-	{1133, 1, &rule22},-	{1134, 1, &rule21},-	{1135, 1, &rule22},-	{1136, 1, &rule21},-	{1137, 1, &rule22},-	{1138, 1, &rule21},-	{1139, 1, &rule22},-	{1140, 1, &rule21},-	{1141, 1, &rule22},-	{1142, 1, &rule21},-	{1143, 1, &rule22},-	{1144, 1, &rule21},-	{1145, 1, &rule22},-	{1146, 1, &rule21},-	{1147, 1, &rule22},-	{1148, 1, &rule21},-	{1149, 1, &rule22},-	{1150, 1, &rule21},-	{1151, 1, &rule22},-	{1152, 1, &rule21},-	{1153, 1, &rule22},-	{1154, 1, &rule13},-	{1155, 5, &rule84},-	{1160, 2, &rule109},-	{1162, 1, &rule21},-	{1163, 1, &rule22},-	{1164, 1, &rule21},-	{1165, 1, &rule22},-	{1166, 1, &rule21},-	{1167, 1, &rule22},-	{1168, 1, &rule21},-	{1169, 1, &rule22},-	{1170, 1, &rule21},-	{1171, 1, &rule22},-	{1172, 1, &rule21},-	{1173, 1, &rule22},-	{1174, 1, &rule21},-	{1175, 1, &rule22},-	{1176, 1, &rule21},-	{1177, 1, &rule22},-	{1178, 1, &rule21},-	{1179, 1, &rule22},-	{1180, 1, &rule21},-	{1181, 1, &rule22},-	{1182, 1, &rule21},-	{1183, 1, &rule22},-	{1184, 1, &rule21},-	{1185, 1, &rule22},-	{1186, 1, &rule21},-	{1187, 1, &rule22},-	{1188, 1, &rule21},-	{1189, 1, &rule22},-	{1190, 1, &rule21},-	{1191, 1, &rule22},-	{1192, 1, &rule21},-	{1193, 1, &rule22},-	{1194, 1, &rule21},-	{1195, 1, &rule22},-	{1196, 1, &rule21},-	{1197, 1, &rule22},-	{1198, 1, &rule21},-	{1199, 1, &rule22},-	{1200, 1, &rule21},-	{1201, 1, &rule22},-	{1202, 1, &rule21},-	{1203, 1, &rule22},-	{1204, 1, &rule21},-	{1205, 1, &rule22},-	{1206, 1, &rule21},-	{1207, 1, &rule22},-	{1208, 1, &rule21},-	{1209, 1, &rule22},-	{1210, 1, &rule21},-	{1211, 1, &rule22},-	{1212, 1, &rule21},-	{1213, 1, &rule22},-	{1214, 1, &rule21},-	{1215, 1, &rule22},-	{1216, 1, &rule110},-	{1217, 1, &rule21},-	{1218, 1, &rule22},-	{1219, 1, &rule21},-	{1220, 1, &rule22},-	{1221, 1, &rule21},-	{1222, 1, &rule22},-	{1223, 1, &rule21},-	{1224, 1, &rule22},-	{1225, 1, &rule21},-	{1226, 1, &rule22},-	{1227, 1, &rule21},-	{1228, 1, &rule22},-	{1229, 1, &rule21},-	{1230, 1, &rule22},-	{1231, 1, &rule111},-	{1232, 1, &rule21},-	{1233, 1, &rule22},-	{1234, 1, &rule21},-	{1235, 1, &rule22},-	{1236, 1, &rule21},-	{1237, 1, &rule22},-	{1238, 1, &rule21},-	{1239, 1, &rule22},-	{1240, 1, &rule21},-	{1241, 1, &rule22},-	{1242, 1, &rule21},-	{1243, 1, &rule22},-	{1244, 1, &rule21},-	{1245, 1, &rule22},-	{1246, 1, &rule21},-	{1247, 1, &rule22},-	{1248, 1, &rule21},-	{1249, 1, &rule22},-	{1250, 1, &rule21},-	{1251, 1, &rule22},-	{1252, 1, &rule21},-	{1253, 1, &rule22},-	{1254, 1, &rule21},-	{1255, 1, &rule22},-	{1256, 1, &rule21},-	{1257, 1, &rule22},-	{1258, 1, &rule21},-	{1259, 1, &rule22},-	{1260, 1, &rule21},-	{1261, 1, &rule22},-	{1262, 1, &rule21},-	{1263, 1, &rule22},-	{1264, 1, &rule21},-	{1265, 1, &rule22},-	{1266, 1, &rule21},-	{1267, 1, &rule22},-	{1268, 1, &rule21},-	{1269, 1, &rule22},-	{1270, 1, &rule21},-	{1271, 1, &rule22},-	{1272, 1, &rule21},-	{1273, 1, &rule22},-	{1274, 1, &rule21},-	{1275, 1, &rule22},-	{1276, 1, &rule21},-	{1277, 1, &rule22},-	{1278, 1, &rule21},-	{1279, 1, &rule22},-	{1280, 1, &rule21},-	{1281, 1, &rule22},-	{1282, 1, &rule21},-	{1283, 1, &rule22},-	{1284, 1, &rule21},-	{1285, 1, &rule22},-	{1286, 1, &rule21},-	{1287, 1, &rule22},-	{1288, 1, &rule21},-	{1289, 1, &rule22},-	{1290, 1, &rule21},-	{1291, 1, &rule22},-	{1292, 1, &rule21},-	{1293, 1, &rule22},-	{1294, 1, &rule21},-	{1295, 1, &rule22},-	{1296, 1, &rule21},-	{1297, 1, &rule22},-	{1298, 1, &rule21},-	{1299, 1, &rule22},-	{1300, 1, &rule21},-	{1301, 1, &rule22},-	{1302, 1, &rule21},-	{1303, 1, &rule22},-	{1304, 1, &rule21},-	{1305, 1, &rule22},-	{1306, 1, &rule21},-	{1307, 1, &rule22},-	{1308, 1, &rule21},-	{1309, 1, &rule22},-	{1310, 1, &rule21},-	{1311, 1, &rule22},-	{1312, 1, &rule21},-	{1313, 1, &rule22},-	{1314, 1, &rule21},-	{1315, 1, &rule22},-	{1316, 1, &rule21},-	{1317, 1, &rule22},-	{1318, 1, &rule21},-	{1319, 1, &rule22},-	{1329, 38, &rule112},-	{1369, 1, &rule83},-	{1370, 6, &rule2},-	{1377, 38, &rule113},-	{1415, 1, &rule14},-	{1417, 1, &rule2},-	{1418, 1, &rule7},-	{1425, 45, &rule84},-	{1470, 1, &rule7},-	{1471, 1, &rule84},-	{1472, 1, &rule2},-	{1473, 2, &rule84},-	{1475, 1, &rule2},-	{1476, 2, &rule84},-	{1478, 1, &rule2},-	{1479, 1, &rule84},-	{1488, 27, &rule45},-	{1520, 3, &rule45},-	{1523, 2, &rule2},-	{1536, 4, &rule16},-	{1542, 3, &rule6},-	{1545, 2, &rule2},-	{1547, 1, &rule3},-	{1548, 2, &rule2},-	{1550, 2, &rule13},-	{1552, 11, &rule84},-	{1563, 1, &rule2},-	{1566, 2, &rule2},-	{1568, 32, &rule45},-	{1600, 1, &rule83},-	{1601, 10, &rule45},-	{1611, 21, &rule84},-	{1632, 10, &rule8},-	{1642, 4, &rule2},-	{1646, 2, &rule45},-	{1648, 1, &rule84},-	{1649, 99, &rule45},-	{1748, 1, &rule2},-	{1749, 1, &rule45},-	{1750, 7, &rule84},-	{1757, 1, &rule16},-	{1758, 1, &rule13},-	{1759, 6, &rule84},-	{1765, 2, &rule83},-	{1767, 2, &rule84},-	{1769, 1, &rule13},-	{1770, 4, &rule84},-	{1774, 2, &rule45},-	{1776, 10, &rule8},-	{1786, 3, &rule45},-	{1789, 2, &rule13},-	{1791, 1, &rule45},-	{1792, 14, &rule2},-	{1807, 1, &rule16},-	{1808, 1, &rule45},-	{1809, 1, &rule84},-	{1810, 30, &rule45},-	{1840, 27, &rule84},-	{1869, 89, &rule45},-	{1958, 11, &rule84},-	{1969, 1, &rule45},-	{1984, 10, &rule8},-	{1994, 33, &rule45},-	{2027, 9, &rule84},-	{2036, 2, &rule83},-	{2038, 1, &rule13},-	{2039, 3, &rule2},-	{2042, 1, &rule83},-	{2048, 22, &rule45},-	{2070, 4, &rule84},-	{2074, 1, &rule83},-	{2075, 9, &rule84},-	{2084, 1, &rule83},-	{2085, 3, &rule84},-	{2088, 1, &rule83},-	{2089, 5, &rule84},-	{2096, 15, &rule2},-	{2112, 25, &rule45},-	{2137, 3, &rule84},-	{2142, 1, &rule2},-	{2304, 3, &rule84},-	{2307, 1, &rule114},-	{2308, 54, &rule45},-	{2362, 1, &rule84},-	{2363, 1, &rule114},-	{2364, 1, &rule84},-	{2365, 1, &rule45},-	{2366, 3, &rule114},-	{2369, 8, &rule84},-	{2377, 4, &rule114},-	{2381, 1, &rule84},-	{2382, 2, &rule114},-	{2384, 1, &rule45},-	{2385, 7, &rule84},-	{2392, 10, &rule45},-	{2402, 2, &rule84},-	{2404, 2, &rule2},-	{2406, 10, &rule8},-	{2416, 1, &rule2},-	{2417, 1, &rule83},-	{2418, 6, &rule45},-	{2425, 7, &rule45},-	{2433, 1, &rule84},-	{2434, 2, &rule114},-	{2437, 8, &rule45},-	{2447, 2, &rule45},-	{2451, 22, &rule45},-	{2474, 7, &rule45},-	{2482, 1, &rule45},-	{2486, 4, &rule45},-	{2492, 1, &rule84},-	{2493, 1, &rule45},-	{2494, 3, &rule114},-	{2497, 4, &rule84},-	{2503, 2, &rule114},-	{2507, 2, &rule114},-	{2509, 1, &rule84},-	{2510, 1, &rule45},-	{2519, 1, &rule114},-	{2524, 2, &rule45},-	{2527, 3, &rule45},-	{2530, 2, &rule84},-	{2534, 10, &rule8},-	{2544, 2, &rule45},-	{2546, 2, &rule3},-	{2548, 6, &rule17},-	{2554, 1, &rule13},-	{2555, 1, &rule3},-	{2561, 2, &rule84},-	{2563, 1, &rule114},-	{2565, 6, &rule45},-	{2575, 2, &rule45},-	{2579, 22, &rule45},-	{2602, 7, &rule45},-	{2610, 2, &rule45},-	{2613, 2, &rule45},-	{2616, 2, &rule45},-	{2620, 1, &rule84},-	{2622, 3, &rule114},-	{2625, 2, &rule84},-	{2631, 2, &rule84},-	{2635, 3, &rule84},-	{2641, 1, &rule84},-	{2649, 4, &rule45},-	{2654, 1, &rule45},-	{2662, 10, &rule8},-	{2672, 2, &rule84},-	{2674, 3, &rule45},-	{2677, 1, &rule84},-	{2689, 2, &rule84},-	{2691, 1, &rule114},-	{2693, 9, &rule45},-	{2703, 3, &rule45},-	{2707, 22, &rule45},-	{2730, 7, &rule45},-	{2738, 2, &rule45},-	{2741, 5, &rule45},-	{2748, 1, &rule84},-	{2749, 1, &rule45},-	{2750, 3, &rule114},-	{2753, 5, &rule84},-	{2759, 2, &rule84},-	{2761, 1, &rule114},-	{2763, 2, &rule114},-	{2765, 1, &rule84},-	{2768, 1, &rule45},-	{2784, 2, &rule45},-	{2786, 2, &rule84},-	{2790, 10, &rule8},-	{2801, 1, &rule3},-	{2817, 1, &rule84},-	{2818, 2, &rule114},-	{2821, 8, &rule45},-	{2831, 2, &rule45},-	{2835, 22, &rule45},-	{2858, 7, &rule45},-	{2866, 2, &rule45},-	{2869, 5, &rule45},-	{2876, 1, &rule84},-	{2877, 1, &rule45},-	{2878, 1, &rule114},-	{2879, 1, &rule84},-	{2880, 1, &rule114},-	{2881, 4, &rule84},-	{2887, 2, &rule114},-	{2891, 2, &rule114},-	{2893, 1, &rule84},-	{2902, 1, &rule84},-	{2903, 1, &rule114},-	{2908, 2, &rule45},-	{2911, 3, &rule45},-	{2914, 2, &rule84},-	{2918, 10, &rule8},-	{2928, 1, &rule13},-	{2929, 1, &rule45},-	{2930, 6, &rule17},-	{2946, 1, &rule84},-	{2947, 1, &rule45},-	{2949, 6, &rule45},-	{2958, 3, &rule45},-	{2962, 4, &rule45},-	{2969, 2, &rule45},-	{2972, 1, &rule45},-	{2974, 2, &rule45},-	{2979, 2, &rule45},-	{2984, 3, &rule45},-	{2990, 12, &rule45},-	{3006, 2, &rule114},-	{3008, 1, &rule84},-	{3009, 2, &rule114},-	{3014, 3, &rule114},-	{3018, 3, &rule114},-	{3021, 1, &rule84},-	{3024, 1, &rule45},-	{3031, 1, &rule114},-	{3046, 10, &rule8},-	{3056, 3, &rule17},-	{3059, 6, &rule13},-	{3065, 1, &rule3},-	{3066, 1, &rule13},-	{3073, 3, &rule114},-	{3077, 8, &rule45},-	{3086, 3, &rule45},-	{3090, 23, &rule45},-	{3114, 10, &rule45},-	{3125, 5, &rule45},-	{3133, 1, &rule45},-	{3134, 3, &rule84},-	{3137, 4, &rule114},-	{3142, 3, &rule84},-	{3146, 4, &rule84},-	{3157, 2, &rule84},-	{3160, 2, &rule45},-	{3168, 2, &rule45},-	{3170, 2, &rule84},-	{3174, 10, &rule8},-	{3192, 7, &rule17},-	{3199, 1, &rule13},-	{3202, 2, &rule114},-	{3205, 8, &rule45},-	{3214, 3, &rule45},-	{3218, 23, &rule45},-	{3242, 10, &rule45},-	{3253, 5, &rule45},-	{3260, 1, &rule84},-	{3261, 1, &rule45},-	{3262, 1, &rule114},-	{3263, 1, &rule84},-	{3264, 5, &rule114},-	{3270, 1, &rule84},-	{3271, 2, &rule114},-	{3274, 2, &rule114},-	{3276, 2, &rule84},-	{3285, 2, &rule114},-	{3294, 1, &rule45},-	{3296, 2, &rule45},-	{3298, 2, &rule84},-	{3302, 10, &rule8},-	{3313, 2, &rule45},-	{3330, 2, &rule114},-	{3333, 8, &rule45},-	{3342, 3, &rule45},-	{3346, 41, &rule45},-	{3389, 1, &rule45},-	{3390, 3, &rule114},-	{3393, 4, &rule84},-	{3398, 3, &rule114},-	{3402, 3, &rule114},-	{3405, 1, &rule84},-	{3406, 1, &rule45},-	{3415, 1, &rule114},-	{3424, 2, &rule45},-	{3426, 2, &rule84},-	{3430, 10, &rule8},-	{3440, 6, &rule17},-	{3449, 1, &rule13},-	{3450, 6, &rule45},-	{3458, 2, &rule114},-	{3461, 18, &rule45},-	{3482, 24, &rule45},-	{3507, 9, &rule45},-	{3517, 1, &rule45},-	{3520, 7, &rule45},-	{3530, 1, &rule84},-	{3535, 3, &rule114},-	{3538, 3, &rule84},-	{3542, 1, &rule84},-	{3544, 8, &rule114},-	{3570, 2, &rule114},-	{3572, 1, &rule2},-	{3585, 48, &rule45},-	{3633, 1, &rule84},-	{3634, 2, &rule45},-	{3636, 7, &rule84},-	{3647, 1, &rule3},-	{3648, 6, &rule45},-	{3654, 1, &rule83},-	{3655, 8, &rule84},-	{3663, 1, &rule2},-	{3664, 10, &rule8},-	{3674, 2, &rule2},-	{3713, 2, &rule45},-	{3716, 1, &rule45},-	{3719, 2, &rule45},-	{3722, 1, &rule45},-	{3725, 1, &rule45},-	{3732, 4, &rule45},-	{3737, 7, &rule45},-	{3745, 3, &rule45},-	{3749, 1, &rule45},-	{3751, 1, &rule45},-	{3754, 2, &rule45},-	{3757, 4, &rule45},-	{3761, 1, &rule84},-	{3762, 2, &rule45},-	{3764, 6, &rule84},-	{3771, 2, &rule84},-	{3773, 1, &rule45},-	{3776, 5, &rule45},-	{3782, 1, &rule83},-	{3784, 6, &rule84},-	{3792, 10, &rule8},-	{3804, 2, &rule45},-	{3840, 1, &rule45},-	{3841, 3, &rule13},-	{3844, 15, &rule2},-	{3859, 5, &rule13},-	{3864, 2, &rule84},-	{3866, 6, &rule13},-	{3872, 10, &rule8},-	{3882, 10, &rule17},-	{3892, 1, &rule13},-	{3893, 1, &rule84},-	{3894, 1, &rule13},-	{3895, 1, &rule84},-	{3896, 1, &rule13},-	{3897, 1, &rule84},-	{3898, 1, &rule4},-	{3899, 1, &rule5},-	{3900, 1, &rule4},-	{3901, 1, &rule5},-	{3902, 2, &rule114},-	{3904, 8, &rule45},-	{3913, 36, &rule45},-	{3953, 14, &rule84},-	{3967, 1, &rule114},-	{3968, 5, &rule84},-	{3973, 1, &rule2},-	{3974, 2, &rule84},-	{3976, 5, &rule45},-	{3981, 11, &rule84},-	{3993, 36, &rule84},-	{4030, 8, &rule13},-	{4038, 1, &rule84},-	{4039, 6, &rule13},-	{4046, 2, &rule13},-	{4048, 5, &rule2},-	{4053, 4, &rule13},-	{4057, 2, &rule2},-	{4096, 43, &rule45},-	{4139, 2, &rule114},-	{4141, 4, &rule84},-	{4145, 1, &rule114},-	{4146, 6, &rule84},-	{4152, 1, &rule114},-	{4153, 2, &rule84},-	{4155, 2, &rule114},-	{4157, 2, &rule84},-	{4159, 1, &rule45},-	{4160, 10, &rule8},-	{4170, 6, &rule2},-	{4176, 6, &rule45},-	{4182, 2, &rule114},-	{4184, 2, &rule84},-	{4186, 4, &rule45},-	{4190, 3, &rule84},-	{4193, 1, &rule45},-	{4194, 3, &rule114},-	{4197, 2, &rule45},-	{4199, 7, &rule114},-	{4206, 3, &rule45},-	{4209, 4, &rule84},-	{4213, 13, &rule45},-	{4226, 1, &rule84},-	{4227, 2, &rule114},-	{4229, 2, &rule84},-	{4231, 6, &rule114},-	{4237, 1, &rule84},-	{4238, 1, &rule45},-	{4239, 1, &rule114},-	{4240, 10, &rule8},-	{4250, 3, &rule114},-	{4253, 1, &rule84},-	{4254, 2, &rule13},-	{4256, 38, &rule115},-	{4304, 43, &rule45},-	{4347, 1, &rule2},-	{4348, 1, &rule83},-	{4352, 329, &rule45},-	{4682, 4, &rule45},-	{4688, 7, &rule45},-	{4696, 1, &rule45},-	{4698, 4, &rule45},-	{4704, 41, &rule45},-	{4746, 4, &rule45},-	{4752, 33, &rule45},-	{4786, 4, &rule45},-	{4792, 7, &rule45},-	{4800, 1, &rule45},-	{4802, 4, &rule45},-	{4808, 15, &rule45},-	{4824, 57, &rule45},-	{4882, 4, &rule45},-	{4888, 67, &rule45},-	{4957, 3, &rule84},-	{4960, 1, &rule13},-	{4961, 8, &rule2},-	{4969, 20, &rule17},-	{4992, 16, &rule45},-	{5008, 10, &rule13},-	{5024, 85, &rule45},-	{5120, 1, &rule7},-	{5121, 620, &rule45},-	{5741, 2, &rule2},-	{5743, 17, &rule45},-	{5760, 1, &rule1},-	{5761, 26, &rule45},-	{5787, 1, &rule4},-	{5788, 1, &rule5},-	{5792, 75, &rule45},-	{5867, 3, &rule2},-	{5870, 3, &rule116},-	{5888, 13, &rule45},-	{5902, 4, &rule45},-	{5906, 3, &rule84},-	{5920, 18, &rule45},-	{5938, 3, &rule84},-	{5941, 2, &rule2},-	{5952, 18, &rule45},-	{5970, 2, &rule84},-	{5984, 13, &rule45},-	{5998, 3, &rule45},-	{6002, 2, &rule84},-	{6016, 52, &rule45},-	{6068, 2, &rule16},-	{6070, 1, &rule114},-	{6071, 7, &rule84},-	{6078, 8, &rule114},-	{6086, 1, &rule84},-	{6087, 2, &rule114},-	{6089, 11, &rule84},-	{6100, 3, &rule2},-	{6103, 1, &rule83},-	{6104, 3, &rule2},-	{6107, 1, &rule3},-	{6108, 1, &rule45},-	{6109, 1, &rule84},-	{6112, 10, &rule8},-	{6128, 10, &rule17},-	{6144, 6, &rule2},-	{6150, 1, &rule7},-	{6151, 4, &rule2},-	{6155, 3, &rule84},-	{6158, 1, &rule1},-	{6160, 10, &rule8},-	{6176, 35, &rule45},-	{6211, 1, &rule83},-	{6212, 52, &rule45},-	{6272, 41, &rule45},-	{6313, 1, &rule84},-	{6314, 1, &rule45},-	{6320, 70, &rule45},-	{6400, 29, &rule45},-	{6432, 3, &rule84},-	{6435, 4, &rule114},-	{6439, 2, &rule84},-	{6441, 3, &rule114},-	{6448, 2, &rule114},-	{6450, 1, &rule84},-	{6451, 6, &rule114},-	{6457, 3, &rule84},-	{6464, 1, &rule13},-	{6468, 2, &rule2},-	{6470, 10, &rule8},-	{6480, 30, &rule45},-	{6512, 5, &rule45},-	{6528, 44, &rule45},-	{6576, 17, &rule114},-	{6593, 7, &rule45},-	{6600, 2, &rule114},-	{6608, 10, &rule8},-	{6618, 1, &rule17},-	{6622, 34, &rule13},-	{6656, 23, &rule45},-	{6679, 2, &rule84},-	{6681, 3, &rule114},-	{6686, 2, &rule2},-	{6688, 53, &rule45},-	{6741, 1, &rule114},-	{6742, 1, &rule84},-	{6743, 1, &rule114},-	{6744, 7, &rule84},-	{6752, 1, &rule84},-	{6753, 1, &rule114},-	{6754, 1, &rule84},-	{6755, 2, &rule114},-	{6757, 8, &rule84},-	{6765, 6, &rule114},-	{6771, 10, &rule84},-	{6783, 1, &rule84},-	{6784, 10, &rule8},-	{6800, 10, &rule8},-	{6816, 7, &rule2},-	{6823, 1, &rule83},-	{6824, 6, &rule2},-	{6912, 4, &rule84},-	{6916, 1, &rule114},-	{6917, 47, &rule45},-	{6964, 1, &rule84},-	{6965, 1, &rule114},-	{6966, 5, &rule84},-	{6971, 1, &rule114},-	{6972, 1, &rule84},-	{6973, 5, &rule114},-	{6978, 1, &rule84},-	{6979, 2, &rule114},-	{6981, 7, &rule45},-	{6992, 10, &rule8},-	{7002, 7, &rule2},-	{7009, 10, &rule13},-	{7019, 9, &rule84},-	{7028, 9, &rule13},-	{7040, 2, &rule84},-	{7042, 1, &rule114},-	{7043, 30, &rule45},-	{7073, 1, &rule114},-	{7074, 4, &rule84},-	{7078, 2, &rule114},-	{7080, 2, &rule84},-	{7082, 1, &rule114},-	{7086, 2, &rule45},-	{7088, 10, &rule8},-	{7104, 38, &rule45},-	{7142, 1, &rule84},-	{7143, 1, &rule114},-	{7144, 2, &rule84},-	{7146, 3, &rule114},-	{7149, 1, &rule84},-	{7150, 1, &rule114},-	{7151, 3, &rule84},-	{7154, 2, &rule114},-	{7164, 4, &rule2},-	{7168, 36, &rule45},-	{7204, 8, &rule114},-	{7212, 8, &rule84},-	{7220, 2, &rule114},-	{7222, 2, &rule84},-	{7227, 5, &rule2},-	{7232, 10, &rule8},-	{7245, 3, &rule45},-	{7248, 10, &rule8},-	{7258, 30, &rule45},-	{7288, 6, &rule83},-	{7294, 2, &rule2},-	{7376, 3, &rule84},-	{7379, 1, &rule2},-	{7380, 13, &rule84},-	{7393, 1, &rule114},-	{7394, 7, &rule84},-	{7401, 4, &rule45},-	{7405, 1, &rule84},-	{7406, 4, &rule45},-	{7410, 1, &rule114},-	{7424, 44, &rule14},-	{7468, 54, &rule83},-	{7522, 22, &rule14},-	{7544, 1, &rule83},-	{7545, 1, &rule117},-	{7546, 3, &rule14},-	{7549, 1, &rule118},-	{7550, 29, &rule14},-	{7579, 37, &rule83},-	{7616, 39, &rule84},-	{7676, 4, &rule84},-	{7680, 1, &rule21},-	{7681, 1, &rule22},-	{7682, 1, &rule21},-	{7683, 1, &rule22},-	{7684, 1, &rule21},-	{7685, 1, &rule22},-	{7686, 1, &rule21},-	{7687, 1, &rule22},-	{7688, 1, &rule21},-	{7689, 1, &rule22},-	{7690, 1, &rule21},-	{7691, 1, &rule22},-	{7692, 1, &rule21},-	{7693, 1, &rule22},-	{7694, 1, &rule21},-	{7695, 1, &rule22},-	{7696, 1, &rule21},-	{7697, 1, &rule22},-	{7698, 1, &rule21},-	{7699, 1, &rule22},-	{7700, 1, &rule21},-	{7701, 1, &rule22},-	{7702, 1, &rule21},-	{7703, 1, &rule22},-	{7704, 1, &rule21},-	{7705, 1, &rule22},-	{7706, 1, &rule21},-	{7707, 1, &rule22},-	{7708, 1, &rule21},-	{7709, 1, &rule22},-	{7710, 1, &rule21},-	{7711, 1, &rule22},-	{7712, 1, &rule21},-	{7713, 1, &rule22},-	{7714, 1, &rule21},-	{7715, 1, &rule22},-	{7716, 1, &rule21},-	{7717, 1, &rule22},-	{7718, 1, &rule21},-	{7719, 1, &rule22},-	{7720, 1, &rule21},-	{7721, 1, &rule22},-	{7722, 1, &rule21},-	{7723, 1, &rule22},-	{7724, 1, &rule21},-	{7725, 1, &rule22},-	{7726, 1, &rule21},-	{7727, 1, &rule22},-	{7728, 1, &rule21},-	{7729, 1, &rule22},-	{7730, 1, &rule21},-	{7731, 1, &rule22},-	{7732, 1, &rule21},-	{7733, 1, &rule22},-	{7734, 1, &rule21},-	{7735, 1, &rule22},-	{7736, 1, &rule21},-	{7737, 1, &rule22},-	{7738, 1, &rule21},-	{7739, 1, &rule22},-	{7740, 1, &rule21},-	{7741, 1, &rule22},-	{7742, 1, &rule21},-	{7743, 1, &rule22},-	{7744, 1, &rule21},-	{7745, 1, &rule22},-	{7746, 1, &rule21},-	{7747, 1, &rule22},-	{7748, 1, &rule21},-	{7749, 1, &rule22},-	{7750, 1, &rule21},-	{7751, 1, &rule22},-	{7752, 1, &rule21},-	{7753, 1, &rule22},-	{7754, 1, &rule21},-	{7755, 1, &rule22},-	{7756, 1, &rule21},-	{7757, 1, &rule22},-	{7758, 1, &rule21},-	{7759, 1, &rule22},-	{7760, 1, &rule21},-	{7761, 1, &rule22},-	{7762, 1, &rule21},-	{7763, 1, &rule22},-	{7764, 1, &rule21},-	{7765, 1, &rule22},-	{7766, 1, &rule21},-	{7767, 1, &rule22},-	{7768, 1, &rule21},-	{7769, 1, &rule22},-	{7770, 1, &rule21},-	{7771, 1, &rule22},-	{7772, 1, &rule21},-	{7773, 1, &rule22},-	{7774, 1, &rule21},-	{7775, 1, &rule22},-	{7776, 1, &rule21},-	{7777, 1, &rule22},-	{7778, 1, &rule21},-	{7779, 1, &rule22},-	{7780, 1, &rule21},-	{7781, 1, &rule22},-	{7782, 1, &rule21},-	{7783, 1, &rule22},-	{7784, 1, &rule21},-	{7785, 1, &rule22},-	{7786, 1, &rule21},-	{7787, 1, &rule22},-	{7788, 1, &rule21},-	{7789, 1, &rule22},-	{7790, 1, &rule21},-	{7791, 1, &rule22},-	{7792, 1, &rule21},-	{7793, 1, &rule22},-	{7794, 1, &rule21},-	{7795, 1, &rule22},-	{7796, 1, &rule21},-	{7797, 1, &rule22},-	{7798, 1, &rule21},-	{7799, 1, &rule22},-	{7800, 1, &rule21},-	{7801, 1, &rule22},-	{7802, 1, &rule21},-	{7803, 1, &rule22},-	{7804, 1, &rule21},-	{7805, 1, &rule22},-	{7806, 1, &rule21},-	{7807, 1, &rule22},-	{7808, 1, &rule21},-	{7809, 1, &rule22},-	{7810, 1, &rule21},-	{7811, 1, &rule22},-	{7812, 1, &rule21},-	{7813, 1, &rule22},-	{7814, 1, &rule21},-	{7815, 1, &rule22},-	{7816, 1, &rule21},-	{7817, 1, &rule22},-	{7818, 1, &rule21},-	{7819, 1, &rule22},-	{7820, 1, &rule21},-	{7821, 1, &rule22},-	{7822, 1, &rule21},-	{7823, 1, &rule22},-	{7824, 1, &rule21},-	{7825, 1, &rule22},-	{7826, 1, &rule21},-	{7827, 1, &rule22},-	{7828, 1, &rule21},-	{7829, 1, &rule22},-	{7830, 5, &rule14},-	{7835, 1, &rule119},-	{7836, 2, &rule14},-	{7838, 1, &rule120},-	{7839, 1, &rule14},-	{7840, 1, &rule21},-	{7841, 1, &rule22},-	{7842, 1, &rule21},-	{7843, 1, &rule22},-	{7844, 1, &rule21},-	{7845, 1, &rule22},-	{7846, 1, &rule21},-	{7847, 1, &rule22},-	{7848, 1, &rule21},-	{7849, 1, &rule22},-	{7850, 1, &rule21},-	{7851, 1, &rule22},-	{7852, 1, &rule21},-	{7853, 1, &rule22},-	{7854, 1, &rule21},-	{7855, 1, &rule22},-	{7856, 1, &rule21},-	{7857, 1, &rule22},-	{7858, 1, &rule21},-	{7859, 1, &rule22},-	{7860, 1, &rule21},-	{7861, 1, &rule22},-	{7862, 1, &rule21},-	{7863, 1, &rule22},-	{7864, 1, &rule21},-	{7865, 1, &rule22},-	{7866, 1, &rule21},-	{7867, 1, &rule22},-	{7868, 1, &rule21},-	{7869, 1, &rule22},-	{7870, 1, &rule21},-	{7871, 1, &rule22},-	{7872, 1, &rule21},-	{7873, 1, &rule22},-	{7874, 1, &rule21},-	{7875, 1, &rule22},-	{7876, 1, &rule21},-	{7877, 1, &rule22},-	{7878, 1, &rule21},-	{7879, 1, &rule22},-	{7880, 1, &rule21},-	{7881, 1, &rule22},-	{7882, 1, &rule21},-	{7883, 1, &rule22},-	{7884, 1, &rule21},-	{7885, 1, &rule22},-	{7886, 1, &rule21},-	{7887, 1, &rule22},-	{7888, 1, &rule21},-	{7889, 1, &rule22},-	{7890, 1, &rule21},-	{7891, 1, &rule22},-	{7892, 1, &rule21},-	{7893, 1, &rule22},-	{7894, 1, &rule21},-	{7895, 1, &rule22},-	{7896, 1, &rule21},-	{7897, 1, &rule22},-	{7898, 1, &rule21},-	{7899, 1, &rule22},-	{7900, 1, &rule21},-	{7901, 1, &rule22},-	{7902, 1, &rule21},-	{7903, 1, &rule22},-	{7904, 1, &rule21},-	{7905, 1, &rule22},-	{7906, 1, &rule21},-	{7907, 1, &rule22},-	{7908, 1, &rule21},-	{7909, 1, &rule22},-	{7910, 1, &rule21},-	{7911, 1, &rule22},-	{7912, 1, &rule21},-	{7913, 1, &rule22},-	{7914, 1, &rule21},-	{7915, 1, &rule22},-	{7916, 1, &rule21},-	{7917, 1, &rule22},-	{7918, 1, &rule21},-	{7919, 1, &rule22},-	{7920, 1, &rule21},-	{7921, 1, &rule22},-	{7922, 1, &rule21},-	{7923, 1, &rule22},-	{7924, 1, &rule21},-	{7925, 1, &rule22},-	{7926, 1, &rule21},-	{7927, 1, &rule22},-	{7928, 1, &rule21},-	{7929, 1, &rule22},-	{7930, 1, &rule21},-	{7931, 1, &rule22},-	{7932, 1, &rule21},-	{7933, 1, &rule22},-	{7934, 1, &rule21},-	{7935, 1, &rule22},-	{7936, 8, &rule121},-	{7944, 8, &rule122},-	{7952, 6, &rule121},-	{7960, 6, &rule122},-	{7968, 8, &rule121},-	{7976, 8, &rule122},-	{7984, 8, &rule121},-	{7992, 8, &rule122},-	{8000, 6, &rule121},-	{8008, 6, &rule122},-	{8016, 1, &rule14},-	{8017, 1, &rule121},-	{8018, 1, &rule14},-	{8019, 1, &rule121},-	{8020, 1, &rule14},-	{8021, 1, &rule121},-	{8022, 1, &rule14},-	{8023, 1, &rule121},-	{8025, 1, &rule122},-	{8027, 1, &rule122},-	{8029, 1, &rule122},-	{8031, 1, &rule122},-	{8032, 8, &rule121},-	{8040, 8, &rule122},-	{8048, 2, &rule123},-	{8050, 4, &rule124},-	{8054, 2, &rule125},-	{8056, 2, &rule126},-	{8058, 2, &rule127},-	{8060, 2, &rule128},-	{8064, 8, &rule121},-	{8072, 8, &rule129},-	{8080, 8, &rule121},-	{8088, 8, &rule129},-	{8096, 8, &rule121},-	{8104, 8, &rule129},-	{8112, 2, &rule121},-	{8114, 1, &rule14},-	{8115, 1, &rule130},-	{8116, 1, &rule14},-	{8118, 2, &rule14},-	{8120, 2, &rule122},-	{8122, 2, &rule131},-	{8124, 1, &rule132},-	{8125, 1, &rule10},-	{8126, 1, &rule133},-	{8127, 3, &rule10},-	{8130, 1, &rule14},-	{8131, 1, &rule130},-	{8132, 1, &rule14},-	{8134, 2, &rule14},-	{8136, 4, &rule134},-	{8140, 1, &rule132},-	{8141, 3, &rule10},-	{8144, 2, &rule121},-	{8146, 2, &rule14},-	{8150, 2, &rule14},-	{8152, 2, &rule122},-	{8154, 2, &rule135},-	{8157, 3, &rule10},-	{8160, 2, &rule121},-	{8162, 3, &rule14},-	{8165, 1, &rule104},-	{8166, 2, &rule14},-	{8168, 2, &rule122},-	{8170, 2, &rule136},-	{8172, 1, &rule107},-	{8173, 3, &rule10},-	{8178, 1, &rule14},-	{8179, 1, &rule130},-	{8180, 1, &rule14},-	{8182, 2, &rule14},-	{8184, 2, &rule137},-	{8186, 2, &rule138},-	{8188, 1, &rule132},-	{8189, 2, &rule10},-	{8192, 11, &rule1},-	{8203, 5, &rule16},-	{8208, 6, &rule7},-	{8214, 2, &rule2},-	{8216, 1, &rule15},-	{8217, 1, &rule19},-	{8218, 1, &rule4},-	{8219, 2, &rule15},-	{8221, 1, &rule19},-	{8222, 1, &rule4},-	{8223, 1, &rule15},-	{8224, 8, &rule2},-	{8232, 1, &rule139},-	{8233, 1, &rule140},-	{8234, 5, &rule16},-	{8239, 1, &rule1},-	{8240, 9, &rule2},-	{8249, 1, &rule15},-	{8250, 1, &rule19},-	{8251, 4, &rule2},-	{8255, 2, &rule11},-	{8257, 3, &rule2},-	{8260, 1, &rule6},-	{8261, 1, &rule4},-	{8262, 1, &rule5},-	{8263, 11, &rule2},-	{8274, 1, &rule6},-	{8275, 1, &rule2},-	{8276, 1, &rule11},-	{8277, 10, &rule2},-	{8287, 1, &rule1},-	{8288, 5, &rule16},-	{8298, 6, &rule16},-	{8304, 1, &rule17},-	{8305, 1, &rule83},-	{8308, 6, &rule17},-	{8314, 3, &rule6},-	{8317, 1, &rule4},-	{8318, 1, &rule5},-	{8319, 1, &rule83},-	{8320, 10, &rule17},-	{8330, 3, &rule6},-	{8333, 1, &rule4},-	{8334, 1, &rule5},-	{8336, 13, &rule83},-	{8352, 26, &rule3},-	{8400, 13, &rule84},-	{8413, 4, &rule109},-	{8417, 1, &rule84},-	{8418, 3, &rule109},-	{8421, 12, &rule84},-	{8448, 2, &rule13},-	{8450, 1, &rule98},-	{8451, 4, &rule13},-	{8455, 1, &rule98},-	{8456, 2, &rule13},-	{8458, 1, &rule14},-	{8459, 3, &rule98},-	{8462, 2, &rule14},-	{8464, 3, &rule98},-	{8467, 1, &rule14},-	{8468, 1, &rule13},-	{8469, 1, &rule98},-	{8470, 2, &rule13},-	{8472, 1, &rule6},-	{8473, 5, &rule98},-	{8478, 6, &rule13},-	{8484, 1, &rule98},-	{8485, 1, &rule13},-	{8486, 1, &rule141},-	{8487, 1, &rule13},-	{8488, 1, &rule98},-	{8489, 1, &rule13},-	{8490, 1, &rule142},-	{8491, 1, &rule143},-	{8492, 2, &rule98},-	{8494, 1, &rule13},-	{8495, 1, &rule14},-	{8496, 2, &rule98},-	{8498, 1, &rule144},-	{8499, 1, &rule98},-	{8500, 1, &rule14},-	{8501, 4, &rule45},-	{8505, 1, &rule14},-	{8506, 2, &rule13},-	{8508, 2, &rule14},-	{8510, 2, &rule98},-	{8512, 5, &rule6},-	{8517, 1, &rule98},-	{8518, 4, &rule14},-	{8522, 1, &rule13},-	{8523, 1, &rule6},-	{8524, 2, &rule13},-	{8526, 1, &rule145},-	{8527, 1, &rule13},-	{8528, 16, &rule17},-	{8544, 16, &rule146},-	{8560, 16, &rule147},-	{8576, 3, &rule116},-	{8579, 1, &rule21},-	{8580, 1, &rule22},-	{8581, 4, &rule116},-	{8585, 1, &rule17},-	{8592, 5, &rule6},-	{8597, 5, &rule13},-	{8602, 2, &rule6},-	{8604, 4, &rule13},-	{8608, 1, &rule6},-	{8609, 2, &rule13},-	{8611, 1, &rule6},-	{8612, 2, &rule13},-	{8614, 1, &rule6},-	{8615, 7, &rule13},-	{8622, 1, &rule6},-	{8623, 31, &rule13},-	{8654, 2, &rule6},-	{8656, 2, &rule13},-	{8658, 1, &rule6},-	{8659, 1, &rule13},-	{8660, 1, &rule6},-	{8661, 31, &rule13},-	{8692, 268, &rule6},-	{8960, 8, &rule13},-	{8968, 4, &rule6},-	{8972, 20, &rule13},-	{8992, 2, &rule6},-	{8994, 7, &rule13},-	{9001, 1, &rule4},-	{9002, 1, &rule5},-	{9003, 81, &rule13},-	{9084, 1, &rule6},-	{9085, 30, &rule13},-	{9115, 25, &rule6},-	{9140, 40, &rule13},-	{9180, 6, &rule6},-	{9186, 18, &rule13},-	{9216, 39, &rule13},-	{9280, 11, &rule13},-	{9312, 60, &rule17},-	{9372, 26, &rule13},-	{9398, 26, &rule148},-	{9424, 26, &rule149},-	{9450, 22, &rule17},-	{9472, 183, &rule13},-	{9655, 1, &rule6},-	{9656, 9, &rule13},-	{9665, 1, &rule6},-	{9666, 54, &rule13},-	{9720, 8, &rule6},-	{9728, 111, &rule13},-	{9839, 1, &rule6},-	{9840, 144, &rule13},-	{9985, 103, &rule13},-	{10088, 1, &rule4},-	{10089, 1, &rule5},-	{10090, 1, &rule4},-	{10091, 1, &rule5},-	{10092, 1, &rule4},-	{10093, 1, &rule5},-	{10094, 1, &rule4},-	{10095, 1, &rule5},-	{10096, 1, &rule4},-	{10097, 1, &rule5},-	{10098, 1, &rule4},-	{10099, 1, &rule5},-	{10100, 1, &rule4},-	{10101, 1, &rule5},-	{10102, 30, &rule17},-	{10132, 44, &rule13},-	{10176, 5, &rule6},-	{10181, 1, &rule4},-	{10182, 1, &rule5},-	{10183, 4, &rule6},-	{10188, 1, &rule6},-	{10190, 24, &rule6},-	{10214, 1, &rule4},-	{10215, 1, &rule5},-	{10216, 1, &rule4},-	{10217, 1, &rule5},-	{10218, 1, &rule4},-	{10219, 1, &rule5},-	{10220, 1, &rule4},-	{10221, 1, &rule5},-	{10222, 1, &rule4},-	{10223, 1, &rule5},-	{10224, 16, &rule6},-	{10240, 256, &rule13},-	{10496, 131, &rule6},-	{10627, 1, &rule4},-	{10628, 1, &rule5},-	{10629, 1, &rule4},-	{10630, 1, &rule5},-	{10631, 1, &rule4},-	{10632, 1, &rule5},-	{10633, 1, &rule4},-	{10634, 1, &rule5},-	{10635, 1, &rule4},-	{10636, 1, &rule5},-	{10637, 1, &rule4},-	{10638, 1, &rule5},-	{10639, 1, &rule4},-	{10640, 1, &rule5},-	{10641, 1, &rule4},-	{10642, 1, &rule5},-	{10643, 1, &rule4},-	{10644, 1, &rule5},-	{10645, 1, &rule4},-	{10646, 1, &rule5},-	{10647, 1, &rule4},-	{10648, 1, &rule5},-	{10649, 63, &rule6},-	{10712, 1, &rule4},-	{10713, 1, &rule5},-	{10714, 1, &rule4},-	{10715, 1, &rule5},-	{10716, 32, &rule6},-	{10748, 1, &rule4},-	{10749, 1, &rule5},-	{10750, 258, &rule6},-	{11008, 48, &rule13},-	{11056, 21, &rule6},-	{11077, 2, &rule13},-	{11079, 6, &rule6},-	{11088, 10, &rule13},-	{11264, 47, &rule112},-	{11312, 47, &rule113},-	{11360, 1, &rule21},-	{11361, 1, &rule22},-	{11362, 1, &rule150},-	{11363, 1, &rule151},-	{11364, 1, &rule152},-	{11365, 1, &rule153},-	{11366, 1, &rule154},-	{11367, 1, &rule21},-	{11368, 1, &rule22},-	{11369, 1, &rule21},-	{11370, 1, &rule22},-	{11371, 1, &rule21},-	{11372, 1, &rule22},-	{11373, 1, &rule155},-	{11374, 1, &rule156},-	{11375, 1, &rule157},-	{11376, 1, &rule158},-	{11377, 1, &rule14},-	{11378, 1, &rule21},-	{11379, 1, &rule22},-	{11380, 1, &rule14},-	{11381, 1, &rule21},-	{11382, 1, &rule22},-	{11383, 6, &rule14},-	{11389, 1, &rule83},-	{11390, 2, &rule159},-	{11392, 1, &rule21},-	{11393, 1, &rule22},-	{11394, 1, &rule21},-	{11395, 1, &rule22},-	{11396, 1, &rule21},-	{11397, 1, &rule22},-	{11398, 1, &rule21},-	{11399, 1, &rule22},-	{11400, 1, &rule21},-	{11401, 1, &rule22},-	{11402, 1, &rule21},-	{11403, 1, &rule22},-	{11404, 1, &rule21},-	{11405, 1, &rule22},-	{11406, 1, &rule21},-	{11407, 1, &rule22},-	{11408, 1, &rule21},-	{11409, 1, &rule22},-	{11410, 1, &rule21},-	{11411, 1, &rule22},-	{11412, 1, &rule21},-	{11413, 1, &rule22},-	{11414, 1, &rule21},-	{11415, 1, &rule22},-	{11416, 1, &rule21},-	{11417, 1, &rule22},-	{11418, 1, &rule21},-	{11419, 1, &rule22},-	{11420, 1, &rule21},-	{11421, 1, &rule22},-	{11422, 1, &rule21},-	{11423, 1, &rule22},-	{11424, 1, &rule21},-	{11425, 1, &rule22},-	{11426, 1, &rule21},-	{11427, 1, &rule22},-	{11428, 1, &rule21},-	{11429, 1, &rule22},-	{11430, 1, &rule21},-	{11431, 1, &rule22},-	{11432, 1, &rule21},-	{11433, 1, &rule22},-	{11434, 1, &rule21},-	{11435, 1, &rule22},-	{11436, 1, &rule21},-	{11437, 1, &rule22},-	{11438, 1, &rule21},-	{11439, 1, &rule22},-	{11440, 1, &rule21},-	{11441, 1, &rule22},-	{11442, 1, &rule21},-	{11443, 1, &rule22},-	{11444, 1, &rule21},-	{11445, 1, &rule22},-	{11446, 1, &rule21},-	{11447, 1, &rule22},-	{11448, 1, &rule21},-	{11449, 1, &rule22},-	{11450, 1, &rule21},-	{11451, 1, &rule22},-	{11452, 1, &rule21},-	{11453, 1, &rule22},-	{11454, 1, &rule21},-	{11455, 1, &rule22},-	{11456, 1, &rule21},-	{11457, 1, &rule22},-	{11458, 1, &rule21},-	{11459, 1, &rule22},-	{11460, 1, &rule21},-	{11461, 1, &rule22},-	{11462, 1, &rule21},-	{11463, 1, &rule22},-	{11464, 1, &rule21},-	{11465, 1, &rule22},-	{11466, 1, &rule21},-	{11467, 1, &rule22},-	{11468, 1, &rule21},-	{11469, 1, &rule22},-	{11470, 1, &rule21},-	{11471, 1, &rule22},-	{11472, 1, &rule21},-	{11473, 1, &rule22},-	{11474, 1, &rule21},-	{11475, 1, &rule22},-	{11476, 1, &rule21},-	{11477, 1, &rule22},-	{11478, 1, &rule21},-	{11479, 1, &rule22},-	{11480, 1, &rule21},-	{11481, 1, &rule22},-	{11482, 1, &rule21},-	{11483, 1, &rule22},-	{11484, 1, &rule21},-	{11485, 1, &rule22},-	{11486, 1, &rule21},-	{11487, 1, &rule22},-	{11488, 1, &rule21},-	{11489, 1, &rule22},-	{11490, 1, &rule21},-	{11491, 1, &rule22},-	{11492, 1, &rule14},-	{11493, 6, &rule13},-	{11499, 1, &rule21},-	{11500, 1, &rule22},-	{11501, 1, &rule21},-	{11502, 1, &rule22},-	{11503, 3, &rule84},-	{11513, 4, &rule2},-	{11517, 1, &rule17},-	{11518, 2, &rule2},-	{11520, 38, &rule160},-	{11568, 54, &rule45},-	{11631, 1, &rule83},-	{11632, 1, &rule2},-	{11647, 1, &rule84},-	{11648, 23, &rule45},-	{11680, 7, &rule45},-	{11688, 7, &rule45},-	{11696, 7, &rule45},-	{11704, 7, &rule45},-	{11712, 7, &rule45},-	{11720, 7, &rule45},-	{11728, 7, &rule45},-	{11736, 7, &rule45},-	{11744, 32, &rule84},-	{11776, 2, &rule2},-	{11778, 1, &rule15},-	{11779, 1, &rule19},-	{11780, 1, &rule15},-	{11781, 1, &rule19},-	{11782, 3, &rule2},-	{11785, 1, &rule15},-	{11786, 1, &rule19},-	{11787, 1, &rule2},-	{11788, 1, &rule15},-	{11789, 1, &rule19},-	{11790, 9, &rule2},-	{11799, 1, &rule7},-	{11800, 2, &rule2},-	{11802, 1, &rule7},-	{11803, 1, &rule2},-	{11804, 1, &rule15},-	{11805, 1, &rule19},-	{11806, 2, &rule2},-	{11808, 1, &rule15},-	{11809, 1, &rule19},-	{11810, 1, &rule4},-	{11811, 1, &rule5},-	{11812, 1, &rule4},-	{11813, 1, &rule5},-	{11814, 1, &rule4},-	{11815, 1, &rule5},-	{11816, 1, &rule4},-	{11817, 1, &rule5},-	{11818, 5, &rule2},-	{11823, 1, &rule83},-	{11824, 2, &rule2},-	{11904, 26, &rule13},-	{11931, 89, &rule13},-	{12032, 214, &rule13},-	{12272, 12, &rule13},-	{12288, 1, &rule1},-	{12289, 3, &rule2},-	{12292, 1, &rule13},-	{12293, 1, &rule83},-	{12294, 1, &rule45},-	{12295, 1, &rule116},-	{12296, 1, &rule4},-	{12297, 1, &rule5},-	{12298, 1, &rule4},-	{12299, 1, &rule5},-	{12300, 1, &rule4},-	{12301, 1, &rule5},-	{12302, 1, &rule4},-	{12303, 1, &rule5},-	{12304, 1, &rule4},-	{12305, 1, &rule5},-	{12306, 2, &rule13},-	{12308, 1, &rule4},-	{12309, 1, &rule5},-	{12310, 1, &rule4},-	{12311, 1, &rule5},-	{12312, 1, &rule4},-	{12313, 1, &rule5},-	{12314, 1, &rule4},-	{12315, 1, &rule5},-	{12316, 1, &rule7},-	{12317, 1, &rule4},-	{12318, 2, &rule5},-	{12320, 1, &rule13},-	{12321, 9, &rule116},-	{12330, 6, &rule84},-	{12336, 1, &rule7},-	{12337, 5, &rule83},-	{12342, 2, &rule13},-	{12344, 3, &rule116},-	{12347, 1, &rule83},-	{12348, 1, &rule45},-	{12349, 1, &rule2},-	{12350, 2, &rule13},-	{12353, 86, &rule45},-	{12441, 2, &rule84},-	{12443, 2, &rule10},-	{12445, 2, &rule83},-	{12447, 1, &rule45},-	{12448, 1, &rule7},-	{12449, 90, &rule45},-	{12539, 1, &rule2},-	{12540, 3, &rule83},-	{12543, 1, &rule45},-	{12549, 41, &rule45},-	{12593, 94, &rule45},-	{12688, 2, &rule13},-	{12690, 4, &rule17},-	{12694, 10, &rule13},-	{12704, 27, &rule45},-	{12736, 36, &rule13},-	{12784, 16, &rule45},-	{12800, 31, &rule13},-	{12832, 10, &rule17},-	{12842, 39, &rule13},-	{12881, 15, &rule17},-	{12896, 32, &rule13},-	{12928, 10, &rule17},-	{12938, 39, &rule13},-	{12977, 15, &rule17},-	{12992, 63, &rule13},-	{13056, 256, &rule13},-	{13312, 6582, &rule45},-	{19904, 64, &rule13},-	{19968, 20940, &rule45},-	{40960, 21, &rule45},-	{40981, 1, &rule83},-	{40982, 1143, &rule45},-	{42128, 55, &rule13},-	{42192, 40, &rule45},-	{42232, 6, &rule83},-	{42238, 2, &rule2},-	{42240, 268, &rule45},-	{42508, 1, &rule83},-	{42509, 3, &rule2},-	{42512, 16, &rule45},-	{42528, 10, &rule8},-	{42538, 2, &rule45},-	{42560, 1, &rule21},-	{42561, 1, &rule22},-	{42562, 1, &rule21},-	{42563, 1, &rule22},-	{42564, 1, &rule21},-	{42565, 1, &rule22},-	{42566, 1, &rule21},-	{42567, 1, &rule22},-	{42568, 1, &rule21},-	{42569, 1, &rule22},-	{42570, 1, &rule21},-	{42571, 1, &rule22},-	{42572, 1, &rule21},-	{42573, 1, &rule22},-	{42574, 1, &rule21},-	{42575, 1, &rule22},-	{42576, 1, &rule21},-	{42577, 1, &rule22},-	{42578, 1, &rule21},-	{42579, 1, &rule22},-	{42580, 1, &rule21},-	{42581, 1, &rule22},-	{42582, 1, &rule21},-	{42583, 1, &rule22},-	{42584, 1, &rule21},-	{42585, 1, &rule22},-	{42586, 1, &rule21},-	{42587, 1, &rule22},-	{42588, 1, &rule21},-	{42589, 1, &rule22},-	{42590, 1, &rule21},-	{42591, 1, &rule22},-	{42592, 1, &rule21},-	{42593, 1, &rule22},-	{42594, 1, &rule21},-	{42595, 1, &rule22},-	{42596, 1, &rule21},-	{42597, 1, &rule22},-	{42598, 1, &rule21},-	{42599, 1, &rule22},-	{42600, 1, &rule21},-	{42601, 1, &rule22},-	{42602, 1, &rule21},-	{42603, 1, &rule22},-	{42604, 1, &rule21},-	{42605, 1, &rule22},-	{42606, 1, &rule45},-	{42607, 1, &rule84},-	{42608, 3, &rule109},-	{42611, 1, &rule2},-	{42620, 2, &rule84},-	{42622, 1, &rule2},-	{42623, 1, &rule83},-	{42624, 1, &rule21},-	{42625, 1, &rule22},-	{42626, 1, &rule21},-	{42627, 1, &rule22},-	{42628, 1, &rule21},-	{42629, 1, &rule22},-	{42630, 1, &rule21},-	{42631, 1, &rule22},-	{42632, 1, &rule21},-	{42633, 1, &rule22},-	{42634, 1, &rule21},-	{42635, 1, &rule22},-	{42636, 1, &rule21},-	{42637, 1, &rule22},-	{42638, 1, &rule21},-	{42639, 1, &rule22},-	{42640, 1, &rule21},-	{42641, 1, &rule22},-	{42642, 1, &rule21},-	{42643, 1, &rule22},-	{42644, 1, &rule21},-	{42645, 1, &rule22},-	{42646, 1, &rule21},-	{42647, 1, &rule22},-	{42656, 70, &rule45},-	{42726, 10, &rule116},-	{42736, 2, &rule84},-	{42738, 6, &rule2},-	{42752, 23, &rule10},-	{42775, 9, &rule83},-	{42784, 2, &rule10},-	{42786, 1, &rule21},-	{42787, 1, &rule22},-	{42788, 1, &rule21},-	{42789, 1, &rule22},-	{42790, 1, &rule21},-	{42791, 1, &rule22},-	{42792, 1, &rule21},-	{42793, 1, &rule22},-	{42794, 1, &rule21},-	{42795, 1, &rule22},-	{42796, 1, &rule21},-	{42797, 1, &rule22},-	{42798, 1, &rule21},-	{42799, 1, &rule22},-	{42800, 2, &rule14},-	{42802, 1, &rule21},-	{42803, 1, &rule22},-	{42804, 1, &rule21},-	{42805, 1, &rule22},-	{42806, 1, &rule21},-	{42807, 1, &rule22},-	{42808, 1, &rule21},-	{42809, 1, &rule22},-	{42810, 1, &rule21},-	{42811, 1, &rule22},-	{42812, 1, &rule21},-	{42813, 1, &rule22},-	{42814, 1, &rule21},-	{42815, 1, &rule22},-	{42816, 1, &rule21},-	{42817, 1, &rule22},-	{42818, 1, &rule21},-	{42819, 1, &rule22},-	{42820, 1, &rule21},-	{42821, 1, &rule22},-	{42822, 1, &rule21},-	{42823, 1, &rule22},-	{42824, 1, &rule21},-	{42825, 1, &rule22},-	{42826, 1, &rule21},-	{42827, 1, &rule22},-	{42828, 1, &rule21},-	{42829, 1, &rule22},-	{42830, 1, &rule21},-	{42831, 1, &rule22},-	{42832, 1, &rule21},-	{42833, 1, &rule22},-	{42834, 1, &rule21},-	{42835, 1, &rule22},-	{42836, 1, &rule21},-	{42837, 1, &rule22},-	{42838, 1, &rule21},-	{42839, 1, &rule22},-	{42840, 1, &rule21},-	{42841, 1, &rule22},-	{42842, 1, &rule21},-	{42843, 1, &rule22},-	{42844, 1, &rule21},-	{42845, 1, &rule22},-	{42846, 1, &rule21},-	{42847, 1, &rule22},-	{42848, 1, &rule21},-	{42849, 1, &rule22},-	{42850, 1, &rule21},-	{42851, 1, &rule22},-	{42852, 1, &rule21},-	{42853, 1, &rule22},-	{42854, 1, &rule21},-	{42855, 1, &rule22},-	{42856, 1, &rule21},-	{42857, 1, &rule22},-	{42858, 1, &rule21},-	{42859, 1, &rule22},-	{42860, 1, &rule21},-	{42861, 1, &rule22},-	{42862, 1, &rule21},-	{42863, 1, &rule22},-	{42864, 1, &rule83},-	{42865, 8, &rule14},-	{42873, 1, &rule21},-	{42874, 1, &rule22},-	{42875, 1, &rule21},-	{42876, 1, &rule22},-	{42877, 1, &rule161},-	{42878, 1, &rule21},-	{42879, 1, &rule22},-	{42880, 1, &rule21},-	{42881, 1, &rule22},-	{42882, 1, &rule21},-	{42883, 1, &rule22},-	{42884, 1, &rule21},-	{42885, 1, &rule22},-	{42886, 1, &rule21},-	{42887, 1, &rule22},-	{42888, 1, &rule83},-	{42889, 2, &rule10},-	{42891, 1, &rule21},-	{42892, 1, &rule22},-	{42893, 1, &rule162},-	{42894, 1, &rule14},-	{42896, 1, &rule21},-	{42897, 1, &rule22},-	{42912, 1, &rule21},-	{42913, 1, &rule22},-	{42914, 1, &rule21},-	{42915, 1, &rule22},-	{42916, 1, &rule21},-	{42917, 1, &rule22},-	{42918, 1, &rule21},-	{42919, 1, &rule22},-	{42920, 1, &rule21},-	{42921, 1, &rule22},-	{43002, 1, &rule14},-	{43003, 7, &rule45},-	{43010, 1, &rule84},-	{43011, 3, &rule45},-	{43014, 1, &rule84},-	{43015, 4, &rule45},-	{43019, 1, &rule84},-	{43020, 23, &rule45},-	{43043, 2, &rule114},-	{43045, 2, &rule84},-	{43047, 1, &rule114},-	{43048, 4, &rule13},-	{43056, 6, &rule17},-	{43062, 2, &rule13},-	{43064, 1, &rule3},-	{43065, 1, &rule13},-	{43072, 52, &rule45},-	{43124, 4, &rule2},-	{43136, 2, &rule114},-	{43138, 50, &rule45},-	{43188, 16, &rule114},-	{43204, 1, &rule84},-	{43214, 2, &rule2},-	{43216, 10, &rule8},-	{43232, 18, &rule84},-	{43250, 6, &rule45},-	{43256, 3, &rule2},-	{43259, 1, &rule45},-	{43264, 10, &rule8},-	{43274, 28, &rule45},-	{43302, 8, &rule84},-	{43310, 2, &rule2},-	{43312, 23, &rule45},-	{43335, 11, &rule84},-	{43346, 2, &rule114},-	{43359, 1, &rule2},-	{43360, 29, &rule45},-	{43392, 3, &rule84},-	{43395, 1, &rule114},-	{43396, 47, &rule45},-	{43443, 1, &rule84},-	{43444, 2, &rule114},-	{43446, 4, &rule84},-	{43450, 2, &rule114},-	{43452, 1, &rule84},-	{43453, 4, &rule114},-	{43457, 13, &rule2},-	{43471, 1, &rule83},-	{43472, 10, &rule8},-	{43486, 2, &rule2},-	{43520, 41, &rule45},-	{43561, 6, &rule84},-	{43567, 2, &rule114},-	{43569, 2, &rule84},-	{43571, 2, &rule114},-	{43573, 2, &rule84},-	{43584, 3, &rule45},-	{43587, 1, &rule84},-	{43588, 8, &rule45},-	{43596, 1, &rule84},-	{43597, 1, &rule114},-	{43600, 10, &rule8},-	{43612, 4, &rule2},-	{43616, 16, &rule45},-	{43632, 1, &rule83},-	{43633, 6, &rule45},-	{43639, 3, &rule13},-	{43642, 1, &rule45},-	{43643, 1, &rule114},-	{43648, 48, &rule45},-	{43696, 1, &rule84},-	{43697, 1, &rule45},-	{43698, 3, &rule84},-	{43701, 2, &rule45},-	{43703, 2, &rule84},-	{43705, 5, &rule45},-	{43710, 2, &rule84},-	{43712, 1, &rule45},-	{43713, 1, &rule84},-	{43714, 1, &rule45},-	{43739, 2, &rule45},-	{43741, 1, &rule83},-	{43742, 2, &rule2},-	{43777, 6, &rule45},-	{43785, 6, &rule45},-	{43793, 6, &rule45},-	{43808, 7, &rule45},-	{43816, 7, &rule45},-	{43968, 35, &rule45},-	{44003, 2, &rule114},-	{44005, 1, &rule84},-	{44006, 2, &rule114},-	{44008, 1, &rule84},-	{44009, 2, &rule114},-	{44011, 1, &rule2},-	{44012, 1, &rule114},-	{44013, 1, &rule84},-	{44016, 10, &rule8},-	{44032, 11172, &rule45},-	{55216, 23, &rule45},-	{55243, 49, &rule45},-	{55296, 896, &rule163},-	{56192, 128, &rule163},-	{56320, 1024, &rule163},-	{57344, 6400, &rule164},-	{63744, 302, &rule45},-	{64048, 62, &rule45},-	{64112, 106, &rule45},-	{64256, 7, &rule14},-	{64275, 5, &rule14},-	{64285, 1, &rule45},-	{64286, 1, &rule84},-	{64287, 10, &rule45},-	{64297, 1, &rule6},-	{64298, 13, &rule45},-	{64312, 5, &rule45},-	{64318, 1, &rule45},-	{64320, 2, &rule45},-	{64323, 2, &rule45},-	{64326, 108, &rule45},-	{64434, 16, &rule10},-	{64467, 363, &rule45},-	{64830, 1, &rule4},-	{64831, 1, &rule5},-	{64848, 64, &rule45},-	{64914, 54, &rule45},-	{65008, 12, &rule45},-	{65020, 1, &rule3},-	{65021, 1, &rule13},-	{65024, 16, &rule84},-	{65040, 7, &rule2},-	{65047, 1, &rule4},-	{65048, 1, &rule5},-	{65049, 1, &rule2},-	{65056, 7, &rule84},-	{65072, 1, &rule2},-	{65073, 2, &rule7},-	{65075, 2, &rule11},-	{65077, 1, &rule4},-	{65078, 1, &rule5},-	{65079, 1, &rule4},-	{65080, 1, &rule5},-	{65081, 1, &rule4},-	{65082, 1, &rule5},-	{65083, 1, &rule4},-	{65084, 1, &rule5},-	{65085, 1, &rule4},-	{65086, 1, &rule5},-	{65087, 1, &rule4},-	{65088, 1, &rule5},-	{65089, 1, &rule4},-	{65090, 1, &rule5},-	{65091, 1, &rule4},-	{65092, 1, &rule5},-	{65093, 2, &rule2},-	{65095, 1, &rule4},-	{65096, 1, &rule5},-	{65097, 4, &rule2},-	{65101, 3, &rule11},-	{65104, 3, &rule2},-	{65108, 4, &rule2},-	{65112, 1, &rule7},-	{65113, 1, &rule4},-	{65114, 1, &rule5},-	{65115, 1, &rule4},-	{65116, 1, &rule5},-	{65117, 1, &rule4},-	{65118, 1, &rule5},-	{65119, 3, &rule2},-	{65122, 1, &rule6},-	{65123, 1, &rule7},-	{65124, 3, &rule6},-	{65128, 1, &rule2},-	{65129, 1, &rule3},-	{65130, 2, &rule2},-	{65136, 5, &rule45},-	{65142, 135, &rule45},-	{65279, 1, &rule16},-	{65281, 3, &rule2},-	{65284, 1, &rule3},-	{65285, 3, &rule2},-	{65288, 1, &rule4},-	{65289, 1, &rule5},-	{65290, 1, &rule2},-	{65291, 1, &rule6},-	{65292, 1, &rule2},-	{65293, 1, &rule7},-	{65294, 2, &rule2},-	{65296, 10, &rule8},-	{65306, 2, &rule2},-	{65308, 3, &rule6},-	{65311, 2, &rule2},-	{65313, 26, &rule9},-	{65339, 1, &rule4},-	{65340, 1, &rule2},-	{65341, 1, &rule5},-	{65342, 1, &rule10},-	{65343, 1, &rule11},-	{65344, 1, &rule10},-	{65345, 26, &rule12},-	{65371, 1, &rule4},-	{65372, 1, &rule6},-	{65373, 1, &rule5},-	{65374, 1, &rule6},-	{65375, 1, &rule4},-	{65376, 1, &rule5},-	{65377, 1, &rule2},-	{65378, 1, &rule4},-	{65379, 1, &rule5},-	{65380, 2, &rule2},-	{65382, 10, &rule45},-	{65392, 1, &rule83},-	{65393, 45, &rule45},-	{65438, 2, &rule83},-	{65440, 31, &rule45},-	{65474, 6, &rule45},-	{65482, 6, &rule45},-	{65490, 6, &rule45},-	{65498, 3, &rule45},-	{65504, 2, &rule3},-	{65506, 1, &rule6},-	{65507, 1, &rule10},-	{65508, 1, &rule13},-	{65509, 2, &rule3},-	{65512, 1, &rule13},-	{65513, 4, &rule6},-	{65517, 2, &rule13},-	{65529, 3, &rule16},-	{65532, 2, &rule13},-	{65536, 12, &rule45},-	{65549, 26, &rule45},-	{65576, 19, &rule45},-	{65596, 2, &rule45},-	{65599, 15, &rule45},-	{65616, 14, &rule45},-	{65664, 123, &rule45},-	{65792, 2, &rule2},-	{65794, 1, &rule13},-	{65799, 45, &rule17},-	{65847, 9, &rule13},-	{65856, 53, &rule116},-	{65909, 4, &rule17},-	{65913, 17, &rule13},-	{65930, 1, &rule17},-	{65936, 12, &rule13},-	{66000, 45, &rule13},-	{66045, 1, &rule84},-	{66176, 29, &rule45},-	{66208, 49, &rule45},-	{66304, 31, &rule45},-	{66336, 4, &rule17},-	{66352, 17, &rule45},-	{66369, 1, &rule116},-	{66370, 8, &rule45},-	{66378, 1, &rule116},-	{66432, 30, &rule45},-	{66463, 1, &rule2},-	{66464, 36, &rule45},-	{66504, 8, &rule45},-	{66512, 1, &rule2},-	{66513, 5, &rule116},-	{66560, 40, &rule165},-	{66600, 40, &rule166},-	{66640, 78, &rule45},-	{66720, 10, &rule8},-	{67584, 6, &rule45},-	{67592, 1, &rule45},-	{67594, 44, &rule45},-	{67639, 2, &rule45},-	{67644, 1, &rule45},-	{67647, 23, &rule45},-	{67671, 1, &rule2},-	{67672, 8, &rule17},-	{67840, 22, &rule45},-	{67862, 6, &rule17},-	{67871, 1, &rule2},-	{67872, 26, &rule45},-	{67903, 1, &rule2},-	{68096, 1, &rule45},-	{68097, 3, &rule84},-	{68101, 2, &rule84},-	{68108, 4, &rule84},-	{68112, 4, &rule45},-	{68117, 3, &rule45},-	{68121, 27, &rule45},-	{68152, 3, &rule84},-	{68159, 1, &rule84},-	{68160, 8, &rule17},-	{68176, 9, &rule2},-	{68192, 29, &rule45},-	{68221, 2, &rule17},-	{68223, 1, &rule2},-	{68352, 54, &rule45},-	{68409, 7, &rule2},-	{68416, 22, &rule45},-	{68440, 8, &rule17},-	{68448, 19, &rule45},-	{68472, 8, &rule17},-	{68608, 73, &rule45},-	{69216, 31, &rule17},-	{69632, 1, &rule114},-	{69633, 1, &rule84},-	{69634, 1, &rule114},-	{69635, 53, &rule45},-	{69688, 15, &rule84},-	{69703, 7, &rule2},-	{69714, 20, &rule17},-	{69734, 10, &rule8},-	{69760, 2, &rule84},-	{69762, 1, &rule114},-	{69763, 45, &rule45},-	{69808, 3, &rule114},-	{69811, 4, &rule84},-	{69815, 2, &rule114},-	{69817, 2, &rule84},-	{69819, 2, &rule2},-	{69821, 1, &rule16},-	{69822, 4, &rule2},-	{73728, 879, &rule45},-	{74752, 99, &rule116},-	{74864, 4, &rule2},-	{77824, 1071, &rule45},-	{92160, 569, &rule45},-	{110592, 2, &rule45},-	{118784, 246, &rule13},-	{119040, 39, &rule13},-	{119081, 60, &rule13},-	{119141, 2, &rule114},-	{119143, 3, &rule84},-	{119146, 3, &rule13},-	{119149, 6, &rule114},-	{119155, 8, &rule16},-	{119163, 8, &rule84},-	{119171, 2, &rule13},-	{119173, 7, &rule84},-	{119180, 30, &rule13},-	{119210, 4, &rule84},-	{119214, 48, &rule13},-	{119296, 66, &rule13},-	{119362, 3, &rule84},-	{119365, 1, &rule13},-	{119552, 87, &rule13},-	{119648, 18, &rule17},-	{119808, 26, &rule98},-	{119834, 26, &rule14},-	{119860, 26, &rule98},-	{119886, 7, &rule14},-	{119894, 18, &rule14},-	{119912, 26, &rule98},-	{119938, 26, &rule14},-	{119964, 1, &rule98},-	{119966, 2, &rule98},-	{119970, 1, &rule98},-	{119973, 2, &rule98},-	{119977, 4, &rule98},-	{119982, 8, &rule98},-	{119990, 4, &rule14},-	{119995, 1, &rule14},-	{119997, 7, &rule14},-	{120005, 11, &rule14},-	{120016, 26, &rule98},-	{120042, 26, &rule14},-	{120068, 2, &rule98},-	{120071, 4, &rule98},-	{120077, 8, &rule98},-	{120086, 7, &rule98},-	{120094, 26, &rule14},-	{120120, 2, &rule98},-	{120123, 4, &rule98},-	{120128, 5, &rule98},-	{120134, 1, &rule98},-	{120138, 7, &rule98},-	{120146, 26, &rule14},-	{120172, 26, &rule98},-	{120198, 26, &rule14},-	{120224, 26, &rule98},-	{120250, 26, &rule14},-	{120276, 26, &rule98},-	{120302, 26, &rule14},-	{120328, 26, &rule98},-	{120354, 26, &rule14},-	{120380, 26, &rule98},-	{120406, 26, &rule14},-	{120432, 26, &rule98},-	{120458, 28, &rule14},-	{120488, 25, &rule98},-	{120513, 1, &rule6},-	{120514, 25, &rule14},-	{120539, 1, &rule6},-	{120540, 6, &rule14},-	{120546, 25, &rule98},-	{120571, 1, &rule6},-	{120572, 25, &rule14},-	{120597, 1, &rule6},-	{120598, 6, &rule14},-	{120604, 25, &rule98},-	{120629, 1, &rule6},-	{120630, 25, &rule14},-	{120655, 1, &rule6},-	{120656, 6, &rule14},-	{120662, 25, &rule98},-	{120687, 1, &rule6},-	{120688, 25, &rule14},-	{120713, 1, &rule6},-	{120714, 6, &rule14},-	{120720, 25, &rule98},-	{120745, 1, &rule6},-	{120746, 25, &rule14},-	{120771, 1, &rule6},-	{120772, 6, &rule14},-	{120778, 1, &rule98},-	{120779, 1, &rule14},-	{120782, 50, &rule8},-	{126976, 44, &rule13},-	{127024, 100, &rule13},-	{127136, 15, &rule13},-	{127153, 14, &rule13},-	{127169, 15, &rule13},-	{127185, 15, &rule13},-	{127232, 11, &rule17},-	{127248, 31, &rule13},-	{127280, 58, &rule13},-	{127344, 43, &rule13},-	{127462, 29, &rule13},-	{127504, 43, &rule13},-	{127552, 9, &rule13},-	{127568, 2, &rule13},-	{127744, 33, &rule13},-	{127792, 6, &rule13},-	{127799, 70, &rule13},-	{127872, 20, &rule13},-	{127904, 37, &rule13},-	{127942, 5, &rule13},-	{127968, 17, &rule13},-	{128000, 63, &rule13},-	{128064, 1, &rule13},-	{128066, 182, &rule13},-	{128249, 4, &rule13},-	{128256, 62, &rule13},-	{128336, 24, &rule13},-	{128507, 5, &rule13},-	{128513, 16, &rule13},-	{128530, 3, &rule13},-	{128534, 1, &rule13},-	{128536, 1, &rule13},-	{128538, 1, &rule13},-	{128540, 3, &rule13},-	{128544, 6, &rule13},-	{128552, 4, &rule13},-	{128557, 1, &rule13},-	{128560, 4, &rule13},-	{128565, 12, &rule13},-	{128581, 11, &rule13},-	{128640, 70, &rule13},-	{128768, 116, &rule13},-	{131072, 42711, &rule45},-	{173824, 4149, &rule45},-	{177984, 222, &rule45},-	{194560, 542, &rule45},-	{917505, 1, &rule16},-	{917536, 96, &rule16},-	{917760, 240, &rule84},-	{983040, 65534, &rule164},-	{1048576, 65534, &rule164}-};-static const struct _charblock_ convchars[]={-	{65, 26, &rule9},-	{97, 26, &rule12},-	{181, 1, &rule18},-	{192, 23, &rule9},-	{216, 7, &rule9},-	{224, 23, &rule12},-	{248, 7, &rule12},-	{255, 1, &rule20},-	{256, 1, &rule21},-	{257, 1, &rule22},-	{258, 1, &rule21},-	{259, 1, &rule22},-	{260, 1, &rule21},-	{261, 1, &rule22},-	{262, 1, &rule21},-	{263, 1, &rule22},-	{264, 1, &rule21},-	{265, 1, &rule22},-	{266, 1, &rule21},-	{267, 1, &rule22},-	{268, 1, &rule21},-	{269, 1, &rule22},-	{270, 1, &rule21},-	{271, 1, &rule22},-	{272, 1, &rule21},-	{273, 1, &rule22},-	{274, 1, &rule21},-	{275, 1, &rule22},-	{276, 1, &rule21},-	{277, 1, &rule22},-	{278, 1, &rule21},-	{279, 1, &rule22},-	{280, 1, &rule21},-	{281, 1, &rule22},-	{282, 1, &rule21},-	{283, 1, &rule22},-	{284, 1, &rule21},-	{285, 1, &rule22},-	{286, 1, &rule21},-	{287, 1, &rule22},-	{288, 1, &rule21},-	{289, 1, &rule22},-	{290, 1, &rule21},-	{291, 1, &rule22},-	{292, 1, &rule21},-	{293, 1, &rule22},-	{294, 1, &rule21},-	{295, 1, &rule22},-	{296, 1, &rule21},-	{297, 1, &rule22},-	{298, 1, &rule21},-	{299, 1, &rule22},-	{300, 1, &rule21},-	{301, 1, &rule22},-	{302, 1, &rule21},-	{303, 1, &rule22},-	{304, 1, &rule23},-	{305, 1, &rule24},-	{306, 1, &rule21},-	{307, 1, &rule22},-	{308, 1, &rule21},-	{309, 1, &rule22},-	{310, 1, &rule21},-	{311, 1, &rule22},-	{313, 1, &rule21},-	{314, 1, &rule22},-	{315, 1, &rule21},-	{316, 1, &rule22},-	{317, 1, &rule21},-	{318, 1, &rule22},-	{319, 1, &rule21},-	{320, 1, &rule22},-	{321, 1, &rule21},-	{322, 1, &rule22},-	{323, 1, &rule21},-	{324, 1, &rule22},-	{325, 1, &rule21},-	{326, 1, &rule22},-	{327, 1, &rule21},-	{328, 1, &rule22},-	{330, 1, &rule21},-	{331, 1, &rule22},-	{332, 1, &rule21},-	{333, 1, &rule22},-	{334, 1, &rule21},-	{335, 1, &rule22},-	{336, 1, &rule21},-	{337, 1, &rule22},-	{338, 1, &rule21},-	{339, 1, &rule22},-	{340, 1, &rule21},-	{341, 1, &rule22},-	{342, 1, &rule21},-	{343, 1, &rule22},-	{344, 1, &rule21},-	{345, 1, &rule22},-	{346, 1, &rule21},-	{347, 1, &rule22},-	{348, 1, &rule21},-	{349, 1, &rule22},-	{350, 1, &rule21},-	{351, 1, &rule22},-	{352, 1, &rule21},-	{353, 1, &rule22},-	{354, 1, &rule21},-	{355, 1, &rule22},-	{356, 1, &rule21},-	{357, 1, &rule22},-	{358, 1, &rule21},-	{359, 1, &rule22},-	{360, 1, &rule21},-	{361, 1, &rule22},-	{362, 1, &rule21},-	{363, 1, &rule22},-	{364, 1, &rule21},-	{365, 1, &rule22},-	{366, 1, &rule21},-	{367, 1, &rule22},-	{368, 1, &rule21},-	{369, 1, &rule22},-	{370, 1, &rule21},-	{371, 1, &rule22},-	{372, 1, &rule21},-	{373, 1, &rule22},-	{374, 1, &rule21},-	{375, 1, &rule22},-	{376, 1, &rule25},-	{377, 1, &rule21},-	{378, 1, &rule22},-	{379, 1, &rule21},-	{380, 1, &rule22},-	{381, 1, &rule21},-	{382, 1, &rule22},-	{383, 1, &rule26},-	{384, 1, &rule27},-	{385, 1, &rule28},-	{386, 1, &rule21},-	{387, 1, &rule22},-	{388, 1, &rule21},-	{389, 1, &rule22},-	{390, 1, &rule29},-	{391, 1, &rule21},-	{392, 1, &rule22},-	{393, 2, &rule30},-	{395, 1, &rule21},-	{396, 1, &rule22},-	{398, 1, &rule31},-	{399, 1, &rule32},-	{400, 1, &rule33},-	{401, 1, &rule21},-	{402, 1, &rule22},-	{403, 1, &rule30},-	{404, 1, &rule34},-	{405, 1, &rule35},-	{406, 1, &rule36},-	{407, 1, &rule37},-	{408, 1, &rule21},-	{409, 1, &rule22},-	{410, 1, &rule38},-	{412, 1, &rule36},-	{413, 1, &rule39},-	{414, 1, &rule40},-	{415, 1, &rule41},-	{416, 1, &rule21},-	{417, 1, &rule22},-	{418, 1, &rule21},-	{419, 1, &rule22},-	{420, 1, &rule21},-	{421, 1, &rule22},-	{422, 1, &rule42},-	{423, 1, &rule21},-	{424, 1, &rule22},-	{425, 1, &rule42},-	{428, 1, &rule21},-	{429, 1, &rule22},-	{430, 1, &rule42},-	{431, 1, &rule21},-	{432, 1, &rule22},-	{433, 2, &rule43},-	{435, 1, &rule21},-	{436, 1, &rule22},-	{437, 1, &rule21},-	{438, 1, &rule22},-	{439, 1, &rule44},-	{440, 1, &rule21},-	{441, 1, &rule22},-	{444, 1, &rule21},-	{445, 1, &rule22},-	{447, 1, &rule46},-	{452, 1, &rule47},-	{453, 1, &rule48},-	{454, 1, &rule49},-	{455, 1, &rule47},-	{456, 1, &rule48},-	{457, 1, &rule49},-	{458, 1, &rule47},-	{459, 1, &rule48},-	{460, 1, &rule49},-	{461, 1, &rule21},-	{462, 1, &rule22},-	{463, 1, &rule21},-	{464, 1, &rule22},-	{465, 1, &rule21},-	{466, 1, &rule22},-	{467, 1, &rule21},-	{468, 1, &rule22},-	{469, 1, &rule21},-	{470, 1, &rule22},-	{471, 1, &rule21},-	{472, 1, &rule22},-	{473, 1, &rule21},-	{474, 1, &rule22},-	{475, 1, &rule21},-	{476, 1, &rule22},-	{477, 1, &rule50},-	{478, 1, &rule21},-	{479, 1, &rule22},-	{480, 1, &rule21},-	{481, 1, &rule22},-	{482, 1, &rule21},-	{483, 1, &rule22},-	{484, 1, &rule21},-	{485, 1, &rule22},-	{486, 1, &rule21},-	{487, 1, &rule22},-	{488, 1, &rule21},-	{489, 1, &rule22},-	{490, 1, &rule21},-	{491, 1, &rule22},-	{492, 1, &rule21},-	{493, 1, &rule22},-	{494, 1, &rule21},-	{495, 1, &rule22},-	{497, 1, &rule47},-	{498, 1, &rule48},-	{499, 1, &rule49},-	{500, 1, &rule21},-	{501, 1, &rule22},-	{502, 1, &rule51},-	{503, 1, &rule52},-	{504, 1, &rule21},-	{505, 1, &rule22},-	{506, 1, &rule21},-	{507, 1, &rule22},-	{508, 1, &rule21},-	{509, 1, &rule22},-	{510, 1, &rule21},-	{511, 1, &rule22},-	{512, 1, &rule21},-	{513, 1, &rule22},-	{514, 1, &rule21},-	{515, 1, &rule22},-	{516, 1, &rule21},-	{517, 1, &rule22},-	{518, 1, &rule21},-	{519, 1, &rule22},-	{520, 1, &rule21},-	{521, 1, &rule22},-	{522, 1, &rule21},-	{523, 1, &rule22},-	{524, 1, &rule21},-	{525, 1, &rule22},-	{526, 1, &rule21},-	{527, 1, &rule22},-	{528, 1, &rule21},-	{529, 1, &rule22},-	{530, 1, &rule21},-	{531, 1, &rule22},-	{532, 1, &rule21},-	{533, 1, &rule22},-	{534, 1, &rule21},-	{535, 1, &rule22},-	{536, 1, &rule21},-	{537, 1, &rule22},-	{538, 1, &rule21},-	{539, 1, &rule22},-	{540, 1, &rule21},-	{541, 1, &rule22},-	{542, 1, &rule21},-	{543, 1, &rule22},-	{544, 1, &rule53},-	{546, 1, &rule21},-	{547, 1, &rule22},-	{548, 1, &rule21},-	{549, 1, &rule22},-	{550, 1, &rule21},-	{551, 1, &rule22},-	{552, 1, &rule21},-	{553, 1, &rule22},-	{554, 1, &rule21},-	{555, 1, &rule22},-	{556, 1, &rule21},-	{557, 1, &rule22},-	{558, 1, &rule21},-	{559, 1, &rule22},-	{560, 1, &rule21},-	{561, 1, &rule22},-	{562, 1, &rule21},-	{563, 1, &rule22},-	{570, 1, &rule54},-	{571, 1, &rule21},-	{572, 1, &rule22},-	{573, 1, &rule55},-	{574, 1, &rule56},-	{575, 2, &rule57},-	{577, 1, &rule21},-	{578, 1, &rule22},-	{579, 1, &rule58},-	{580, 1, &rule59},-	{581, 1, &rule60},-	{582, 1, &rule21},-	{583, 1, &rule22},-	{584, 1, &rule21},-	{585, 1, &rule22},-	{586, 1, &rule21},-	{587, 1, &rule22},-	{588, 1, &rule21},-	{589, 1, &rule22},-	{590, 1, &rule21},-	{591, 1, &rule22},-	{592, 1, &rule61},-	{593, 1, &rule62},-	{594, 1, &rule63},-	{595, 1, &rule64},-	{596, 1, &rule65},-	{598, 2, &rule66},-	{601, 1, &rule67},-	{603, 1, &rule68},-	{608, 1, &rule66},-	{611, 1, &rule69},-	{613, 1, &rule70},-	{616, 1, &rule71},-	{617, 1, &rule72},-	{619, 1, &rule73},-	{623, 1, &rule72},-	{625, 1, &rule74},-	{626, 1, &rule75},-	{629, 1, &rule76},-	{637, 1, &rule77},-	{640, 1, &rule78},-	{643, 1, &rule78},-	{648, 1, &rule78},-	{649, 1, &rule79},-	{650, 2, &rule80},-	{652, 1, &rule81},-	{658, 1, &rule82},-	{837, 1, &rule85},-	{880, 1, &rule21},-	{881, 1, &rule22},-	{882, 1, &rule21},-	{883, 1, &rule22},-	{886, 1, &rule21},-	{887, 1, &rule22},-	{891, 3, &rule40},-	{902, 1, &rule86},-	{904, 3, &rule87},-	{908, 1, &rule88},-	{910, 2, &rule89},-	{913, 17, &rule9},-	{931, 9, &rule9},-	{940, 1, &rule90},-	{941, 3, &rule91},-	{945, 17, &rule12},-	{962, 1, &rule92},-	{963, 9, &rule12},-	{972, 1, &rule93},-	{973, 2, &rule94},-	{975, 1, &rule95},-	{976, 1, &rule96},-	{977, 1, &rule97},-	{981, 1, &rule99},-	{982, 1, &rule100},-	{983, 1, &rule101},-	{984, 1, &rule21},-	{985, 1, &rule22},-	{986, 1, &rule21},-	{987, 1, &rule22},-	{988, 1, &rule21},-	{989, 1, &rule22},-	{990, 1, &rule21},-	{991, 1, &rule22},-	{992, 1, &rule21},-	{993, 1, &rule22},-	{994, 1, &rule21},-	{995, 1, &rule22},-	{996, 1, &rule21},-	{997, 1, &rule22},-	{998, 1, &rule21},-	{999, 1, &rule22},-	{1000, 1, &rule21},-	{1001, 1, &rule22},-	{1002, 1, &rule21},-	{1003, 1, &rule22},-	{1004, 1, &rule21},-	{1005, 1, &rule22},-	{1006, 1, &rule21},-	{1007, 1, &rule22},-	{1008, 1, &rule102},-	{1009, 1, &rule103},-	{1010, 1, &rule104},-	{1012, 1, &rule105},-	{1013, 1, &rule106},-	{1015, 1, &rule21},-	{1016, 1, &rule22},-	{1017, 1, &rule107},-	{1018, 1, &rule21},-	{1019, 1, &rule22},-	{1021, 3, &rule53},-	{1024, 16, &rule108},-	{1040, 32, &rule9},-	{1072, 32, &rule12},-	{1104, 16, &rule103},-	{1120, 1, &rule21},-	{1121, 1, &rule22},-	{1122, 1, &rule21},-	{1123, 1, &rule22},-	{1124, 1, &rule21},-	{1125, 1, &rule22},-	{1126, 1, &rule21},-	{1127, 1, &rule22},-	{1128, 1, &rule21},-	{1129, 1, &rule22},-	{1130, 1, &rule21},-	{1131, 1, &rule22},-	{1132, 1, &rule21},-	{1133, 1, &rule22},-	{1134, 1, &rule21},-	{1135, 1, &rule22},-	{1136, 1, &rule21},-	{1137, 1, &rule22},-	{1138, 1, &rule21},-	{1139, 1, &rule22},-	{1140, 1, &rule21},-	{1141, 1, &rule22},-	{1142, 1, &rule21},-	{1143, 1, &rule22},-	{1144, 1, &rule21},-	{1145, 1, &rule22},-	{1146, 1, &rule21},-	{1147, 1, &rule22},-	{1148, 1, &rule21},-	{1149, 1, &rule22},-	{1150, 1, &rule21},-	{1151, 1, &rule22},-	{1152, 1, &rule21},-	{1153, 1, &rule22},-	{1162, 1, &rule21},-	{1163, 1, &rule22},-	{1164, 1, &rule21},-	{1165, 1, &rule22},-	{1166, 1, &rule21},-	{1167, 1, &rule22},-	{1168, 1, &rule21},-	{1169, 1, &rule22},-	{1170, 1, &rule21},-	{1171, 1, &rule22},-	{1172, 1, &rule21},-	{1173, 1, &rule22},-	{1174, 1, &rule21},-	{1175, 1, &rule22},-	{1176, 1, &rule21},-	{1177, 1, &rule22},-	{1178, 1, &rule21},-	{1179, 1, &rule22},-	{1180, 1, &rule21},-	{1181, 1, &rule22},-	{1182, 1, &rule21},-	{1183, 1, &rule22},-	{1184, 1, &rule21},-	{1185, 1, &rule22},-	{1186, 1, &rule21},-	{1187, 1, &rule22},-	{1188, 1, &rule21},-	{1189, 1, &rule22},-	{1190, 1, &rule21},-	{1191, 1, &rule22},-	{1192, 1, &rule21},-	{1193, 1, &rule22},-	{1194, 1, &rule21},-	{1195, 1, &rule22},-	{1196, 1, &rule21},-	{1197, 1, &rule22},-	{1198, 1, &rule21},-	{1199, 1, &rule22},-	{1200, 1, &rule21},-	{1201, 1, &rule22},-	{1202, 1, &rule21},-	{1203, 1, &rule22},-	{1204, 1, &rule21},-	{1205, 1, &rule22},-	{1206, 1, &rule21},-	{1207, 1, &rule22},-	{1208, 1, &rule21},-	{1209, 1, &rule22},-	{1210, 1, &rule21},-	{1211, 1, &rule22},-	{1212, 1, &rule21},-	{1213, 1, &rule22},-	{1214, 1, &rule21},-	{1215, 1, &rule22},-	{1216, 1, &rule110},-	{1217, 1, &rule21},-	{1218, 1, &rule22},-	{1219, 1, &rule21},-	{1220, 1, &rule22},-	{1221, 1, &rule21},-	{1222, 1, &rule22},-	{1223, 1, &rule21},-	{1224, 1, &rule22},-	{1225, 1, &rule21},-	{1226, 1, &rule22},-	{1227, 1, &rule21},-	{1228, 1, &rule22},-	{1229, 1, &rule21},-	{1230, 1, &rule22},-	{1231, 1, &rule111},-	{1232, 1, &rule21},-	{1233, 1, &rule22},-	{1234, 1, &rule21},-	{1235, 1, &rule22},-	{1236, 1, &rule21},-	{1237, 1, &rule22},-	{1238, 1, &rule21},-	{1239, 1, &rule22},-	{1240, 1, &rule21},-	{1241, 1, &rule22},-	{1242, 1, &rule21},-	{1243, 1, &rule22},-	{1244, 1, &rule21},-	{1245, 1, &rule22},-	{1246, 1, &rule21},-	{1247, 1, &rule22},-	{1248, 1, &rule21},-	{1249, 1, &rule22},-	{1250, 1, &rule21},-	{1251, 1, &rule22},-	{1252, 1, &rule21},-	{1253, 1, &rule22},-	{1254, 1, &rule21},-	{1255, 1, &rule22},-	{1256, 1, &rule21},-	{1257, 1, &rule22},-	{1258, 1, &rule21},-	{1259, 1, &rule22},-	{1260, 1, &rule21},-	{1261, 1, &rule22},-	{1262, 1, &rule21},-	{1263, 1, &rule22},-	{1264, 1, &rule21},-	{1265, 1, &rule22},-	{1266, 1, &rule21},-	{1267, 1, &rule22},-	{1268, 1, &rule21},-	{1269, 1, &rule22},-	{1270, 1, &rule21},-	{1271, 1, &rule22},-	{1272, 1, &rule21},-	{1273, 1, &rule22},-	{1274, 1, &rule21},-	{1275, 1, &rule22},-	{1276, 1, &rule21},-	{1277, 1, &rule22},-	{1278, 1, &rule21},-	{1279, 1, &rule22},-	{1280, 1, &rule21},-	{1281, 1, &rule22},-	{1282, 1, &rule21},-	{1283, 1, &rule22},-	{1284, 1, &rule21},-	{1285, 1, &rule22},-	{1286, 1, &rule21},-	{1287, 1, &rule22},-	{1288, 1, &rule21},-	{1289, 1, &rule22},-	{1290, 1, &rule21},-	{1291, 1, &rule22},-	{1292, 1, &rule21},-	{1293, 1, &rule22},-	{1294, 1, &rule21},-	{1295, 1, &rule22},-	{1296, 1, &rule21},-	{1297, 1, &rule22},-	{1298, 1, &rule21},-	{1299, 1, &rule22},-	{1300, 1, &rule21},-	{1301, 1, &rule22},-	{1302, 1, &rule21},-	{1303, 1, &rule22},-	{1304, 1, &rule21},-	{1305, 1, &rule22},-	{1306, 1, &rule21},-	{1307, 1, &rule22},-	{1308, 1, &rule21},-	{1309, 1, &rule22},-	{1310, 1, &rule21},-	{1311, 1, &rule22},-	{1312, 1, &rule21},-	{1313, 1, &rule22},-	{1314, 1, &rule21},-	{1315, 1, &rule22},-	{1316, 1, &rule21},-	{1317, 1, &rule22},-	{1318, 1, &rule21},-	{1319, 1, &rule22},-	{1329, 38, &rule112},-	{1377, 38, &rule113},-	{4256, 38, &rule115},-	{7545, 1, &rule117},-	{7549, 1, &rule118},-	{7680, 1, &rule21},-	{7681, 1, &rule22},-	{7682, 1, &rule21},-	{7683, 1, &rule22},-	{7684, 1, &rule21},-	{7685, 1, &rule22},-	{7686, 1, &rule21},-	{7687, 1, &rule22},-	{7688, 1, &rule21},-	{7689, 1, &rule22},-	{7690, 1, &rule21},-	{7691, 1, &rule22},-	{7692, 1, &rule21},-	{7693, 1, &rule22},-	{7694, 1, &rule21},-	{7695, 1, &rule22},-	{7696, 1, &rule21},-	{7697, 1, &rule22},-	{7698, 1, &rule21},-	{7699, 1, &rule22},-	{7700, 1, &rule21},-	{7701, 1, &rule22},-	{7702, 1, &rule21},-	{7703, 1, &rule22},-	{7704, 1, &rule21},-	{7705, 1, &rule22},-	{7706, 1, &rule21},-	{7707, 1, &rule22},-	{7708, 1, &rule21},-	{7709, 1, &rule22},-	{7710, 1, &rule21},-	{7711, 1, &rule22},-	{7712, 1, &rule21},-	{7713, 1, &rule22},-	{7714, 1, &rule21},-	{7715, 1, &rule22},-	{7716, 1, &rule21},-	{7717, 1, &rule22},-	{7718, 1, &rule21},-	{7719, 1, &rule22},-	{7720, 1, &rule21},-	{7721, 1, &rule22},-	{7722, 1, &rule21},-	{7723, 1, &rule22},-	{7724, 1, &rule21},-	{7725, 1, &rule22},-	{7726, 1, &rule21},-	{7727, 1, &rule22},-	{7728, 1, &rule21},-	{7729, 1, &rule22},-	{7730, 1, &rule21},-	{7731, 1, &rule22},-	{7732, 1, &rule21},-	{7733, 1, &rule22},-	{7734, 1, &rule21},-	{7735, 1, &rule22},-	{7736, 1, &rule21},-	{7737, 1, &rule22},-	{7738, 1, &rule21},-	{7739, 1, &rule22},-	{7740, 1, &rule21},-	{7741, 1, &rule22},-	{7742, 1, &rule21},-	{7743, 1, &rule22},-	{7744, 1, &rule21},-	{7745, 1, &rule22},-	{7746, 1, &rule21},-	{7747, 1, &rule22},-	{7748, 1, &rule21},-	{7749, 1, &rule22},-	{7750, 1, &rule21},-	{7751, 1, &rule22},-	{7752, 1, &rule21},-	{7753, 1, &rule22},-	{7754, 1, &rule21},-	{7755, 1, &rule22},-	{7756, 1, &rule21},-	{7757, 1, &rule22},-	{7758, 1, &rule21},-	{7759, 1, &rule22},-	{7760, 1, &rule21},-	{7761, 1, &rule22},-	{7762, 1, &rule21},-	{7763, 1, &rule22},-	{7764, 1, &rule21},-	{7765, 1, &rule22},-	{7766, 1, &rule21},-	{7767, 1, &rule22},-	{7768, 1, &rule21},-	{7769, 1, &rule22},-	{7770, 1, &rule21},-	{7771, 1, &rule22},-	{7772, 1, &rule21},-	{7773, 1, &rule22},-	{7774, 1, &rule21},-	{7775, 1, &rule22},-	{7776, 1, &rule21},-	{7777, 1, &rule22},-	{7778, 1, &rule21},-	{7779, 1, &rule22},-	{7780, 1, &rule21},-	{7781, 1, &rule22},-	{7782, 1, &rule21},-	{7783, 1, &rule22},-	{7784, 1, &rule21},-	{7785, 1, &rule22},-	{7786, 1, &rule21},-	{7787, 1, &rule22},-	{7788, 1, &rule21},-	{7789, 1, &rule22},-	{7790, 1, &rule21},-	{7791, 1, &rule22},-	{7792, 1, &rule21},-	{7793, 1, &rule22},-	{7794, 1, &rule21},-	{7795, 1, &rule22},-	{7796, 1, &rule21},-	{7797, 1, &rule22},-	{7798, 1, &rule21},-	{7799, 1, &rule22},-	{7800, 1, &rule21},-	{7801, 1, &rule22},-	{7802, 1, &rule21},-	{7803, 1, &rule22},-	{7804, 1, &rule21},-	{7805, 1, &rule22},-	{7806, 1, &rule21},-	{7807, 1, &rule22},-	{7808, 1, &rule21},-	{7809, 1, &rule22},-	{7810, 1, &rule21},-	{7811, 1, &rule22},-	{7812, 1, &rule21},-	{7813, 1, &rule22},-	{7814, 1, &rule21},-	{7815, 1, &rule22},-	{7816, 1, &rule21},-	{7817, 1, &rule22},-	{7818, 1, &rule21},-	{7819, 1, &rule22},-	{7820, 1, &rule21},-	{7821, 1, &rule22},-	{7822, 1, &rule21},-	{7823, 1, &rule22},-	{7824, 1, &rule21},-	{7825, 1, &rule22},-	{7826, 1, &rule21},-	{7827, 1, &rule22},-	{7828, 1, &rule21},-	{7829, 1, &rule22},-	{7835, 1, &rule119},-	{7838, 1, &rule120},-	{7840, 1, &rule21},-	{7841, 1, &rule22},-	{7842, 1, &rule21},-	{7843, 1, &rule22},-	{7844, 1, &rule21},-	{7845, 1, &rule22},-	{7846, 1, &rule21},-	{7847, 1, &rule22},-	{7848, 1, &rule21},-	{7849, 1, &rule22},-	{7850, 1, &rule21},-	{7851, 1, &rule22},-	{7852, 1, &rule21},-	{7853, 1, &rule22},-	{7854, 1, &rule21},-	{7855, 1, &rule22},-	{7856, 1, &rule21},-	{7857, 1, &rule22},-	{7858, 1, &rule21},-	{7859, 1, &rule22},-	{7860, 1, &rule21},-	{7861, 1, &rule22},-	{7862, 1, &rule21},-	{7863, 1, &rule22},-	{7864, 1, &rule21},-	{7865, 1, &rule22},-	{7866, 1, &rule21},-	{7867, 1, &rule22},-	{7868, 1, &rule21},-	{7869, 1, &rule22},-	{7870, 1, &rule21},-	{7871, 1, &rule22},-	{7872, 1, &rule21},-	{7873, 1, &rule22},-	{7874, 1, &rule21},-	{7875, 1, &rule22},-	{7876, 1, &rule21},-	{7877, 1, &rule22},-	{7878, 1, &rule21},-	{7879, 1, &rule22},-	{7880, 1, &rule21},-	{7881, 1, &rule22},-	{7882, 1, &rule21},-	{7883, 1, &rule22},-	{7884, 1, &rule21},-	{7885, 1, &rule22},-	{7886, 1, &rule21},-	{7887, 1, &rule22},-	{7888, 1, &rule21},-	{7889, 1, &rule22},-	{7890, 1, &rule21},-	{7891, 1, &rule22},-	{7892, 1, &rule21},-	{7893, 1, &rule22},-	{7894, 1, &rule21},-	{7895, 1, &rule22},-	{7896, 1, &rule21},-	{7897, 1, &rule22},-	{7898, 1, &rule21},-	{7899, 1, &rule22},-	{7900, 1, &rule21},-	{7901, 1, &rule22},-	{7902, 1, &rule21},-	{7903, 1, &rule22},-	{7904, 1, &rule21},-	{7905, 1, &rule22},-	{7906, 1, &rule21},-	{7907, 1, &rule22},-	{7908, 1, &rule21},-	{7909, 1, &rule22},-	{7910, 1, &rule21},-	{7911, 1, &rule22},-	{7912, 1, &rule21},-	{7913, 1, &rule22},-	{7914, 1, &rule21},-	{7915, 1, &rule22},-	{7916, 1, &rule21},-	{7917, 1, &rule22},-	{7918, 1, &rule21},-	{7919, 1, &rule22},-	{7920, 1, &rule21},-	{7921, 1, &rule22},-	{7922, 1, &rule21},-	{7923, 1, &rule22},-	{7924, 1, &rule21},-	{7925, 1, &rule22},-	{7926, 1, &rule21},-	{7927, 1, &rule22},-	{7928, 1, &rule21},-	{7929, 1, &rule22},-	{7930, 1, &rule21},-	{7931, 1, &rule22},-	{7932, 1, &rule21},-	{7933, 1, &rule22},-	{7934, 1, &rule21},-	{7935, 1, &rule22},-	{7936, 8, &rule121},-	{7944, 8, &rule122},-	{7952, 6, &rule121},-	{7960, 6, &rule122},-	{7968, 8, &rule121},-	{7976, 8, &rule122},-	{7984, 8, &rule121},-	{7992, 8, &rule122},-	{8000, 6, &rule121},-	{8008, 6, &rule122},-	{8017, 1, &rule121},-	{8019, 1, &rule121},-	{8021, 1, &rule121},-	{8023, 1, &rule121},-	{8025, 1, &rule122},-	{8027, 1, &rule122},-	{8029, 1, &rule122},-	{8031, 1, &rule122},-	{8032, 8, &rule121},-	{8040, 8, &rule122},-	{8048, 2, &rule123},-	{8050, 4, &rule124},-	{8054, 2, &rule125},-	{8056, 2, &rule126},-	{8058, 2, &rule127},-	{8060, 2, &rule128},-	{8064, 8, &rule121},-	{8072, 8, &rule129},-	{8080, 8, &rule121},-	{8088, 8, &rule129},-	{8096, 8, &rule121},-	{8104, 8, &rule129},-	{8112, 2, &rule121},-	{8115, 1, &rule130},-	{8120, 2, &rule122},-	{8122, 2, &rule131},-	{8124, 1, &rule132},-	{8126, 1, &rule133},-	{8131, 1, &rule130},-	{8136, 4, &rule134},-	{8140, 1, &rule132},-	{8144, 2, &rule121},-	{8152, 2, &rule122},-	{8154, 2, &rule135},-	{8160, 2, &rule121},-	{8165, 1, &rule104},-	{8168, 2, &rule122},-	{8170, 2, &rule136},-	{8172, 1, &rule107},-	{8179, 1, &rule130},-	{8184, 2, &rule137},-	{8186, 2, &rule138},-	{8188, 1, &rule132},-	{8486, 1, &rule141},-	{8490, 1, &rule142},-	{8491, 1, &rule143},-	{8498, 1, &rule144},-	{8526, 1, &rule145},-	{8544, 16, &rule146},-	{8560, 16, &rule147},-	{8579, 1, &rule21},-	{8580, 1, &rule22},-	{9398, 26, &rule148},-	{9424, 26, &rule149},-	{11264, 47, &rule112},-	{11312, 47, &rule113},-	{11360, 1, &rule21},-	{11361, 1, &rule22},-	{11362, 1, &rule150},-	{11363, 1, &rule151},-	{11364, 1, &rule152},-	{11365, 1, &rule153},-	{11366, 1, &rule154},-	{11367, 1, &rule21},-	{11368, 1, &rule22},-	{11369, 1, &rule21},-	{11370, 1, &rule22},-	{11371, 1, &rule21},-	{11372, 1, &rule22},-	{11373, 1, &rule155},-	{11374, 1, &rule156},-	{11375, 1, &rule157},-	{11376, 1, &rule158},-	{11378, 1, &rule21},-	{11379, 1, &rule22},-	{11381, 1, &rule21},-	{11382, 1, &rule22},-	{11390, 2, &rule159},-	{11392, 1, &rule21},-	{11393, 1, &rule22},-	{11394, 1, &rule21},-	{11395, 1, &rule22},-	{11396, 1, &rule21},-	{11397, 1, &rule22},-	{11398, 1, &rule21},-	{11399, 1, &rule22},-	{11400, 1, &rule21},-	{11401, 1, &rule22},-	{11402, 1, &rule21},-	{11403, 1, &rule22},-	{11404, 1, &rule21},-	{11405, 1, &rule22},-	{11406, 1, &rule21},-	{11407, 1, &rule22},-	{11408, 1, &rule21},-	{11409, 1, &rule22},-	{11410, 1, &rule21},-	{11411, 1, &rule22},-	{11412, 1, &rule21},-	{11413, 1, &rule22},-	{11414, 1, &rule21},-	{11415, 1, &rule22},-	{11416, 1, &rule21},-	{11417, 1, &rule22},-	{11418, 1, &rule21},-	{11419, 1, &rule22},-	{11420, 1, &rule21},-	{11421, 1, &rule22},-	{11422, 1, &rule21},-	{11423, 1, &rule22},-	{11424, 1, &rule21},-	{11425, 1, &rule22},-	{11426, 1, &rule21},-	{11427, 1, &rule22},-	{11428, 1, &rule21},-	{11429, 1, &rule22},-	{11430, 1, &rule21},-	{11431, 1, &rule22},-	{11432, 1, &rule21},-	{11433, 1, &rule22},-	{11434, 1, &rule21},-	{11435, 1, &rule22},-	{11436, 1, &rule21},-	{11437, 1, &rule22},-	{11438, 1, &rule21},-	{11439, 1, &rule22},-	{11440, 1, &rule21},-	{11441, 1, &rule22},-	{11442, 1, &rule21},-	{11443, 1, &rule22},-	{11444, 1, &rule21},-	{11445, 1, &rule22},-	{11446, 1, &rule21},-	{11447, 1, &rule22},-	{11448, 1, &rule21},-	{11449, 1, &rule22},-	{11450, 1, &rule21},-	{11451, 1, &rule22},-	{11452, 1, &rule21},-	{11453, 1, &rule22},-	{11454, 1, &rule21},-	{11455, 1, &rule22},-	{11456, 1, &rule21},-	{11457, 1, &rule22},-	{11458, 1, &rule21},-	{11459, 1, &rule22},-	{11460, 1, &rule21},-	{11461, 1, &rule22},-	{11462, 1, &rule21},-	{11463, 1, &rule22},-	{11464, 1, &rule21},-	{11465, 1, &rule22},-	{11466, 1, &rule21},-	{11467, 1, &rule22},-	{11468, 1, &rule21},-	{11469, 1, &rule22},-	{11470, 1, &rule21},-	{11471, 1, &rule22},-	{11472, 1, &rule21},-	{11473, 1, &rule22},-	{11474, 1, &rule21},-	{11475, 1, &rule22},-	{11476, 1, &rule21},-	{11477, 1, &rule22},-	{11478, 1, &rule21},-	{11479, 1, &rule22},-	{11480, 1, &rule21},-	{11481, 1, &rule22},-	{11482, 1, &rule21},-	{11483, 1, &rule22},-	{11484, 1, &rule21},-	{11485, 1, &rule22},-	{11486, 1, &rule21},-	{11487, 1, &rule22},-	{11488, 1, &rule21},-	{11489, 1, &rule22},-	{11490, 1, &rule21},-	{11491, 1, &rule22},-	{11499, 1, &rule21},-	{11500, 1, &rule22},-	{11501, 1, &rule21},-	{11502, 1, &rule22},-	{11520, 38, &rule160},-	{42560, 1, &rule21},-	{42561, 1, &rule22},-	{42562, 1, &rule21},-	{42563, 1, &rule22},-	{42564, 1, &rule21},-	{42565, 1, &rule22},-	{42566, 1, &rule21},-	{42567, 1, &rule22},-	{42568, 1, &rule21},-	{42569, 1, &rule22},-	{42570, 1, &rule21},-	{42571, 1, &rule22},-	{42572, 1, &rule21},-	{42573, 1, &rule22},-	{42574, 1, &rule21},-	{42575, 1, &rule22},-	{42576, 1, &rule21},-	{42577, 1, &rule22},-	{42578, 1, &rule21},-	{42579, 1, &rule22},-	{42580, 1, &rule21},-	{42581, 1, &rule22},-	{42582, 1, &rule21},-	{42583, 1, &rule22},-	{42584, 1, &rule21},-	{42585, 1, &rule22},-	{42586, 1, &rule21},-	{42587, 1, &rule22},-	{42588, 1, &rule21},-	{42589, 1, &rule22},-	{42590, 1, &rule21},-	{42591, 1, &rule22},-	{42592, 1, &rule21},-	{42593, 1, &rule22},-	{42594, 1, &rule21},-	{42595, 1, &rule22},-	{42596, 1, &rule21},-	{42597, 1, &rule22},-	{42598, 1, &rule21},-	{42599, 1, &rule22},-	{42600, 1, &rule21},-	{42601, 1, &rule22},-	{42602, 1, &rule21},-	{42603, 1, &rule22},-	{42604, 1, &rule21},-	{42605, 1, &rule22},-	{42624, 1, &rule21},-	{42625, 1, &rule22},-	{42626, 1, &rule21},-	{42627, 1, &rule22},-	{42628, 1, &rule21},-	{42629, 1, &rule22},-	{42630, 1, &rule21},-	{42631, 1, &rule22},-	{42632, 1, &rule21},-	{42633, 1, &rule22},-	{42634, 1, &rule21},-	{42635, 1, &rule22},-	{42636, 1, &rule21},-	{42637, 1, &rule22},-	{42638, 1, &rule21},-	{42639, 1, &rule22},-	{42640, 1, &rule21},-	{42641, 1, &rule22},-	{42642, 1, &rule21},-	{42643, 1, &rule22},-	{42644, 1, &rule21},-	{42645, 1, &rule22},-	{42646, 1, &rule21},-	{42647, 1, &rule22},-	{42786, 1, &rule21},-	{42787, 1, &rule22},-	{42788, 1, &rule21},-	{42789, 1, &rule22},-	{42790, 1, &rule21},-	{42791, 1, &rule22},-	{42792, 1, &rule21},-	{42793, 1, &rule22},-	{42794, 1, &rule21},-	{42795, 1, &rule22},-	{42796, 1, &rule21},-	{42797, 1, &rule22},-	{42798, 1, &rule21},-	{42799, 1, &rule22},-	{42802, 1, &rule21},-	{42803, 1, &rule22},-	{42804, 1, &rule21},-	{42805, 1, &rule22},-	{42806, 1, &rule21},-	{42807, 1, &rule22},-	{42808, 1, &rule21},-	{42809, 1, &rule22},-	{42810, 1, &rule21},-	{42811, 1, &rule22},-	{42812, 1, &rule21},-	{42813, 1, &rule22},-	{42814, 1, &rule21},-	{42815, 1, &rule22},-	{42816, 1, &rule21},-	{42817, 1, &rule22},-	{42818, 1, &rule21},-	{42819, 1, &rule22},-	{42820, 1, &rule21},-	{42821, 1, &rule22},-	{42822, 1, &rule21},-	{42823, 1, &rule22},-	{42824, 1, &rule21},-	{42825, 1, &rule22},-	{42826, 1, &rule21},-	{42827, 1, &rule22},-	{42828, 1, &rule21},-	{42829, 1, &rule22},-	{42830, 1, &rule21},-	{42831, 1, &rule22},-	{42832, 1, &rule21},-	{42833, 1, &rule22},-	{42834, 1, &rule21},-	{42835, 1, &rule22},-	{42836, 1, &rule21},-	{42837, 1, &rule22},-	{42838, 1, &rule21},-	{42839, 1, &rule22},-	{42840, 1, &rule21},-	{42841, 1, &rule22},-	{42842, 1, &rule21},-	{42843, 1, &rule22},-	{42844, 1, &rule21},-	{42845, 1, &rule22},-	{42846, 1, &rule21},-	{42847, 1, &rule22},-	{42848, 1, &rule21},-	{42849, 1, &rule22},-	{42850, 1, &rule21},-	{42851, 1, &rule22},-	{42852, 1, &rule21},-	{42853, 1, &rule22},-	{42854, 1, &rule21},-	{42855, 1, &rule22},-	{42856, 1, &rule21},-	{42857, 1, &rule22},-	{42858, 1, &rule21},-	{42859, 1, &rule22},-	{42860, 1, &rule21},-	{42861, 1, &rule22},-	{42862, 1, &rule21},-	{42863, 1, &rule22},-	{42873, 1, &rule21},-	{42874, 1, &rule22},-	{42875, 1, &rule21},-	{42876, 1, &rule22},-	{42877, 1, &rule161},-	{42878, 1, &rule21},-	{42879, 1, &rule22},-	{42880, 1, &rule21},-	{42881, 1, &rule22},-	{42882, 1, &rule21},-	{42883, 1, &rule22},-	{42884, 1, &rule21},-	{42885, 1, &rule22},-	{42886, 1, &rule21},-	{42887, 1, &rule22},-	{42891, 1, &rule21},-	{42892, 1, &rule22},-	{42893, 1, &rule162},-	{42896, 1, &rule21},-	{42897, 1, &rule22},-	{42912, 1, &rule21},-	{42913, 1, &rule22},-	{42914, 1, &rule21},-	{42915, 1, &rule22},-	{42916, 1, &rule21},-	{42917, 1, &rule22},-	{42918, 1, &rule21},-	{42919, 1, &rule22},-	{42920, 1, &rule21},-	{42921, 1, &rule22},-	{65313, 26, &rule9},-	{65345, 26, &rule12},-	{66560, 40, &rule165},-	{66600, 40, &rule166}-};-static const struct _charblock_ spacechars[]={-	{32, 1, &rule1},-	{160, 1, &rule1},-	{5760, 1, &rule1},-	{6158, 1, &rule1},-	{8192, 11, &rule1},-	{8239, 1, &rule1},-	{8287, 1, &rule1},-	{12288, 1, &rule1}-};--/*-	Obtain the reference to character rule by doing-	binary search over the specified array of blocks.-	To make checkattr shorter, the address of-	nullrule is returned if the search fails:-	this rule defines no category and no conversion-	distances. The compare function returns 0 when-	key->start is within the block. Otherwise-	result of comparison of key->start and start of the-	current block is returned as usual.-*/--static const struct _convrule_ nullrule={0,NUMCAT_CN,0,0,0,0};--int blkcmp(const void *vk,const void *vb)-{-	const struct _charblock_ *key,*cur;-	key=vk;-	cur=vb;-	if((key->start>=cur->start)&&(key->start<(cur->start+cur->length)))-	{-		return 0;-	}-	if(key->start>cur->start) return 1;-	return -1;-}--static const struct _convrule_ *getrule(-	const struct _charblock_ *blocks,-	int numblocks,-	int unichar)-{-	struct _charblock_ key={unichar,1,(void *)0};-	struct _charblock_ *cb=bsearch(&key,blocks,numblocks,sizeof(key),blkcmp);-	if(cb==(void *)0) return &nullrule;-	return cb->rule;-}-	---/*-	Check whether a character (internal code) has certain attributes.-	Attributes (category flags) may be ORed. The function ANDs-	character category flags and the mask and returns the result.-	If the character belongs to one of the categories requested,-	the result will be nonzero.-*/--inline static int checkattr(int c,unsigned int catmask)-{-	return (catmask & (getrule(allchars,(c<256)?NUM_LAT1BLOCKS:NUM_BLOCKS,c)->category));-}--inline static int checkattr_s(int c,unsigned int catmask)-{-        return (catmask & (getrule(spacechars,NUM_SPACEBLOCKS,c)->category));-}--/*-	Define predicate functions for some combinations of categories.-*/--#define unipred(p,m) \-int p(int c) \-{ \-	return checkattr(c,m); \-}--#define unipred_s(p,m) \-int p(int c) \-{ \-        return checkattr_s(c,m); \-}--/*-	Make these rules as close to Hugs as possible.-*/--unipred(u_iswcntrl,GENCAT_CC)-unipred(u_iswprint, (GENCAT_MC | GENCAT_NO | GENCAT_SK | GENCAT_ME | GENCAT_ND |   GENCAT_PO | GENCAT_LT | GENCAT_PC | GENCAT_SM | GENCAT_ZS |   GENCAT_LU | GENCAT_PD | GENCAT_SO | GENCAT_PE | GENCAT_PF |   GENCAT_PS | GENCAT_SC | GENCAT_LL | GENCAT_LM | GENCAT_PI |   GENCAT_NL | GENCAT_MN | GENCAT_LO))-unipred_s(u_iswspace,GENCAT_ZS)-unipred(u_iswupper,(GENCAT_LU|GENCAT_LT))-unipred(u_iswlower,GENCAT_LL)-unipred(u_iswalpha,(GENCAT_LL|GENCAT_LU|GENCAT_LT|GENCAT_LM|GENCAT_LO))-unipred(u_iswdigit,GENCAT_ND)--unipred(u_iswalnum,(GENCAT_LT|GENCAT_LU|GENCAT_LL|GENCAT_LM|GENCAT_LO|-		    GENCAT_MC|GENCAT_ME|GENCAT_MN|-		    GENCAT_NO|GENCAT_ND|GENCAT_NL))--#define caseconv(p,to) \-int p(int c) \-{ \-	const struct _convrule_ *rule=getrule(convchars,NUM_CONVBLOCKS,c);\-	if(rule==&nullrule) return c;\-	return c+rule->to;\-}--caseconv(u_towupper,updist)-caseconv(u_towlower,lowdist)-caseconv(u_towtitle,titledist)--int u_gencat(int c)+Generated by ubconfc at Wed Oct 15 14:24:39 EDT 2014+@generated+-------------------------------------------------------------------------*/++#include "WCsubst.h"++/* Unicode general categories, listed in the same order as in the Unicode+ * standard -- this must be the same order as in GHC.Unicode.+ */++enum {+    NUMCAT_LU,  /* Letter, Uppercase */+    NUMCAT_LL,  /* Letter, Lowercase */+    NUMCAT_LT,  /* Letter, Titlecase */+    NUMCAT_LM,  /* Letter, Modifier */+    NUMCAT_LO,  /* Letter, Other */+    NUMCAT_MN,  /* Mark, Non-Spacing */+    NUMCAT_MC,  /* Mark, Spacing Combining */+    NUMCAT_ME,  /* Mark, Enclosing */+    NUMCAT_ND,  /* Number, Decimal */+    NUMCAT_NL,  /* Number, Letter */+    NUMCAT_NO,  /* Number, Other */+    NUMCAT_PC,  /* Punctuation, Connector */+    NUMCAT_PD,  /* Punctuation, Dash */+    NUMCAT_PS,  /* Punctuation, Open */+    NUMCAT_PE,  /* Punctuation, Close */+    NUMCAT_PI,  /* Punctuation, Initial quote */+    NUMCAT_PF,  /* Punctuation, Final quote */+    NUMCAT_PO,  /* Punctuation, Other */+    NUMCAT_SM,  /* Symbol, Math */+    NUMCAT_SC,  /* Symbol, Currency */+    NUMCAT_SK,  /* Symbol, Modifier */+    NUMCAT_SO,  /* Symbol, Other */+    NUMCAT_ZS,  /* Separator, Space */+    NUMCAT_ZL,  /* Separator, Line */+    NUMCAT_ZP,  /* Separator, Paragraph */+    NUMCAT_CC,  /* Other, Control */+    NUMCAT_CF,  /* Other, Format */+    NUMCAT_CS,  /* Other, Surrogate */+    NUMCAT_CO,  /* Other, Private Use */+    NUMCAT_CN   /* Other, Not Assigned */+};++struct _convrule_ +{ +	unsigned int category;+	unsigned int catnumber;+	int possible;+	int updist;+	int lowdist; +	int titledist;+};++struct _charblock_ +{ +	int start;+	int length;+	const struct _convrule_ *rule;+};++#define GENCAT_ZP 67108864+#define GENCAT_MC 8388608+#define GENCAT_NO 131072+#define GENCAT_SK 1024+#define GENCAT_CO 268435456+#define GENCAT_ME 4194304+#define GENCAT_ND 256+#define GENCAT_PO 4+#define GENCAT_LT 524288+#define GENCAT_PC 2048+#define GENCAT_SM 64+#define GENCAT_ZS 2+#define GENCAT_CC 1+#define GENCAT_LU 512+#define GENCAT_PD 128+#define GENCAT_SO 8192+#define GENCAT_PE 32+#define GENCAT_CS 134217728+#define GENCAT_PF 262144+#define GENCAT_CF 65536+#define GENCAT_PS 16+#define GENCAT_SC 8+#define GENCAT_LL 4096+#define GENCAT_ZL 33554432+#define GENCAT_LM 1048576+#define GENCAT_PI 32768+#define GENCAT_NL 16777216+#define GENCAT_MN 2097152+#define GENCAT_LO 16384+#define MAX_UNI_CHAR 1114109+#define NUM_BLOCKS 3073+#define NUM_CONVBLOCKS 1276+#define NUM_SPACEBLOCKS 7+#define NUM_LAT1BLOCKS 63+#define NUM_RULES 181+static const struct _convrule_ rule169={GENCAT_LU, NUMCAT_LU, 1, 0, -35332, 0};+static const struct _convrule_ rule157={GENCAT_SO, NUMCAT_SO, 1, -26, 0, -26};+static const struct _convrule_ rule168={GENCAT_LL, NUMCAT_LL, 1, -7264, 0, -7264};+static const struct _convrule_ rule173={GENCAT_LU, NUMCAT_LU, 1, 0, -42315, 0};+static const struct _convrule_ rule129={GENCAT_LL, NUMCAT_LL, 1, 8, 0, 8};+static const struct _convrule_ rule88={GENCAT_LL, NUMCAT_LL, 1, 42258, 0, 42258};+static const struct _convrule_ rule20={GENCAT_LL, NUMCAT_LL, 0, 0, 0, 0};+static const struct _convrule_ rule76={GENCAT_LL, NUMCAT_LL, 1, 10743, 0, 10743};+static const struct _convrule_ rule61={GENCAT_LL, NUMCAT_LL, 1, 10783, 0, 10783};+static const struct _convrule_ rule37={GENCAT_LU, NUMCAT_LU, 1, 0, 211, 0};+static const struct _convrule_ rule80={GENCAT_LL, NUMCAT_LL, 1, -214, 0, -214};+static const struct _convrule_ rule75={GENCAT_LL, NUMCAT_LL, 1, -211, 0, -211};+static const struct _convrule_ rule121={GENCAT_LL, NUMCAT_LL, 1, -48, 0, -48};+static const struct _convrule_ rule52={GENCAT_LU, NUMCAT_LU, 1, 0, -56, 0};+static const struct _convrule_ rule135={GENCAT_LL, NUMCAT_LL, 1, 112, 0, 112};+static const struct _convrule_ rule71={GENCAT_LL, NUMCAT_LL, 1, -207, 0, -207};+static const struct _convrule_ rule123={GENCAT_LU, NUMCAT_LU, 1, 0, 7264, 0};+static const struct _convrule_ rule152={GENCAT_LU, NUMCAT_LU, 1, 0, 28, 0};+static const struct _convrule_ rule159={GENCAT_LU, NUMCAT_LU, 1, 0, -3814, 0};+static const struct _convrule_ rule45={GENCAT_LU, NUMCAT_LU, 1, 0, 219, 0};+static const struct _convrule_ rule7={GENCAT_PD, NUMCAT_PD, 0, 0, 0, 0};+static const struct _convrule_ rule180={GENCAT_LL, NUMCAT_LL, 1, -40, 0, -40};+static const struct _convrule_ rule97={GENCAT_LL, NUMCAT_LL, 1, -38, 0, -38};+static const struct _convrule_ rule95={GENCAT_LU, NUMCAT_LU, 1, 0, 64, 0};+static const struct _convrule_ rule1={GENCAT_ZS, NUMCAT_ZS, 0, 0, 0, 0};+static const struct _convrule_ rule29={GENCAT_LU, NUMCAT_LU, 1, 0, 210, 0};+static const struct _convrule_ rule35={GENCAT_LU, NUMCAT_LU, 1, 0, 207, 0};+static const struct _convrule_ rule154={GENCAT_NL, NUMCAT_NL, 1, 0, 16, 0};+static const struct _convrule_ rule13={GENCAT_SO, NUMCAT_SO, 0, 0, 0, 0};+static const struct _convrule_ rule149={GENCAT_LU, NUMCAT_LU, 1, 0, -7517, 0};+static const struct _convrule_ rule128={GENCAT_LU, NUMCAT_LU, 1, 0, -7615, 0};+static const struct _convrule_ rule98={GENCAT_LL, NUMCAT_LL, 1, -37, 0, -37};+static const struct _convrule_ rule2={GENCAT_PO, NUMCAT_PO, 0, 0, 0, 0};+static const struct _convrule_ rule69={GENCAT_LL, NUMCAT_LL, 1, 42319, 0, 42319};+static const struct _convrule_ rule56={GENCAT_LU, NUMCAT_LU, 1, 0, 10792, 0};+static const struct _convrule_ rule25={GENCAT_LL, NUMCAT_LL, 1, -232, 0, -232};+static const struct _convrule_ rule43={GENCAT_LU, NUMCAT_LU, 1, 0, 218, 0};+static const struct _convrule_ rule165={GENCAT_LU, NUMCAT_LU, 1, 0, -10783, 0};+static const struct _convrule_ rule133={GENCAT_LL, NUMCAT_LL, 1, 100, 0, 100};+static const struct _convrule_ rule96={GENCAT_LU, NUMCAT_LU, 1, 0, 63, 0};+static const struct _convrule_ rule90={GENCAT_MN, NUMCAT_MN, 0, 0, 0, 0};+static const struct _convrule_ rule12={GENCAT_LL, NUMCAT_LL, 1, -32, 0, -32};+static const struct _convrule_ rule93={GENCAT_LU, NUMCAT_LU, 1, 0, 38, 0};+static const struct _convrule_ rule99={GENCAT_LL, NUMCAT_LL, 1, -31, 0, -31};+static const struct _convrule_ rule105={GENCAT_LU, NUMCAT_LU, 0, 0, 0, 0};+static const struct _convrule_ rule11={GENCAT_PC, NUMCAT_PC, 0, 0, 0, 0};+static const struct _convrule_ rule175={GENCAT_LU, NUMCAT_LU, 1, 0, -42258, 0};+static const struct _convrule_ rule144={GENCAT_LU, NUMCAT_LU, 1, 0, -112, 0};+static const struct _convrule_ rule15={GENCAT_PI, NUMCAT_PI, 0, 0, 0, 0};+static const struct _convrule_ rule132={GENCAT_LL, NUMCAT_LL, 1, 86, 0, 86};+static const struct _convrule_ rule122={GENCAT_MC, NUMCAT_MC, 0, 0, 0, 0};+static const struct _convrule_ rule126={GENCAT_LL, NUMCAT_LL, 1, 3814, 0, 3814};+static const struct _convrule_ rule44={GENCAT_LU, NUMCAT_LU, 1, 0, 217, 0};+static const struct _convrule_ rule153={GENCAT_LL, NUMCAT_LL, 1, -28, 0, -28};+static const struct _convrule_ rule178={GENCAT_CO, NUMCAT_CO, 0, 0, 0, 0};+static const struct _convrule_ rule114={GENCAT_LL, NUMCAT_LL, 1, -96, 0, -96};+static const struct _convrule_ rule51={GENCAT_LU, NUMCAT_LU, 1, 0, -97, 0};+static const struct _convrule_ rule39={GENCAT_LL, NUMCAT_LL, 1, 163, 0, 163};+static const struct _convrule_ rule179={GENCAT_LU, NUMCAT_LU, 1, 0, 40, 0};+static const struct _convrule_ rule124={GENCAT_NL, NUMCAT_NL, 0, 0, 0, 0};+static const struct _convrule_ rule94={GENCAT_LU, NUMCAT_LU, 1, 0, 37, 0};+static const struct _convrule_ rule82={GENCAT_LL, NUMCAT_LL, 1, -218, 0, -218};+static const struct _convrule_ rule118={GENCAT_LU, NUMCAT_LU, 1, 0, 15, 0};+static const struct _convrule_ rule67={GENCAT_LL, NUMCAT_LL, 1, -202, 0, -202};+static const struct _convrule_ rule66={GENCAT_LL, NUMCAT_LL, 1, -205, 0, -205};+static const struct _convrule_ rule47={GENCAT_LU, NUMCAT_LU, 1, 0, 2, 1};+static const struct _convrule_ rule30={GENCAT_LU, NUMCAT_LU, 1, 0, 206, 0};+static const struct _convrule_ rule109={GENCAT_LL, NUMCAT_LL, 1, -86, 0, -86};+static const struct _convrule_ rule4={GENCAT_PS, NUMCAT_PS, 0, 0, 0, 0};+static const struct _convrule_ rule3={GENCAT_SC, NUMCAT_SC, 0, 0, 0, 0};+static const struct _convrule_ rule150={GENCAT_LU, NUMCAT_LU, 1, 0, -8383, 0};+static const struct _convrule_ rule120={GENCAT_LU, NUMCAT_LU, 1, 0, 48, 0};+static const struct _convrule_ rule14={GENCAT_LO, NUMCAT_LO, 0, 0, 0, 0};+static const struct _convrule_ rule18={GENCAT_LL, NUMCAT_LL, 1, 743, 0, 743};+static const struct _convrule_ rule147={GENCAT_ZL, NUMCAT_ZL, 0, 0, 0, 0};+static const struct _convrule_ rule142={GENCAT_LU, NUMCAT_LU, 1, 0, -86, 0};+static const struct _convrule_ rule171={GENCAT_LU, NUMCAT_LU, 1, 0, -42308, 0};+static const struct _convrule_ rule162={GENCAT_LL, NUMCAT_LL, 1, -10792, 0, -10792};+static const struct _convrule_ rule166={GENCAT_LU, NUMCAT_LU, 1, 0, -10782, 0};+static const struct _convrule_ rule139={GENCAT_LU, NUMCAT_LU, 1, 0, -74, 0};+static const struct _convrule_ rule24={GENCAT_LU, NUMCAT_LU, 1, 0, -199, 0};+static const struct _convrule_ rule143={GENCAT_LU, NUMCAT_LU, 1, 0, -100, 0};+static const struct _convrule_ rule125={GENCAT_LL, NUMCAT_LL, 1, 35332, 0, 35332};+static const struct _convrule_ rule141={GENCAT_LL, NUMCAT_LL, 1, -7205, 0, -7205};+static const struct _convrule_ rule138={GENCAT_LL, NUMCAT_LL, 1, 9, 0, 9};+static const struct _convrule_ rule27={GENCAT_LL, NUMCAT_LL, 1, -300, 0, -300};+static const struct _convrule_ rule172={GENCAT_LU, NUMCAT_LU, 1, 0, -42319, 0};+static const struct _convrule_ rule31={GENCAT_LU, NUMCAT_LU, 1, 0, 205, 0};+static const struct _convrule_ rule59={GENCAT_LU, NUMCAT_LU, 1, 0, 69, 0};+static const struct _convrule_ rule6={GENCAT_SM, NUMCAT_SM, 0, 0, 0, 0};+static const struct _convrule_ rule119={GENCAT_LL, NUMCAT_LL, 1, -15, 0, -15};+static const struct _convrule_ rule110={GENCAT_LL, NUMCAT_LL, 1, -80, 0, -80};+static const struct _convrule_ rule176={GENCAT_LU, NUMCAT_LU, 1, 0, -42282, 0};+static const struct _convrule_ rule151={GENCAT_LU, NUMCAT_LU, 1, 0, -8262, 0};+static const struct _convrule_ rule130={GENCAT_LU, NUMCAT_LU, 1, 0, -8, 0};+static const struct _convrule_ rule26={GENCAT_LU, NUMCAT_LU, 1, 0, -121, 0};+static const struct _convrule_ rule0={GENCAT_CC, NUMCAT_CC, 0, 0, 0, 0};+static const struct _convrule_ rule111={GENCAT_LL, NUMCAT_LL, 1, 7, 0, 7};+static const struct _convrule_ rule91={GENCAT_MN, NUMCAT_MN, 1, 84, 0, 84};+static const struct _convrule_ rule78={GENCAT_LL, NUMCAT_LL, 1, 10749, 0, 10749};+static const struct _convrule_ rule77={GENCAT_LL, NUMCAT_LL, 1, 42305, 0, 42305};+static const struct _convrule_ rule70={GENCAT_LL, NUMCAT_LL, 1, 42315, 0, 42315};+static const struct _convrule_ rule50={GENCAT_LL, NUMCAT_LL, 1, -79, 0, -79};+static const struct _convrule_ rule60={GENCAT_LU, NUMCAT_LU, 1, 0, 71, 0};+static const struct _convrule_ rule22={GENCAT_LU, NUMCAT_LU, 1, 0, 1, 0};+static const struct _convrule_ rule49={GENCAT_LL, NUMCAT_LL, 1, -2, 0, -1};+static const struct _convrule_ rule92={GENCAT_LU, NUMCAT_LU, 1, 0, 116, 0};+static const struct _convrule_ rule83={GENCAT_LL, NUMCAT_LL, 1, 42282, 0, 42282};+static const struct _convrule_ rule155={GENCAT_NL, NUMCAT_NL, 1, -16, 0, -16};+static const struct _convrule_ rule102={GENCAT_LU, NUMCAT_LU, 1, 0, 8, 0};+static const struct _convrule_ rule23={GENCAT_LL, NUMCAT_LL, 1, -1, 0, -1};+static const struct _convrule_ rule87={GENCAT_LL, NUMCAT_LL, 1, -219, 0, -219};+static const struct _convrule_ rule79={GENCAT_LL, NUMCAT_LL, 1, -213, 0, -213};+static const struct _convrule_ rule64={GENCAT_LL, NUMCAT_LL, 1, -210, 0, -210};+static const struct _convrule_ rule163={GENCAT_LU, NUMCAT_LU, 1, 0, -10780, 0};+static const struct _convrule_ rule86={GENCAT_LL, NUMCAT_LL, 1, -71, 0, -71};+static const struct _convrule_ rule84={GENCAT_LL, NUMCAT_LL, 1, -69, 0, -69};+static const struct _convrule_ rule32={GENCAT_LU, NUMCAT_LU, 1, 0, 79, 0};+static const struct _convrule_ rule115={GENCAT_LU, NUMCAT_LU, 1, 0, -7, 0};+static const struct _convrule_ rule74={GENCAT_LL, NUMCAT_LL, 1, -209, 0, -209};+static const struct _convrule_ rule177={GENCAT_CS, NUMCAT_CS, 0, 0, 0, 0};+static const struct _convrule_ rule140={GENCAT_LT, NUMCAT_LT, 1, 0, -9, 0};+static const struct _convrule_ rule57={GENCAT_LL, NUMCAT_LL, 1, 10815, 0, 10815};+static const struct _convrule_ rule72={GENCAT_LL, NUMCAT_LL, 1, 42280, 0, 42280};+static const struct _convrule_ rule34={GENCAT_LU, NUMCAT_LU, 1, 0, 203, 0};+static const struct _convrule_ rule63={GENCAT_LL, NUMCAT_LL, 1, 10782, 0, 10782};+static const struct _convrule_ rule170={GENCAT_LU, NUMCAT_LU, 1, 0, -42280, 0};+static const struct _convrule_ rule145={GENCAT_LU, NUMCAT_LU, 1, 0, -128, 0};+static const struct _convrule_ rule100={GENCAT_LL, NUMCAT_LL, 1, -64, 0, -64};+static const struct _convrule_ rule17={GENCAT_NO, NUMCAT_NO, 0, 0, 0, 0};+static const struct _convrule_ rule89={GENCAT_LM, NUMCAT_LM, 0, 0, 0, 0};+static const struct _convrule_ rule46={GENCAT_LL, NUMCAT_LL, 1, 56, 0, 56};+static const struct _convrule_ rule131={GENCAT_LL, NUMCAT_LL, 1, 74, 0, 74};+static const struct _convrule_ rule42={GENCAT_LU, NUMCAT_LU, 1, 0, 214, 0};+static const struct _convrule_ rule148={GENCAT_ZP, NUMCAT_ZP, 0, 0, 0, 0};+static const struct _convrule_ rule101={GENCAT_LL, NUMCAT_LL, 1, -63, 0, -63};+static const struct _convrule_ rule36={GENCAT_LL, NUMCAT_LL, 1, 97, 0, 97};+static const struct _convrule_ rule137={GENCAT_LT, NUMCAT_LT, 1, 0, -8, 0};+static const struct _convrule_ rule134={GENCAT_LL, NUMCAT_LL, 1, 128, 0, 128};+static const struct _convrule_ rule81={GENCAT_LL, NUMCAT_LL, 1, 10727, 0, 10727};+static const struct _convrule_ rule62={GENCAT_LL, NUMCAT_LL, 1, 10780, 0, 10780};+static const struct _convrule_ rule41={GENCAT_LL, NUMCAT_LL, 1, 130, 0, 130};+static const struct _convrule_ rule68={GENCAT_LL, NUMCAT_LL, 1, -203, 0, -203};+static const struct _convrule_ rule65={GENCAT_LL, NUMCAT_LL, 1, -206, 0, -206};+static const struct _convrule_ rule48={GENCAT_LT, NUMCAT_LT, 1, -1, 1, 0};+static const struct _convrule_ rule19={GENCAT_PF, NUMCAT_PF, 0, 0, 0, 0};+static const struct _convrule_ rule33={GENCAT_LU, NUMCAT_LU, 1, 0, 202, 0};+static const struct _convrule_ rule103={GENCAT_LL, NUMCAT_LL, 1, -62, 0, -62};+static const struct _convrule_ rule8={GENCAT_ND, NUMCAT_ND, 0, 0, 0, 0};+static const struct _convrule_ rule53={GENCAT_LU, NUMCAT_LU, 1, 0, -130, 0};+static const struct _convrule_ rule28={GENCAT_LL, NUMCAT_LL, 1, 195, 0, 195};+static const struct _convrule_ rule158={GENCAT_LU, NUMCAT_LU, 1, 0, -10743, 0};+static const struct _convrule_ rule127={GENCAT_LL, NUMCAT_LL, 1, -59, 0, -59};+static const struct _convrule_ rule113={GENCAT_LU, NUMCAT_LU, 1, 0, -60, 0};+static const struct _convrule_ rule108={GENCAT_LL, NUMCAT_LL, 1, -8, 0, -8};+static const struct _convrule_ rule73={GENCAT_LL, NUMCAT_LL, 1, 42308, 0, 42308};+static const struct _convrule_ rule40={GENCAT_LU, NUMCAT_LU, 1, 0, 213, 0};+static const struct _convrule_ rule136={GENCAT_LL, NUMCAT_LL, 1, 126, 0, 126};+static const struct _convrule_ rule116={GENCAT_LU, NUMCAT_LU, 1, 0, 80, 0};+static const struct _convrule_ rule55={GENCAT_LU, NUMCAT_LU, 1, 0, -163, 0};+static const struct _convrule_ rule174={GENCAT_LU, NUMCAT_LU, 1, 0, -42305, 0};+static const struct _convrule_ rule161={GENCAT_LL, NUMCAT_LL, 1, -10795, 0, -10795};+static const struct _convrule_ rule58={GENCAT_LU, NUMCAT_LU, 1, 0, -195, 0};+static const struct _convrule_ rule54={GENCAT_LU, NUMCAT_LU, 1, 0, 10795, 0};+static const struct _convrule_ rule107={GENCAT_LL, NUMCAT_LL, 1, -54, 0, -54};+static const struct _convrule_ rule146={GENCAT_LU, NUMCAT_LU, 1, 0, -126, 0};+static const struct _convrule_ rule104={GENCAT_LL, NUMCAT_LL, 1, -57, 0, -57};+static const struct _convrule_ rule21={GENCAT_LL, NUMCAT_LL, 1, 121, 0, 121};+static const struct _convrule_ rule156={GENCAT_SO, NUMCAT_SO, 1, 0, 26, 0};+static const struct _convrule_ rule85={GENCAT_LL, NUMCAT_LL, 1, -217, 0, -217};+static const struct _convrule_ rule16={GENCAT_CF, NUMCAT_CF, 0, 0, 0, 0};+static const struct _convrule_ rule112={GENCAT_LL, NUMCAT_LL, 1, -116, 0, -116};+static const struct _convrule_ rule38={GENCAT_LU, NUMCAT_LU, 1, 0, 209, 0};+static const struct _convrule_ rule10={GENCAT_SK, NUMCAT_SK, 0, 0, 0, 0};+static const struct _convrule_ rule167={GENCAT_LU, NUMCAT_LU, 1, 0, -10815, 0};+static const struct _convrule_ rule5={GENCAT_PE, NUMCAT_PE, 0, 0, 0, 0};+static const struct _convrule_ rule164={GENCAT_LU, NUMCAT_LU, 1, 0, -10749, 0};+static const struct _convrule_ rule117={GENCAT_ME, NUMCAT_ME, 0, 0, 0, 0};+static const struct _convrule_ rule106={GENCAT_LL, NUMCAT_LL, 1, -47, 0, -47};+static const struct _convrule_ rule160={GENCAT_LU, NUMCAT_LU, 1, 0, -10727, 0};+static const struct _convrule_ rule9={GENCAT_LU, NUMCAT_LU, 1, 0, 32, 0};+static const struct _charblock_ allchars[]={+	{0, 32, &rule0},+	{32, 1, &rule1},+	{33, 3, &rule2},+	{36, 1, &rule3},+	{37, 3, &rule2},+	{40, 1, &rule4},+	{41, 1, &rule5},+	{42, 1, &rule2},+	{43, 1, &rule6},+	{44, 1, &rule2},+	{45, 1, &rule7},+	{46, 2, &rule2},+	{48, 10, &rule8},+	{58, 2, &rule2},+	{60, 3, &rule6},+	{63, 2, &rule2},+	{65, 26, &rule9},+	{91, 1, &rule4},+	{92, 1, &rule2},+	{93, 1, &rule5},+	{94, 1, &rule10},+	{95, 1, &rule11},+	{96, 1, &rule10},+	{97, 26, &rule12},+	{123, 1, &rule4},+	{124, 1, &rule6},+	{125, 1, &rule5},+	{126, 1, &rule6},+	{127, 33, &rule0},+	{160, 1, &rule1},+	{161, 1, &rule2},+	{162, 4, &rule3},+	{166, 1, &rule13},+	{167, 1, &rule2},+	{168, 1, &rule10},+	{169, 1, &rule13},+	{170, 1, &rule14},+	{171, 1, &rule15},+	{172, 1, &rule6},+	{173, 1, &rule16},+	{174, 1, &rule13},+	{175, 1, &rule10},+	{176, 1, &rule13},+	{177, 1, &rule6},+	{178, 2, &rule17},+	{180, 1, &rule10},+	{181, 1, &rule18},+	{182, 2, &rule2},+	{184, 1, &rule10},+	{185, 1, &rule17},+	{186, 1, &rule14},+	{187, 1, &rule19},+	{188, 3, &rule17},+	{191, 1, &rule2},+	{192, 23, &rule9},+	{215, 1, &rule6},+	{216, 7, &rule9},+	{223, 1, &rule20},+	{224, 23, &rule12},+	{247, 1, &rule6},+	{248, 7, &rule12},+	{255, 1, &rule21},+	{256, 1, &rule22},+	{257, 1, &rule23},+	{258, 1, &rule22},+	{259, 1, &rule23},+	{260, 1, &rule22},+	{261, 1, &rule23},+	{262, 1, &rule22},+	{263, 1, &rule23},+	{264, 1, &rule22},+	{265, 1, &rule23},+	{266, 1, &rule22},+	{267, 1, &rule23},+	{268, 1, &rule22},+	{269, 1, &rule23},+	{270, 1, &rule22},+	{271, 1, &rule23},+	{272, 1, &rule22},+	{273, 1, &rule23},+	{274, 1, &rule22},+	{275, 1, &rule23},+	{276, 1, &rule22},+	{277, 1, &rule23},+	{278, 1, &rule22},+	{279, 1, &rule23},+	{280, 1, &rule22},+	{281, 1, &rule23},+	{282, 1, &rule22},+	{283, 1, &rule23},+	{284, 1, &rule22},+	{285, 1, &rule23},+	{286, 1, &rule22},+	{287, 1, &rule23},+	{288, 1, &rule22},+	{289, 1, &rule23},+	{290, 1, &rule22},+	{291, 1, &rule23},+	{292, 1, &rule22},+	{293, 1, &rule23},+	{294, 1, &rule22},+	{295, 1, &rule23},+	{296, 1, &rule22},+	{297, 1, &rule23},+	{298, 1, &rule22},+	{299, 1, &rule23},+	{300, 1, &rule22},+	{301, 1, &rule23},+	{302, 1, &rule22},+	{303, 1, &rule23},+	{304, 1, &rule24},+	{305, 1, &rule25},+	{306, 1, &rule22},+	{307, 1, &rule23},+	{308, 1, &rule22},+	{309, 1, &rule23},+	{310, 1, &rule22},+	{311, 1, &rule23},+	{312, 1, &rule20},+	{313, 1, &rule22},+	{314, 1, &rule23},+	{315, 1, &rule22},+	{316, 1, &rule23},+	{317, 1, &rule22},+	{318, 1, &rule23},+	{319, 1, &rule22},+	{320, 1, &rule23},+	{321, 1, &rule22},+	{322, 1, &rule23},+	{323, 1, &rule22},+	{324, 1, &rule23},+	{325, 1, &rule22},+	{326, 1, &rule23},+	{327, 1, &rule22},+	{328, 1, &rule23},+	{329, 1, &rule20},+	{330, 1, &rule22},+	{331, 1, &rule23},+	{332, 1, &rule22},+	{333, 1, &rule23},+	{334, 1, &rule22},+	{335, 1, &rule23},+	{336, 1, &rule22},+	{337, 1, &rule23},+	{338, 1, &rule22},+	{339, 1, &rule23},+	{340, 1, &rule22},+	{341, 1, &rule23},+	{342, 1, &rule22},+	{343, 1, &rule23},+	{344, 1, &rule22},+	{345, 1, &rule23},+	{346, 1, &rule22},+	{347, 1, &rule23},+	{348, 1, &rule22},+	{349, 1, &rule23},+	{350, 1, &rule22},+	{351, 1, &rule23},+	{352, 1, &rule22},+	{353, 1, &rule23},+	{354, 1, &rule22},+	{355, 1, &rule23},+	{356, 1, &rule22},+	{357, 1, &rule23},+	{358, 1, &rule22},+	{359, 1, &rule23},+	{360, 1, &rule22},+	{361, 1, &rule23},+	{362, 1, &rule22},+	{363, 1, &rule23},+	{364, 1, &rule22},+	{365, 1, &rule23},+	{366, 1, &rule22},+	{367, 1, &rule23},+	{368, 1, &rule22},+	{369, 1, &rule23},+	{370, 1, &rule22},+	{371, 1, &rule23},+	{372, 1, &rule22},+	{373, 1, &rule23},+	{374, 1, &rule22},+	{375, 1, &rule23},+	{376, 1, &rule26},+	{377, 1, &rule22},+	{378, 1, &rule23},+	{379, 1, &rule22},+	{380, 1, &rule23},+	{381, 1, &rule22},+	{382, 1, &rule23},+	{383, 1, &rule27},+	{384, 1, &rule28},+	{385, 1, &rule29},+	{386, 1, &rule22},+	{387, 1, &rule23},+	{388, 1, &rule22},+	{389, 1, &rule23},+	{390, 1, &rule30},+	{391, 1, &rule22},+	{392, 1, &rule23},+	{393, 2, &rule31},+	{395, 1, &rule22},+	{396, 1, &rule23},+	{397, 1, &rule20},+	{398, 1, &rule32},+	{399, 1, &rule33},+	{400, 1, &rule34},+	{401, 1, &rule22},+	{402, 1, &rule23},+	{403, 1, &rule31},+	{404, 1, &rule35},+	{405, 1, &rule36},+	{406, 1, &rule37},+	{407, 1, &rule38},+	{408, 1, &rule22},+	{409, 1, &rule23},+	{410, 1, &rule39},+	{411, 1, &rule20},+	{412, 1, &rule37},+	{413, 1, &rule40},+	{414, 1, &rule41},+	{415, 1, &rule42},+	{416, 1, &rule22},+	{417, 1, &rule23},+	{418, 1, &rule22},+	{419, 1, &rule23},+	{420, 1, &rule22},+	{421, 1, &rule23},+	{422, 1, &rule43},+	{423, 1, &rule22},+	{424, 1, &rule23},+	{425, 1, &rule43},+	{426, 2, &rule20},+	{428, 1, &rule22},+	{429, 1, &rule23},+	{430, 1, &rule43},+	{431, 1, &rule22},+	{432, 1, &rule23},+	{433, 2, &rule44},+	{435, 1, &rule22},+	{436, 1, &rule23},+	{437, 1, &rule22},+	{438, 1, &rule23},+	{439, 1, &rule45},+	{440, 1, &rule22},+	{441, 1, &rule23},+	{442, 1, &rule20},+	{443, 1, &rule14},+	{444, 1, &rule22},+	{445, 1, &rule23},+	{446, 1, &rule20},+	{447, 1, &rule46},+	{448, 4, &rule14},+	{452, 1, &rule47},+	{453, 1, &rule48},+	{454, 1, &rule49},+	{455, 1, &rule47},+	{456, 1, &rule48},+	{457, 1, &rule49},+	{458, 1, &rule47},+	{459, 1, &rule48},+	{460, 1, &rule49},+	{461, 1, &rule22},+	{462, 1, &rule23},+	{463, 1, &rule22},+	{464, 1, &rule23},+	{465, 1, &rule22},+	{466, 1, &rule23},+	{467, 1, &rule22},+	{468, 1, &rule23},+	{469, 1, &rule22},+	{470, 1, &rule23},+	{471, 1, &rule22},+	{472, 1, &rule23},+	{473, 1, &rule22},+	{474, 1, &rule23},+	{475, 1, &rule22},+	{476, 1, &rule23},+	{477, 1, &rule50},+	{478, 1, &rule22},+	{479, 1, &rule23},+	{480, 1, &rule22},+	{481, 1, &rule23},+	{482, 1, &rule22},+	{483, 1, &rule23},+	{484, 1, &rule22},+	{485, 1, &rule23},+	{486, 1, &rule22},+	{487, 1, &rule23},+	{488, 1, &rule22},+	{489, 1, &rule23},+	{490, 1, &rule22},+	{491, 1, &rule23},+	{492, 1, &rule22},+	{493, 1, &rule23},+	{494, 1, &rule22},+	{495, 1, &rule23},+	{496, 1, &rule20},+	{497, 1, &rule47},+	{498, 1, &rule48},+	{499, 1, &rule49},+	{500, 1, &rule22},+	{501, 1, &rule23},+	{502, 1, &rule51},+	{503, 1, &rule52},+	{504, 1, &rule22},+	{505, 1, &rule23},+	{506, 1, &rule22},+	{507, 1, &rule23},+	{508, 1, &rule22},+	{509, 1, &rule23},+	{510, 1, &rule22},+	{511, 1, &rule23},+	{512, 1, &rule22},+	{513, 1, &rule23},+	{514, 1, &rule22},+	{515, 1, &rule23},+	{516, 1, &rule22},+	{517, 1, &rule23},+	{518, 1, &rule22},+	{519, 1, &rule23},+	{520, 1, &rule22},+	{521, 1, &rule23},+	{522, 1, &rule22},+	{523, 1, &rule23},+	{524, 1, &rule22},+	{525, 1, &rule23},+	{526, 1, &rule22},+	{527, 1, &rule23},+	{528, 1, &rule22},+	{529, 1, &rule23},+	{530, 1, &rule22},+	{531, 1, &rule23},+	{532, 1, &rule22},+	{533, 1, &rule23},+	{534, 1, &rule22},+	{535, 1, &rule23},+	{536, 1, &rule22},+	{537, 1, &rule23},+	{538, 1, &rule22},+	{539, 1, &rule23},+	{540, 1, &rule22},+	{541, 1, &rule23},+	{542, 1, &rule22},+	{543, 1, &rule23},+	{544, 1, &rule53},+	{545, 1, &rule20},+	{546, 1, &rule22},+	{547, 1, &rule23},+	{548, 1, &rule22},+	{549, 1, &rule23},+	{550, 1, &rule22},+	{551, 1, &rule23},+	{552, 1, &rule22},+	{553, 1, &rule23},+	{554, 1, &rule22},+	{555, 1, &rule23},+	{556, 1, &rule22},+	{557, 1, &rule23},+	{558, 1, &rule22},+	{559, 1, &rule23},+	{560, 1, &rule22},+	{561, 1, &rule23},+	{562, 1, &rule22},+	{563, 1, &rule23},+	{564, 6, &rule20},+	{570, 1, &rule54},+	{571, 1, &rule22},+	{572, 1, &rule23},+	{573, 1, &rule55},+	{574, 1, &rule56},+	{575, 2, &rule57},+	{577, 1, &rule22},+	{578, 1, &rule23},+	{579, 1, &rule58},+	{580, 1, &rule59},+	{581, 1, &rule60},+	{582, 1, &rule22},+	{583, 1, &rule23},+	{584, 1, &rule22},+	{585, 1, &rule23},+	{586, 1, &rule22},+	{587, 1, &rule23},+	{588, 1, &rule22},+	{589, 1, &rule23},+	{590, 1, &rule22},+	{591, 1, &rule23},+	{592, 1, &rule61},+	{593, 1, &rule62},+	{594, 1, &rule63},+	{595, 1, &rule64},+	{596, 1, &rule65},+	{597, 1, &rule20},+	{598, 2, &rule66},+	{600, 1, &rule20},+	{601, 1, &rule67},+	{602, 1, &rule20},+	{603, 1, &rule68},+	{604, 1, &rule69},+	{605, 3, &rule20},+	{608, 1, &rule66},+	{609, 1, &rule70},+	{610, 1, &rule20},+	{611, 1, &rule71},+	{612, 1, &rule20},+	{613, 1, &rule72},+	{614, 1, &rule73},+	{615, 1, &rule20},+	{616, 1, &rule74},+	{617, 1, &rule75},+	{618, 1, &rule20},+	{619, 1, &rule76},+	{620, 1, &rule77},+	{621, 2, &rule20},+	{623, 1, &rule75},+	{624, 1, &rule20},+	{625, 1, &rule78},+	{626, 1, &rule79},+	{627, 2, &rule20},+	{629, 1, &rule80},+	{630, 7, &rule20},+	{637, 1, &rule81},+	{638, 2, &rule20},+	{640, 1, &rule82},+	{641, 2, &rule20},+	{643, 1, &rule82},+	{644, 3, &rule20},+	{647, 1, &rule83},+	{648, 1, &rule82},+	{649, 1, &rule84},+	{650, 2, &rule85},+	{652, 1, &rule86},+	{653, 5, &rule20},+	{658, 1, &rule87},+	{659, 1, &rule20},+	{660, 1, &rule14},+	{661, 9, &rule20},+	{670, 1, &rule88},+	{671, 17, &rule20},+	{688, 18, &rule89},+	{706, 4, &rule10},+	{710, 12, &rule89},+	{722, 14, &rule10},+	{736, 5, &rule89},+	{741, 7, &rule10},+	{748, 1, &rule89},+	{749, 1, &rule10},+	{750, 1, &rule89},+	{751, 17, &rule10},+	{768, 69, &rule90},+	{837, 1, &rule91},+	{838, 42, &rule90},+	{880, 1, &rule22},+	{881, 1, &rule23},+	{882, 1, &rule22},+	{883, 1, &rule23},+	{884, 1, &rule89},+	{885, 1, &rule10},+	{886, 1, &rule22},+	{887, 1, &rule23},+	{890, 1, &rule89},+	{891, 3, &rule41},+	{894, 1, &rule2},+	{895, 1, &rule92},+	{900, 2, &rule10},+	{902, 1, &rule93},+	{903, 1, &rule2},+	{904, 3, &rule94},+	{908, 1, &rule95},+	{910, 2, &rule96},+	{912, 1, &rule20},+	{913, 17, &rule9},+	{931, 9, &rule9},+	{940, 1, &rule97},+	{941, 3, &rule98},+	{944, 1, &rule20},+	{945, 17, &rule12},+	{962, 1, &rule99},+	{963, 9, &rule12},+	{972, 1, &rule100},+	{973, 2, &rule101},+	{975, 1, &rule102},+	{976, 1, &rule103},+	{977, 1, &rule104},+	{978, 3, &rule105},+	{981, 1, &rule106},+	{982, 1, &rule107},+	{983, 1, &rule108},+	{984, 1, &rule22},+	{985, 1, &rule23},+	{986, 1, &rule22},+	{987, 1, &rule23},+	{988, 1, &rule22},+	{989, 1, &rule23},+	{990, 1, &rule22},+	{991, 1, &rule23},+	{992, 1, &rule22},+	{993, 1, &rule23},+	{994, 1, &rule22},+	{995, 1, &rule23},+	{996, 1, &rule22},+	{997, 1, &rule23},+	{998, 1, &rule22},+	{999, 1, &rule23},+	{1000, 1, &rule22},+	{1001, 1, &rule23},+	{1002, 1, &rule22},+	{1003, 1, &rule23},+	{1004, 1, &rule22},+	{1005, 1, &rule23},+	{1006, 1, &rule22},+	{1007, 1, &rule23},+	{1008, 1, &rule109},+	{1009, 1, &rule110},+	{1010, 1, &rule111},+	{1011, 1, &rule112},+	{1012, 1, &rule113},+	{1013, 1, &rule114},+	{1014, 1, &rule6},+	{1015, 1, &rule22},+	{1016, 1, &rule23},+	{1017, 1, &rule115},+	{1018, 1, &rule22},+	{1019, 1, &rule23},+	{1020, 1, &rule20},+	{1021, 3, &rule53},+	{1024, 16, &rule116},+	{1040, 32, &rule9},+	{1072, 32, &rule12},+	{1104, 16, &rule110},+	{1120, 1, &rule22},+	{1121, 1, &rule23},+	{1122, 1, &rule22},+	{1123, 1, &rule23},+	{1124, 1, &rule22},+	{1125, 1, &rule23},+	{1126, 1, &rule22},+	{1127, 1, &rule23},+	{1128, 1, &rule22},+	{1129, 1, &rule23},+	{1130, 1, &rule22},+	{1131, 1, &rule23},+	{1132, 1, &rule22},+	{1133, 1, &rule23},+	{1134, 1, &rule22},+	{1135, 1, &rule23},+	{1136, 1, &rule22},+	{1137, 1, &rule23},+	{1138, 1, &rule22},+	{1139, 1, &rule23},+	{1140, 1, &rule22},+	{1141, 1, &rule23},+	{1142, 1, &rule22},+	{1143, 1, &rule23},+	{1144, 1, &rule22},+	{1145, 1, &rule23},+	{1146, 1, &rule22},+	{1147, 1, &rule23},+	{1148, 1, &rule22},+	{1149, 1, &rule23},+	{1150, 1, &rule22},+	{1151, 1, &rule23},+	{1152, 1, &rule22},+	{1153, 1, &rule23},+	{1154, 1, &rule13},+	{1155, 5, &rule90},+	{1160, 2, &rule117},+	{1162, 1, &rule22},+	{1163, 1, &rule23},+	{1164, 1, &rule22},+	{1165, 1, &rule23},+	{1166, 1, &rule22},+	{1167, 1, &rule23},+	{1168, 1, &rule22},+	{1169, 1, &rule23},+	{1170, 1, &rule22},+	{1171, 1, &rule23},+	{1172, 1, &rule22},+	{1173, 1, &rule23},+	{1174, 1, &rule22},+	{1175, 1, &rule23},+	{1176, 1, &rule22},+	{1177, 1, &rule23},+	{1178, 1, &rule22},+	{1179, 1, &rule23},+	{1180, 1, &rule22},+	{1181, 1, &rule23},+	{1182, 1, &rule22},+	{1183, 1, &rule23},+	{1184, 1, &rule22},+	{1185, 1, &rule23},+	{1186, 1, &rule22},+	{1187, 1, &rule23},+	{1188, 1, &rule22},+	{1189, 1, &rule23},+	{1190, 1, &rule22},+	{1191, 1, &rule23},+	{1192, 1, &rule22},+	{1193, 1, &rule23},+	{1194, 1, &rule22},+	{1195, 1, &rule23},+	{1196, 1, &rule22},+	{1197, 1, &rule23},+	{1198, 1, &rule22},+	{1199, 1, &rule23},+	{1200, 1, &rule22},+	{1201, 1, &rule23},+	{1202, 1, &rule22},+	{1203, 1, &rule23},+	{1204, 1, &rule22},+	{1205, 1, &rule23},+	{1206, 1, &rule22},+	{1207, 1, &rule23},+	{1208, 1, &rule22},+	{1209, 1, &rule23},+	{1210, 1, &rule22},+	{1211, 1, &rule23},+	{1212, 1, &rule22},+	{1213, 1, &rule23},+	{1214, 1, &rule22},+	{1215, 1, &rule23},+	{1216, 1, &rule118},+	{1217, 1, &rule22},+	{1218, 1, &rule23},+	{1219, 1, &rule22},+	{1220, 1, &rule23},+	{1221, 1, &rule22},+	{1222, 1, &rule23},+	{1223, 1, &rule22},+	{1224, 1, &rule23},+	{1225, 1, &rule22},+	{1226, 1, &rule23},+	{1227, 1, &rule22},+	{1228, 1, &rule23},+	{1229, 1, &rule22},+	{1230, 1, &rule23},+	{1231, 1, &rule119},+	{1232, 1, &rule22},+	{1233, 1, &rule23},+	{1234, 1, &rule22},+	{1235, 1, &rule23},+	{1236, 1, &rule22},+	{1237, 1, &rule23},+	{1238, 1, &rule22},+	{1239, 1, &rule23},+	{1240, 1, &rule22},+	{1241, 1, &rule23},+	{1242, 1, &rule22},+	{1243, 1, &rule23},+	{1244, 1, &rule22},+	{1245, 1, &rule23},+	{1246, 1, &rule22},+	{1247, 1, &rule23},+	{1248, 1, &rule22},+	{1249, 1, &rule23},+	{1250, 1, &rule22},+	{1251, 1, &rule23},+	{1252, 1, &rule22},+	{1253, 1, &rule23},+	{1254, 1, &rule22},+	{1255, 1, &rule23},+	{1256, 1, &rule22},+	{1257, 1, &rule23},+	{1258, 1, &rule22},+	{1259, 1, &rule23},+	{1260, 1, &rule22},+	{1261, 1, &rule23},+	{1262, 1, &rule22},+	{1263, 1, &rule23},+	{1264, 1, &rule22},+	{1265, 1, &rule23},+	{1266, 1, &rule22},+	{1267, 1, &rule23},+	{1268, 1, &rule22},+	{1269, 1, &rule23},+	{1270, 1, &rule22},+	{1271, 1, &rule23},+	{1272, 1, &rule22},+	{1273, 1, &rule23},+	{1274, 1, &rule22},+	{1275, 1, &rule23},+	{1276, 1, &rule22},+	{1277, 1, &rule23},+	{1278, 1, &rule22},+	{1279, 1, &rule23},+	{1280, 1, &rule22},+	{1281, 1, &rule23},+	{1282, 1, &rule22},+	{1283, 1, &rule23},+	{1284, 1, &rule22},+	{1285, 1, &rule23},+	{1286, 1, &rule22},+	{1287, 1, &rule23},+	{1288, 1, &rule22},+	{1289, 1, &rule23},+	{1290, 1, &rule22},+	{1291, 1, &rule23},+	{1292, 1, &rule22},+	{1293, 1, &rule23},+	{1294, 1, &rule22},+	{1295, 1, &rule23},+	{1296, 1, &rule22},+	{1297, 1, &rule23},+	{1298, 1, &rule22},+	{1299, 1, &rule23},+	{1300, 1, &rule22},+	{1301, 1, &rule23},+	{1302, 1, &rule22},+	{1303, 1, &rule23},+	{1304, 1, &rule22},+	{1305, 1, &rule23},+	{1306, 1, &rule22},+	{1307, 1, &rule23},+	{1308, 1, &rule22},+	{1309, 1, &rule23},+	{1310, 1, &rule22},+	{1311, 1, &rule23},+	{1312, 1, &rule22},+	{1313, 1, &rule23},+	{1314, 1, &rule22},+	{1315, 1, &rule23},+	{1316, 1, &rule22},+	{1317, 1, &rule23},+	{1318, 1, &rule22},+	{1319, 1, &rule23},+	{1320, 1, &rule22},+	{1321, 1, &rule23},+	{1322, 1, &rule22},+	{1323, 1, &rule23},+	{1324, 1, &rule22},+	{1325, 1, &rule23},+	{1326, 1, &rule22},+	{1327, 1, &rule23},+	{1329, 38, &rule120},+	{1369, 1, &rule89},+	{1370, 6, &rule2},+	{1377, 38, &rule121},+	{1415, 1, &rule20},+	{1417, 1, &rule2},+	{1418, 1, &rule7},+	{1421, 2, &rule13},+	{1423, 1, &rule3},+	{1425, 45, &rule90},+	{1470, 1, &rule7},+	{1471, 1, &rule90},+	{1472, 1, &rule2},+	{1473, 2, &rule90},+	{1475, 1, &rule2},+	{1476, 2, &rule90},+	{1478, 1, &rule2},+	{1479, 1, &rule90},+	{1488, 27, &rule14},+	{1520, 3, &rule14},+	{1523, 2, &rule2},+	{1536, 6, &rule16},+	{1542, 3, &rule6},+	{1545, 2, &rule2},+	{1547, 1, &rule3},+	{1548, 2, &rule2},+	{1550, 2, &rule13},+	{1552, 11, &rule90},+	{1563, 1, &rule2},+	{1564, 1, &rule16},+	{1566, 2, &rule2},+	{1568, 32, &rule14},+	{1600, 1, &rule89},+	{1601, 10, &rule14},+	{1611, 21, &rule90},+	{1632, 10, &rule8},+	{1642, 4, &rule2},+	{1646, 2, &rule14},+	{1648, 1, &rule90},+	{1649, 99, &rule14},+	{1748, 1, &rule2},+	{1749, 1, &rule14},+	{1750, 7, &rule90},+	{1757, 1, &rule16},+	{1758, 1, &rule13},+	{1759, 6, &rule90},+	{1765, 2, &rule89},+	{1767, 2, &rule90},+	{1769, 1, &rule13},+	{1770, 4, &rule90},+	{1774, 2, &rule14},+	{1776, 10, &rule8},+	{1786, 3, &rule14},+	{1789, 2, &rule13},+	{1791, 1, &rule14},+	{1792, 14, &rule2},+	{1807, 1, &rule16},+	{1808, 1, &rule14},+	{1809, 1, &rule90},+	{1810, 30, &rule14},+	{1840, 27, &rule90},+	{1869, 89, &rule14},+	{1958, 11, &rule90},+	{1969, 1, &rule14},+	{1984, 10, &rule8},+	{1994, 33, &rule14},+	{2027, 9, &rule90},+	{2036, 2, &rule89},+	{2038, 1, &rule13},+	{2039, 3, &rule2},+	{2042, 1, &rule89},+	{2048, 22, &rule14},+	{2070, 4, &rule90},+	{2074, 1, &rule89},+	{2075, 9, &rule90},+	{2084, 1, &rule89},+	{2085, 3, &rule90},+	{2088, 1, &rule89},+	{2089, 5, &rule90},+	{2096, 15, &rule2},+	{2112, 25, &rule14},+	{2137, 3, &rule90},+	{2142, 1, &rule2},+	{2208, 19, &rule14},+	{2276, 31, &rule90},+	{2307, 1, &rule122},+	{2308, 54, &rule14},+	{2362, 1, &rule90},+	{2363, 1, &rule122},+	{2364, 1, &rule90},+	{2365, 1, &rule14},+	{2366, 3, &rule122},+	{2369, 8, &rule90},+	{2377, 4, &rule122},+	{2381, 1, &rule90},+	{2382, 2, &rule122},+	{2384, 1, &rule14},+	{2385, 7, &rule90},+	{2392, 10, &rule14},+	{2402, 2, &rule90},+	{2404, 2, &rule2},+	{2406, 10, &rule8},+	{2416, 1, &rule2},+	{2417, 1, &rule89},+	{2418, 15, &rule14},+	{2433, 1, &rule90},+	{2434, 2, &rule122},+	{2437, 8, &rule14},+	{2447, 2, &rule14},+	{2451, 22, &rule14},+	{2474, 7, &rule14},+	{2482, 1, &rule14},+	{2486, 4, &rule14},+	{2492, 1, &rule90},+	{2493, 1, &rule14},+	{2494, 3, &rule122},+	{2497, 4, &rule90},+	{2503, 2, &rule122},+	{2507, 2, &rule122},+	{2509, 1, &rule90},+	{2510, 1, &rule14},+	{2519, 1, &rule122},+	{2524, 2, &rule14},+	{2527, 3, &rule14},+	{2530, 2, &rule90},+	{2534, 10, &rule8},+	{2544, 2, &rule14},+	{2546, 2, &rule3},+	{2548, 6, &rule17},+	{2554, 1, &rule13},+	{2555, 1, &rule3},+	{2561, 2, &rule90},+	{2563, 1, &rule122},+	{2565, 6, &rule14},+	{2575, 2, &rule14},+	{2579, 22, &rule14},+	{2602, 7, &rule14},+	{2610, 2, &rule14},+	{2613, 2, &rule14},+	{2616, 2, &rule14},+	{2620, 1, &rule90},+	{2622, 3, &rule122},+	{2625, 2, &rule90},+	{2631, 2, &rule90},+	{2635, 3, &rule90},+	{2641, 1, &rule90},+	{2649, 4, &rule14},+	{2654, 1, &rule14},+	{2662, 10, &rule8},+	{2672, 2, &rule90},+	{2674, 3, &rule14},+	{2677, 1, &rule90},+	{2689, 2, &rule90},+	{2691, 1, &rule122},+	{2693, 9, &rule14},+	{2703, 3, &rule14},+	{2707, 22, &rule14},+	{2730, 7, &rule14},+	{2738, 2, &rule14},+	{2741, 5, &rule14},+	{2748, 1, &rule90},+	{2749, 1, &rule14},+	{2750, 3, &rule122},+	{2753, 5, &rule90},+	{2759, 2, &rule90},+	{2761, 1, &rule122},+	{2763, 2, &rule122},+	{2765, 1, &rule90},+	{2768, 1, &rule14},+	{2784, 2, &rule14},+	{2786, 2, &rule90},+	{2790, 10, &rule8},+	{2800, 1, &rule2},+	{2801, 1, &rule3},+	{2817, 1, &rule90},+	{2818, 2, &rule122},+	{2821, 8, &rule14},+	{2831, 2, &rule14},+	{2835, 22, &rule14},+	{2858, 7, &rule14},+	{2866, 2, &rule14},+	{2869, 5, &rule14},+	{2876, 1, &rule90},+	{2877, 1, &rule14},+	{2878, 1, &rule122},+	{2879, 1, &rule90},+	{2880, 1, &rule122},+	{2881, 4, &rule90},+	{2887, 2, &rule122},+	{2891, 2, &rule122},+	{2893, 1, &rule90},+	{2902, 1, &rule90},+	{2903, 1, &rule122},+	{2908, 2, &rule14},+	{2911, 3, &rule14},+	{2914, 2, &rule90},+	{2918, 10, &rule8},+	{2928, 1, &rule13},+	{2929, 1, &rule14},+	{2930, 6, &rule17},+	{2946, 1, &rule90},+	{2947, 1, &rule14},+	{2949, 6, &rule14},+	{2958, 3, &rule14},+	{2962, 4, &rule14},+	{2969, 2, &rule14},+	{2972, 1, &rule14},+	{2974, 2, &rule14},+	{2979, 2, &rule14},+	{2984, 3, &rule14},+	{2990, 12, &rule14},+	{3006, 2, &rule122},+	{3008, 1, &rule90},+	{3009, 2, &rule122},+	{3014, 3, &rule122},+	{3018, 3, &rule122},+	{3021, 1, &rule90},+	{3024, 1, &rule14},+	{3031, 1, &rule122},+	{3046, 10, &rule8},+	{3056, 3, &rule17},+	{3059, 6, &rule13},+	{3065, 1, &rule3},+	{3066, 1, &rule13},+	{3072, 1, &rule90},+	{3073, 3, &rule122},+	{3077, 8, &rule14},+	{3086, 3, &rule14},+	{3090, 23, &rule14},+	{3114, 16, &rule14},+	{3133, 1, &rule14},+	{3134, 3, &rule90},+	{3137, 4, &rule122},+	{3142, 3, &rule90},+	{3146, 4, &rule90},+	{3157, 2, &rule90},+	{3160, 2, &rule14},+	{3168, 2, &rule14},+	{3170, 2, &rule90},+	{3174, 10, &rule8},+	{3192, 7, &rule17},+	{3199, 1, &rule13},+	{3201, 1, &rule90},+	{3202, 2, &rule122},+	{3205, 8, &rule14},+	{3214, 3, &rule14},+	{3218, 23, &rule14},+	{3242, 10, &rule14},+	{3253, 5, &rule14},+	{3260, 1, &rule90},+	{3261, 1, &rule14},+	{3262, 1, &rule122},+	{3263, 1, &rule90},+	{3264, 5, &rule122},+	{3270, 1, &rule90},+	{3271, 2, &rule122},+	{3274, 2, &rule122},+	{3276, 2, &rule90},+	{3285, 2, &rule122},+	{3294, 1, &rule14},+	{3296, 2, &rule14},+	{3298, 2, &rule90},+	{3302, 10, &rule8},+	{3313, 2, &rule14},+	{3329, 1, &rule90},+	{3330, 2, &rule122},+	{3333, 8, &rule14},+	{3342, 3, &rule14},+	{3346, 41, &rule14},+	{3389, 1, &rule14},+	{3390, 3, &rule122},+	{3393, 4, &rule90},+	{3398, 3, &rule122},+	{3402, 3, &rule122},+	{3405, 1, &rule90},+	{3406, 1, &rule14},+	{3415, 1, &rule122},+	{3424, 2, &rule14},+	{3426, 2, &rule90},+	{3430, 10, &rule8},+	{3440, 6, &rule17},+	{3449, 1, &rule13},+	{3450, 6, &rule14},+	{3458, 2, &rule122},+	{3461, 18, &rule14},+	{3482, 24, &rule14},+	{3507, 9, &rule14},+	{3517, 1, &rule14},+	{3520, 7, &rule14},+	{3530, 1, &rule90},+	{3535, 3, &rule122},+	{3538, 3, &rule90},+	{3542, 1, &rule90},+	{3544, 8, &rule122},+	{3558, 10, &rule8},+	{3570, 2, &rule122},+	{3572, 1, &rule2},+	{3585, 48, &rule14},+	{3633, 1, &rule90},+	{3634, 2, &rule14},+	{3636, 7, &rule90},+	{3647, 1, &rule3},+	{3648, 6, &rule14},+	{3654, 1, &rule89},+	{3655, 8, &rule90},+	{3663, 1, &rule2},+	{3664, 10, &rule8},+	{3674, 2, &rule2},+	{3713, 2, &rule14},+	{3716, 1, &rule14},+	{3719, 2, &rule14},+	{3722, 1, &rule14},+	{3725, 1, &rule14},+	{3732, 4, &rule14},+	{3737, 7, &rule14},+	{3745, 3, &rule14},+	{3749, 1, &rule14},+	{3751, 1, &rule14},+	{3754, 2, &rule14},+	{3757, 4, &rule14},+	{3761, 1, &rule90},+	{3762, 2, &rule14},+	{3764, 6, &rule90},+	{3771, 2, &rule90},+	{3773, 1, &rule14},+	{3776, 5, &rule14},+	{3782, 1, &rule89},+	{3784, 6, &rule90},+	{3792, 10, &rule8},+	{3804, 4, &rule14},+	{3840, 1, &rule14},+	{3841, 3, &rule13},+	{3844, 15, &rule2},+	{3859, 1, &rule13},+	{3860, 1, &rule2},+	{3861, 3, &rule13},+	{3864, 2, &rule90},+	{3866, 6, &rule13},+	{3872, 10, &rule8},+	{3882, 10, &rule17},+	{3892, 1, &rule13},+	{3893, 1, &rule90},+	{3894, 1, &rule13},+	{3895, 1, &rule90},+	{3896, 1, &rule13},+	{3897, 1, &rule90},+	{3898, 1, &rule4},+	{3899, 1, &rule5},+	{3900, 1, &rule4},+	{3901, 1, &rule5},+	{3902, 2, &rule122},+	{3904, 8, &rule14},+	{3913, 36, &rule14},+	{3953, 14, &rule90},+	{3967, 1, &rule122},+	{3968, 5, &rule90},+	{3973, 1, &rule2},+	{3974, 2, &rule90},+	{3976, 5, &rule14},+	{3981, 11, &rule90},+	{3993, 36, &rule90},+	{4030, 8, &rule13},+	{4038, 1, &rule90},+	{4039, 6, &rule13},+	{4046, 2, &rule13},+	{4048, 5, &rule2},+	{4053, 4, &rule13},+	{4057, 2, &rule2},+	{4096, 43, &rule14},+	{4139, 2, &rule122},+	{4141, 4, &rule90},+	{4145, 1, &rule122},+	{4146, 6, &rule90},+	{4152, 1, &rule122},+	{4153, 2, &rule90},+	{4155, 2, &rule122},+	{4157, 2, &rule90},+	{4159, 1, &rule14},+	{4160, 10, &rule8},+	{4170, 6, &rule2},+	{4176, 6, &rule14},+	{4182, 2, &rule122},+	{4184, 2, &rule90},+	{4186, 4, &rule14},+	{4190, 3, &rule90},+	{4193, 1, &rule14},+	{4194, 3, &rule122},+	{4197, 2, &rule14},+	{4199, 7, &rule122},+	{4206, 3, &rule14},+	{4209, 4, &rule90},+	{4213, 13, &rule14},+	{4226, 1, &rule90},+	{4227, 2, &rule122},+	{4229, 2, &rule90},+	{4231, 6, &rule122},+	{4237, 1, &rule90},+	{4238, 1, &rule14},+	{4239, 1, &rule122},+	{4240, 10, &rule8},+	{4250, 3, &rule122},+	{4253, 1, &rule90},+	{4254, 2, &rule13},+	{4256, 38, &rule123},+	{4295, 1, &rule123},+	{4301, 1, &rule123},+	{4304, 43, &rule14},+	{4347, 1, &rule2},+	{4348, 1, &rule89},+	{4349, 332, &rule14},+	{4682, 4, &rule14},+	{4688, 7, &rule14},+	{4696, 1, &rule14},+	{4698, 4, &rule14},+	{4704, 41, &rule14},+	{4746, 4, &rule14},+	{4752, 33, &rule14},+	{4786, 4, &rule14},+	{4792, 7, &rule14},+	{4800, 1, &rule14},+	{4802, 4, &rule14},+	{4808, 15, &rule14},+	{4824, 57, &rule14},+	{4882, 4, &rule14},+	{4888, 67, &rule14},+	{4957, 3, &rule90},+	{4960, 9, &rule2},+	{4969, 20, &rule17},+	{4992, 16, &rule14},+	{5008, 10, &rule13},+	{5024, 85, &rule14},+	{5120, 1, &rule7},+	{5121, 620, &rule14},+	{5741, 2, &rule2},+	{5743, 17, &rule14},+	{5760, 1, &rule1},+	{5761, 26, &rule14},+	{5787, 1, &rule4},+	{5788, 1, &rule5},+	{5792, 75, &rule14},+	{5867, 3, &rule2},+	{5870, 3, &rule124},+	{5873, 8, &rule14},+	{5888, 13, &rule14},+	{5902, 4, &rule14},+	{5906, 3, &rule90},+	{5920, 18, &rule14},+	{5938, 3, &rule90},+	{5941, 2, &rule2},+	{5952, 18, &rule14},+	{5970, 2, &rule90},+	{5984, 13, &rule14},+	{5998, 3, &rule14},+	{6002, 2, &rule90},+	{6016, 52, &rule14},+	{6068, 2, &rule90},+	{6070, 1, &rule122},+	{6071, 7, &rule90},+	{6078, 8, &rule122},+	{6086, 1, &rule90},+	{6087, 2, &rule122},+	{6089, 11, &rule90},+	{6100, 3, &rule2},+	{6103, 1, &rule89},+	{6104, 3, &rule2},+	{6107, 1, &rule3},+	{6108, 1, &rule14},+	{6109, 1, &rule90},+	{6112, 10, &rule8},+	{6128, 10, &rule17},+	{6144, 6, &rule2},+	{6150, 1, &rule7},+	{6151, 4, &rule2},+	{6155, 3, &rule90},+	{6158, 1, &rule16},+	{6160, 10, &rule8},+	{6176, 35, &rule14},+	{6211, 1, &rule89},+	{6212, 52, &rule14},+	{6272, 41, &rule14},+	{6313, 1, &rule90},+	{6314, 1, &rule14},+	{6320, 70, &rule14},+	{6400, 31, &rule14},+	{6432, 3, &rule90},+	{6435, 4, &rule122},+	{6439, 2, &rule90},+	{6441, 3, &rule122},+	{6448, 2, &rule122},+	{6450, 1, &rule90},+	{6451, 6, &rule122},+	{6457, 3, &rule90},+	{6464, 1, &rule13},+	{6468, 2, &rule2},+	{6470, 10, &rule8},+	{6480, 30, &rule14},+	{6512, 5, &rule14},+	{6528, 44, &rule14},+	{6576, 17, &rule122},+	{6593, 7, &rule14},+	{6600, 2, &rule122},+	{6608, 10, &rule8},+	{6618, 1, &rule17},+	{6622, 34, &rule13},+	{6656, 23, &rule14},+	{6679, 2, &rule90},+	{6681, 2, &rule122},+	{6683, 1, &rule90},+	{6686, 2, &rule2},+	{6688, 53, &rule14},+	{6741, 1, &rule122},+	{6742, 1, &rule90},+	{6743, 1, &rule122},+	{6744, 7, &rule90},+	{6752, 1, &rule90},+	{6753, 1, &rule122},+	{6754, 1, &rule90},+	{6755, 2, &rule122},+	{6757, 8, &rule90},+	{6765, 6, &rule122},+	{6771, 10, &rule90},+	{6783, 1, &rule90},+	{6784, 10, &rule8},+	{6800, 10, &rule8},+	{6816, 7, &rule2},+	{6823, 1, &rule89},+	{6824, 6, &rule2},+	{6832, 14, &rule90},+	{6846, 1, &rule117},+	{6912, 4, &rule90},+	{6916, 1, &rule122},+	{6917, 47, &rule14},+	{6964, 1, &rule90},+	{6965, 1, &rule122},+	{6966, 5, &rule90},+	{6971, 1, &rule122},+	{6972, 1, &rule90},+	{6973, 5, &rule122},+	{6978, 1, &rule90},+	{6979, 2, &rule122},+	{6981, 7, &rule14},+	{6992, 10, &rule8},+	{7002, 7, &rule2},+	{7009, 10, &rule13},+	{7019, 9, &rule90},+	{7028, 9, &rule13},+	{7040, 2, &rule90},+	{7042, 1, &rule122},+	{7043, 30, &rule14},+	{7073, 1, &rule122},+	{7074, 4, &rule90},+	{7078, 2, &rule122},+	{7080, 2, &rule90},+	{7082, 1, &rule122},+	{7083, 3, &rule90},+	{7086, 2, &rule14},+	{7088, 10, &rule8},+	{7098, 44, &rule14},+	{7142, 1, &rule90},+	{7143, 1, &rule122},+	{7144, 2, &rule90},+	{7146, 3, &rule122},+	{7149, 1, &rule90},+	{7150, 1, &rule122},+	{7151, 3, &rule90},+	{7154, 2, &rule122},+	{7164, 4, &rule2},+	{7168, 36, &rule14},+	{7204, 8, &rule122},+	{7212, 8, &rule90},+	{7220, 2, &rule122},+	{7222, 2, &rule90},+	{7227, 5, &rule2},+	{7232, 10, &rule8},+	{7245, 3, &rule14},+	{7248, 10, &rule8},+	{7258, 30, &rule14},+	{7288, 6, &rule89},+	{7294, 2, &rule2},+	{7360, 8, &rule2},+	{7376, 3, &rule90},+	{7379, 1, &rule2},+	{7380, 13, &rule90},+	{7393, 1, &rule122},+	{7394, 7, &rule90},+	{7401, 4, &rule14},+	{7405, 1, &rule90},+	{7406, 4, &rule14},+	{7410, 2, &rule122},+	{7412, 1, &rule90},+	{7413, 2, &rule14},+	{7416, 2, &rule90},+	{7424, 44, &rule20},+	{7468, 63, &rule89},+	{7531, 13, &rule20},+	{7544, 1, &rule89},+	{7545, 1, &rule125},+	{7546, 3, &rule20},+	{7549, 1, &rule126},+	{7550, 29, &rule20},+	{7579, 37, &rule89},+	{7616, 54, &rule90},+	{7676, 4, &rule90},+	{7680, 1, &rule22},+	{7681, 1, &rule23},+	{7682, 1, &rule22},+	{7683, 1, &rule23},+	{7684, 1, &rule22},+	{7685, 1, &rule23},+	{7686, 1, &rule22},+	{7687, 1, &rule23},+	{7688, 1, &rule22},+	{7689, 1, &rule23},+	{7690, 1, &rule22},+	{7691, 1, &rule23},+	{7692, 1, &rule22},+	{7693, 1, &rule23},+	{7694, 1, &rule22},+	{7695, 1, &rule23},+	{7696, 1, &rule22},+	{7697, 1, &rule23},+	{7698, 1, &rule22},+	{7699, 1, &rule23},+	{7700, 1, &rule22},+	{7701, 1, &rule23},+	{7702, 1, &rule22},+	{7703, 1, &rule23},+	{7704, 1, &rule22},+	{7705, 1, &rule23},+	{7706, 1, &rule22},+	{7707, 1, &rule23},+	{7708, 1, &rule22},+	{7709, 1, &rule23},+	{7710, 1, &rule22},+	{7711, 1, &rule23},+	{7712, 1, &rule22},+	{7713, 1, &rule23},+	{7714, 1, &rule22},+	{7715, 1, &rule23},+	{7716, 1, &rule22},+	{7717, 1, &rule23},+	{7718, 1, &rule22},+	{7719, 1, &rule23},+	{7720, 1, &rule22},+	{7721, 1, &rule23},+	{7722, 1, &rule22},+	{7723, 1, &rule23},+	{7724, 1, &rule22},+	{7725, 1, &rule23},+	{7726, 1, &rule22},+	{7727, 1, &rule23},+	{7728, 1, &rule22},+	{7729, 1, &rule23},+	{7730, 1, &rule22},+	{7731, 1, &rule23},+	{7732, 1, &rule22},+	{7733, 1, &rule23},+	{7734, 1, &rule22},+	{7735, 1, &rule23},+	{7736, 1, &rule22},+	{7737, 1, &rule23},+	{7738, 1, &rule22},+	{7739, 1, &rule23},+	{7740, 1, &rule22},+	{7741, 1, &rule23},+	{7742, 1, &rule22},+	{7743, 1, &rule23},+	{7744, 1, &rule22},+	{7745, 1, &rule23},+	{7746, 1, &rule22},+	{7747, 1, &rule23},+	{7748, 1, &rule22},+	{7749, 1, &rule23},+	{7750, 1, &rule22},+	{7751, 1, &rule23},+	{7752, 1, &rule22},+	{7753, 1, &rule23},+	{7754, 1, &rule22},+	{7755, 1, &rule23},+	{7756, 1, &rule22},+	{7757, 1, &rule23},+	{7758, 1, &rule22},+	{7759, 1, &rule23},+	{7760, 1, &rule22},+	{7761, 1, &rule23},+	{7762, 1, &rule22},+	{7763, 1, &rule23},+	{7764, 1, &rule22},+	{7765, 1, &rule23},+	{7766, 1, &rule22},+	{7767, 1, &rule23},+	{7768, 1, &rule22},+	{7769, 1, &rule23},+	{7770, 1, &rule22},+	{7771, 1, &rule23},+	{7772, 1, &rule22},+	{7773, 1, &rule23},+	{7774, 1, &rule22},+	{7775, 1, &rule23},+	{7776, 1, &rule22},+	{7777, 1, &rule23},+	{7778, 1, &rule22},+	{7779, 1, &rule23},+	{7780, 1, &rule22},+	{7781, 1, &rule23},+	{7782, 1, &rule22},+	{7783, 1, &rule23},+	{7784, 1, &rule22},+	{7785, 1, &rule23},+	{7786, 1, &rule22},+	{7787, 1, &rule23},+	{7788, 1, &rule22},+	{7789, 1, &rule23},+	{7790, 1, &rule22},+	{7791, 1, &rule23},+	{7792, 1, &rule22},+	{7793, 1, &rule23},+	{7794, 1, &rule22},+	{7795, 1, &rule23},+	{7796, 1, &rule22},+	{7797, 1, &rule23},+	{7798, 1, &rule22},+	{7799, 1, &rule23},+	{7800, 1, &rule22},+	{7801, 1, &rule23},+	{7802, 1, &rule22},+	{7803, 1, &rule23},+	{7804, 1, &rule22},+	{7805, 1, &rule23},+	{7806, 1, &rule22},+	{7807, 1, &rule23},+	{7808, 1, &rule22},+	{7809, 1, &rule23},+	{7810, 1, &rule22},+	{7811, 1, &rule23},+	{7812, 1, &rule22},+	{7813, 1, &rule23},+	{7814, 1, &rule22},+	{7815, 1, &rule23},+	{7816, 1, &rule22},+	{7817, 1, &rule23},+	{7818, 1, &rule22},+	{7819, 1, &rule23},+	{7820, 1, &rule22},+	{7821, 1, &rule23},+	{7822, 1, &rule22},+	{7823, 1, &rule23},+	{7824, 1, &rule22},+	{7825, 1, &rule23},+	{7826, 1, &rule22},+	{7827, 1, &rule23},+	{7828, 1, &rule22},+	{7829, 1, &rule23},+	{7830, 5, &rule20},+	{7835, 1, &rule127},+	{7836, 2, &rule20},+	{7838, 1, &rule128},+	{7839, 1, &rule20},+	{7840, 1, &rule22},+	{7841, 1, &rule23},+	{7842, 1, &rule22},+	{7843, 1, &rule23},+	{7844, 1, &rule22},+	{7845, 1, &rule23},+	{7846, 1, &rule22},+	{7847, 1, &rule23},+	{7848, 1, &rule22},+	{7849, 1, &rule23},+	{7850, 1, &rule22},+	{7851, 1, &rule23},+	{7852, 1, &rule22},+	{7853, 1, &rule23},+	{7854, 1, &rule22},+	{7855, 1, &rule23},+	{7856, 1, &rule22},+	{7857, 1, &rule23},+	{7858, 1, &rule22},+	{7859, 1, &rule23},+	{7860, 1, &rule22},+	{7861, 1, &rule23},+	{7862, 1, &rule22},+	{7863, 1, &rule23},+	{7864, 1, &rule22},+	{7865, 1, &rule23},+	{7866, 1, &rule22},+	{7867, 1, &rule23},+	{7868, 1, &rule22},+	{7869, 1, &rule23},+	{7870, 1, &rule22},+	{7871, 1, &rule23},+	{7872, 1, &rule22},+	{7873, 1, &rule23},+	{7874, 1, &rule22},+	{7875, 1, &rule23},+	{7876, 1, &rule22},+	{7877, 1, &rule23},+	{7878, 1, &rule22},+	{7879, 1, &rule23},+	{7880, 1, &rule22},+	{7881, 1, &rule23},+	{7882, 1, &rule22},+	{7883, 1, &rule23},+	{7884, 1, &rule22},+	{7885, 1, &rule23},+	{7886, 1, &rule22},+	{7887, 1, &rule23},+	{7888, 1, &rule22},+	{7889, 1, &rule23},+	{7890, 1, &rule22},+	{7891, 1, &rule23},+	{7892, 1, &rule22},+	{7893, 1, &rule23},+	{7894, 1, &rule22},+	{7895, 1, &rule23},+	{7896, 1, &rule22},+	{7897, 1, &rule23},+	{7898, 1, &rule22},+	{7899, 1, &rule23},+	{7900, 1, &rule22},+	{7901, 1, &rule23},+	{7902, 1, &rule22},+	{7903, 1, &rule23},+	{7904, 1, &rule22},+	{7905, 1, &rule23},+	{7906, 1, &rule22},+	{7907, 1, &rule23},+	{7908, 1, &rule22},+	{7909, 1, &rule23},+	{7910, 1, &rule22},+	{7911, 1, &rule23},+	{7912, 1, &rule22},+	{7913, 1, &rule23},+	{7914, 1, &rule22},+	{7915, 1, &rule23},+	{7916, 1, &rule22},+	{7917, 1, &rule23},+	{7918, 1, &rule22},+	{7919, 1, &rule23},+	{7920, 1, &rule22},+	{7921, 1, &rule23},+	{7922, 1, &rule22},+	{7923, 1, &rule23},+	{7924, 1, &rule22},+	{7925, 1, &rule23},+	{7926, 1, &rule22},+	{7927, 1, &rule23},+	{7928, 1, &rule22},+	{7929, 1, &rule23},+	{7930, 1, &rule22},+	{7931, 1, &rule23},+	{7932, 1, &rule22},+	{7933, 1, &rule23},+	{7934, 1, &rule22},+	{7935, 1, &rule23},+	{7936, 8, &rule129},+	{7944, 8, &rule130},+	{7952, 6, &rule129},+	{7960, 6, &rule130},+	{7968, 8, &rule129},+	{7976, 8, &rule130},+	{7984, 8, &rule129},+	{7992, 8, &rule130},+	{8000, 6, &rule129},+	{8008, 6, &rule130},+	{8016, 1, &rule20},+	{8017, 1, &rule129},+	{8018, 1, &rule20},+	{8019, 1, &rule129},+	{8020, 1, &rule20},+	{8021, 1, &rule129},+	{8022, 1, &rule20},+	{8023, 1, &rule129},+	{8025, 1, &rule130},+	{8027, 1, &rule130},+	{8029, 1, &rule130},+	{8031, 1, &rule130},+	{8032, 8, &rule129},+	{8040, 8, &rule130},+	{8048, 2, &rule131},+	{8050, 4, &rule132},+	{8054, 2, &rule133},+	{8056, 2, &rule134},+	{8058, 2, &rule135},+	{8060, 2, &rule136},+	{8064, 8, &rule129},+	{8072, 8, &rule137},+	{8080, 8, &rule129},+	{8088, 8, &rule137},+	{8096, 8, &rule129},+	{8104, 8, &rule137},+	{8112, 2, &rule129},+	{8114, 1, &rule20},+	{8115, 1, &rule138},+	{8116, 1, &rule20},+	{8118, 2, &rule20},+	{8120, 2, &rule130},+	{8122, 2, &rule139},+	{8124, 1, &rule140},+	{8125, 1, &rule10},+	{8126, 1, &rule141},+	{8127, 3, &rule10},+	{8130, 1, &rule20},+	{8131, 1, &rule138},+	{8132, 1, &rule20},+	{8134, 2, &rule20},+	{8136, 4, &rule142},+	{8140, 1, &rule140},+	{8141, 3, &rule10},+	{8144, 2, &rule129},+	{8146, 2, &rule20},+	{8150, 2, &rule20},+	{8152, 2, &rule130},+	{8154, 2, &rule143},+	{8157, 3, &rule10},+	{8160, 2, &rule129},+	{8162, 3, &rule20},+	{8165, 1, &rule111},+	{8166, 2, &rule20},+	{8168, 2, &rule130},+	{8170, 2, &rule144},+	{8172, 1, &rule115},+	{8173, 3, &rule10},+	{8178, 1, &rule20},+	{8179, 1, &rule138},+	{8180, 1, &rule20},+	{8182, 2, &rule20},+	{8184, 2, &rule145},+	{8186, 2, &rule146},+	{8188, 1, &rule140},+	{8189, 2, &rule10},+	{8192, 11, &rule1},+	{8203, 5, &rule16},+	{8208, 6, &rule7},+	{8214, 2, &rule2},+	{8216, 1, &rule15},+	{8217, 1, &rule19},+	{8218, 1, &rule4},+	{8219, 2, &rule15},+	{8221, 1, &rule19},+	{8222, 1, &rule4},+	{8223, 1, &rule15},+	{8224, 8, &rule2},+	{8232, 1, &rule147},+	{8233, 1, &rule148},+	{8234, 5, &rule16},+	{8239, 1, &rule1},+	{8240, 9, &rule2},+	{8249, 1, &rule15},+	{8250, 1, &rule19},+	{8251, 4, &rule2},+	{8255, 2, &rule11},+	{8257, 3, &rule2},+	{8260, 1, &rule6},+	{8261, 1, &rule4},+	{8262, 1, &rule5},+	{8263, 11, &rule2},+	{8274, 1, &rule6},+	{8275, 1, &rule2},+	{8276, 1, &rule11},+	{8277, 10, &rule2},+	{8287, 1, &rule1},+	{8288, 5, &rule16},+	{8294, 10, &rule16},+	{8304, 1, &rule17},+	{8305, 1, &rule89},+	{8308, 6, &rule17},+	{8314, 3, &rule6},+	{8317, 1, &rule4},+	{8318, 1, &rule5},+	{8319, 1, &rule89},+	{8320, 10, &rule17},+	{8330, 3, &rule6},+	{8333, 1, &rule4},+	{8334, 1, &rule5},+	{8336, 13, &rule89},+	{8352, 30, &rule3},+	{8400, 13, &rule90},+	{8413, 4, &rule117},+	{8417, 1, &rule90},+	{8418, 3, &rule117},+	{8421, 12, &rule90},+	{8448, 2, &rule13},+	{8450, 1, &rule105},+	{8451, 4, &rule13},+	{8455, 1, &rule105},+	{8456, 2, &rule13},+	{8458, 1, &rule20},+	{8459, 3, &rule105},+	{8462, 2, &rule20},+	{8464, 3, &rule105},+	{8467, 1, &rule20},+	{8468, 1, &rule13},+	{8469, 1, &rule105},+	{8470, 2, &rule13},+	{8472, 1, &rule6},+	{8473, 5, &rule105},+	{8478, 6, &rule13},+	{8484, 1, &rule105},+	{8485, 1, &rule13},+	{8486, 1, &rule149},+	{8487, 1, &rule13},+	{8488, 1, &rule105},+	{8489, 1, &rule13},+	{8490, 1, &rule150},+	{8491, 1, &rule151},+	{8492, 2, &rule105},+	{8494, 1, &rule13},+	{8495, 1, &rule20},+	{8496, 2, &rule105},+	{8498, 1, &rule152},+	{8499, 1, &rule105},+	{8500, 1, &rule20},+	{8501, 4, &rule14},+	{8505, 1, &rule20},+	{8506, 2, &rule13},+	{8508, 2, &rule20},+	{8510, 2, &rule105},+	{8512, 5, &rule6},+	{8517, 1, &rule105},+	{8518, 4, &rule20},+	{8522, 1, &rule13},+	{8523, 1, &rule6},+	{8524, 2, &rule13},+	{8526, 1, &rule153},+	{8527, 1, &rule13},+	{8528, 16, &rule17},+	{8544, 16, &rule154},+	{8560, 16, &rule155},+	{8576, 3, &rule124},+	{8579, 1, &rule22},+	{8580, 1, &rule23},+	{8581, 4, &rule124},+	{8585, 1, &rule17},+	{8592, 5, &rule6},+	{8597, 5, &rule13},+	{8602, 2, &rule6},+	{8604, 4, &rule13},+	{8608, 1, &rule6},+	{8609, 2, &rule13},+	{8611, 1, &rule6},+	{8612, 2, &rule13},+	{8614, 1, &rule6},+	{8615, 7, &rule13},+	{8622, 1, &rule6},+	{8623, 31, &rule13},+	{8654, 2, &rule6},+	{8656, 2, &rule13},+	{8658, 1, &rule6},+	{8659, 1, &rule13},+	{8660, 1, &rule6},+	{8661, 31, &rule13},+	{8692, 268, &rule6},+	{8960, 8, &rule13},+	{8968, 1, &rule4},+	{8969, 1, &rule5},+	{8970, 1, &rule4},+	{8971, 1, &rule5},+	{8972, 20, &rule13},+	{8992, 2, &rule6},+	{8994, 7, &rule13},+	{9001, 1, &rule4},+	{9002, 1, &rule5},+	{9003, 81, &rule13},+	{9084, 1, &rule6},+	{9085, 30, &rule13},+	{9115, 25, &rule6},+	{9140, 40, &rule13},+	{9180, 6, &rule6},+	{9186, 25, &rule13},+	{9216, 39, &rule13},+	{9280, 11, &rule13},+	{9312, 60, &rule17},+	{9372, 26, &rule13},+	{9398, 26, &rule156},+	{9424, 26, &rule157},+	{9450, 22, &rule17},+	{9472, 183, &rule13},+	{9655, 1, &rule6},+	{9656, 9, &rule13},+	{9665, 1, &rule6},+	{9666, 54, &rule13},+	{9720, 8, &rule6},+	{9728, 111, &rule13},+	{9839, 1, &rule6},+	{9840, 248, &rule13},+	{10088, 1, &rule4},+	{10089, 1, &rule5},+	{10090, 1, &rule4},+	{10091, 1, &rule5},+	{10092, 1, &rule4},+	{10093, 1, &rule5},+	{10094, 1, &rule4},+	{10095, 1, &rule5},+	{10096, 1, &rule4},+	{10097, 1, &rule5},+	{10098, 1, &rule4},+	{10099, 1, &rule5},+	{10100, 1, &rule4},+	{10101, 1, &rule5},+	{10102, 30, &rule17},+	{10132, 44, &rule13},+	{10176, 5, &rule6},+	{10181, 1, &rule4},+	{10182, 1, &rule5},+	{10183, 31, &rule6},+	{10214, 1, &rule4},+	{10215, 1, &rule5},+	{10216, 1, &rule4},+	{10217, 1, &rule5},+	{10218, 1, &rule4},+	{10219, 1, &rule5},+	{10220, 1, &rule4},+	{10221, 1, &rule5},+	{10222, 1, &rule4},+	{10223, 1, &rule5},+	{10224, 16, &rule6},+	{10240, 256, &rule13},+	{10496, 131, &rule6},+	{10627, 1, &rule4},+	{10628, 1, &rule5},+	{10629, 1, &rule4},+	{10630, 1, &rule5},+	{10631, 1, &rule4},+	{10632, 1, &rule5},+	{10633, 1, &rule4},+	{10634, 1, &rule5},+	{10635, 1, &rule4},+	{10636, 1, &rule5},+	{10637, 1, &rule4},+	{10638, 1, &rule5},+	{10639, 1, &rule4},+	{10640, 1, &rule5},+	{10641, 1, &rule4},+	{10642, 1, &rule5},+	{10643, 1, &rule4},+	{10644, 1, &rule5},+	{10645, 1, &rule4},+	{10646, 1, &rule5},+	{10647, 1, &rule4},+	{10648, 1, &rule5},+	{10649, 63, &rule6},+	{10712, 1, &rule4},+	{10713, 1, &rule5},+	{10714, 1, &rule4},+	{10715, 1, &rule5},+	{10716, 32, &rule6},+	{10748, 1, &rule4},+	{10749, 1, &rule5},+	{10750, 258, &rule6},+	{11008, 48, &rule13},+	{11056, 21, &rule6},+	{11077, 2, &rule13},+	{11079, 6, &rule6},+	{11085, 39, &rule13},+	{11126, 32, &rule13},+	{11160, 34, &rule13},+	{11197, 12, &rule13},+	{11210, 8, &rule13},+	{11264, 47, &rule120},+	{11312, 47, &rule121},+	{11360, 1, &rule22},+	{11361, 1, &rule23},+	{11362, 1, &rule158},+	{11363, 1, &rule159},+	{11364, 1, &rule160},+	{11365, 1, &rule161},+	{11366, 1, &rule162},+	{11367, 1, &rule22},+	{11368, 1, &rule23},+	{11369, 1, &rule22},+	{11370, 1, &rule23},+	{11371, 1, &rule22},+	{11372, 1, &rule23},+	{11373, 1, &rule163},+	{11374, 1, &rule164},+	{11375, 1, &rule165},+	{11376, 1, &rule166},+	{11377, 1, &rule20},+	{11378, 1, &rule22},+	{11379, 1, &rule23},+	{11380, 1, &rule20},+	{11381, 1, &rule22},+	{11382, 1, &rule23},+	{11383, 5, &rule20},+	{11388, 2, &rule89},+	{11390, 2, &rule167},+	{11392, 1, &rule22},+	{11393, 1, &rule23},+	{11394, 1, &rule22},+	{11395, 1, &rule23},+	{11396, 1, &rule22},+	{11397, 1, &rule23},+	{11398, 1, &rule22},+	{11399, 1, &rule23},+	{11400, 1, &rule22},+	{11401, 1, &rule23},+	{11402, 1, &rule22},+	{11403, 1, &rule23},+	{11404, 1, &rule22},+	{11405, 1, &rule23},+	{11406, 1, &rule22},+	{11407, 1, &rule23},+	{11408, 1, &rule22},+	{11409, 1, &rule23},+	{11410, 1, &rule22},+	{11411, 1, &rule23},+	{11412, 1, &rule22},+	{11413, 1, &rule23},+	{11414, 1, &rule22},+	{11415, 1, &rule23},+	{11416, 1, &rule22},+	{11417, 1, &rule23},+	{11418, 1, &rule22},+	{11419, 1, &rule23},+	{11420, 1, &rule22},+	{11421, 1, &rule23},+	{11422, 1, &rule22},+	{11423, 1, &rule23},+	{11424, 1, &rule22},+	{11425, 1, &rule23},+	{11426, 1, &rule22},+	{11427, 1, &rule23},+	{11428, 1, &rule22},+	{11429, 1, &rule23},+	{11430, 1, &rule22},+	{11431, 1, &rule23},+	{11432, 1, &rule22},+	{11433, 1, &rule23},+	{11434, 1, &rule22},+	{11435, 1, &rule23},+	{11436, 1, &rule22},+	{11437, 1, &rule23},+	{11438, 1, &rule22},+	{11439, 1, &rule23},+	{11440, 1, &rule22},+	{11441, 1, &rule23},+	{11442, 1, &rule22},+	{11443, 1, &rule23},+	{11444, 1, &rule22},+	{11445, 1, &rule23},+	{11446, 1, &rule22},+	{11447, 1, &rule23},+	{11448, 1, &rule22},+	{11449, 1, &rule23},+	{11450, 1, &rule22},+	{11451, 1, &rule23},+	{11452, 1, &rule22},+	{11453, 1, &rule23},+	{11454, 1, &rule22},+	{11455, 1, &rule23},+	{11456, 1, &rule22},+	{11457, 1, &rule23},+	{11458, 1, &rule22},+	{11459, 1, &rule23},+	{11460, 1, &rule22},+	{11461, 1, &rule23},+	{11462, 1, &rule22},+	{11463, 1, &rule23},+	{11464, 1, &rule22},+	{11465, 1, &rule23},+	{11466, 1, &rule22},+	{11467, 1, &rule23},+	{11468, 1, &rule22},+	{11469, 1, &rule23},+	{11470, 1, &rule22},+	{11471, 1, &rule23},+	{11472, 1, &rule22},+	{11473, 1, &rule23},+	{11474, 1, &rule22},+	{11475, 1, &rule23},+	{11476, 1, &rule22},+	{11477, 1, &rule23},+	{11478, 1, &rule22},+	{11479, 1, &rule23},+	{11480, 1, &rule22},+	{11481, 1, &rule23},+	{11482, 1, &rule22},+	{11483, 1, &rule23},+	{11484, 1, &rule22},+	{11485, 1, &rule23},+	{11486, 1, &rule22},+	{11487, 1, &rule23},+	{11488, 1, &rule22},+	{11489, 1, &rule23},+	{11490, 1, &rule22},+	{11491, 1, &rule23},+	{11492, 1, &rule20},+	{11493, 6, &rule13},+	{11499, 1, &rule22},+	{11500, 1, &rule23},+	{11501, 1, &rule22},+	{11502, 1, &rule23},+	{11503, 3, &rule90},+	{11506, 1, &rule22},+	{11507, 1, &rule23},+	{11513, 4, &rule2},+	{11517, 1, &rule17},+	{11518, 2, &rule2},+	{11520, 38, &rule168},+	{11559, 1, &rule168},+	{11565, 1, &rule168},+	{11568, 56, &rule14},+	{11631, 1, &rule89},+	{11632, 1, &rule2},+	{11647, 1, &rule90},+	{11648, 23, &rule14},+	{11680, 7, &rule14},+	{11688, 7, &rule14},+	{11696, 7, &rule14},+	{11704, 7, &rule14},+	{11712, 7, &rule14},+	{11720, 7, &rule14},+	{11728, 7, &rule14},+	{11736, 7, &rule14},+	{11744, 32, &rule90},+	{11776, 2, &rule2},+	{11778, 1, &rule15},+	{11779, 1, &rule19},+	{11780, 1, &rule15},+	{11781, 1, &rule19},+	{11782, 3, &rule2},+	{11785, 1, &rule15},+	{11786, 1, &rule19},+	{11787, 1, &rule2},+	{11788, 1, &rule15},+	{11789, 1, &rule19},+	{11790, 9, &rule2},+	{11799, 1, &rule7},+	{11800, 2, &rule2},+	{11802, 1, &rule7},+	{11803, 1, &rule2},+	{11804, 1, &rule15},+	{11805, 1, &rule19},+	{11806, 2, &rule2},+	{11808, 1, &rule15},+	{11809, 1, &rule19},+	{11810, 1, &rule4},+	{11811, 1, &rule5},+	{11812, 1, &rule4},+	{11813, 1, &rule5},+	{11814, 1, &rule4},+	{11815, 1, &rule5},+	{11816, 1, &rule4},+	{11817, 1, &rule5},+	{11818, 5, &rule2},+	{11823, 1, &rule89},+	{11824, 10, &rule2},+	{11834, 2, &rule7},+	{11836, 4, &rule2},+	{11840, 1, &rule7},+	{11841, 1, &rule2},+	{11842, 1, &rule4},+	{11904, 26, &rule13},+	{11931, 89, &rule13},+	{12032, 214, &rule13},+	{12272, 12, &rule13},+	{12288, 1, &rule1},+	{12289, 3, &rule2},+	{12292, 1, &rule13},+	{12293, 1, &rule89},+	{12294, 1, &rule14},+	{12295, 1, &rule124},+	{12296, 1, &rule4},+	{12297, 1, &rule5},+	{12298, 1, &rule4},+	{12299, 1, &rule5},+	{12300, 1, &rule4},+	{12301, 1, &rule5},+	{12302, 1, &rule4},+	{12303, 1, &rule5},+	{12304, 1, &rule4},+	{12305, 1, &rule5},+	{12306, 2, &rule13},+	{12308, 1, &rule4},+	{12309, 1, &rule5},+	{12310, 1, &rule4},+	{12311, 1, &rule5},+	{12312, 1, &rule4},+	{12313, 1, &rule5},+	{12314, 1, &rule4},+	{12315, 1, &rule5},+	{12316, 1, &rule7},+	{12317, 1, &rule4},+	{12318, 2, &rule5},+	{12320, 1, &rule13},+	{12321, 9, &rule124},+	{12330, 4, &rule90},+	{12334, 2, &rule122},+	{12336, 1, &rule7},+	{12337, 5, &rule89},+	{12342, 2, &rule13},+	{12344, 3, &rule124},+	{12347, 1, &rule89},+	{12348, 1, &rule14},+	{12349, 1, &rule2},+	{12350, 2, &rule13},+	{12353, 86, &rule14},+	{12441, 2, &rule90},+	{12443, 2, &rule10},+	{12445, 2, &rule89},+	{12447, 1, &rule14},+	{12448, 1, &rule7},+	{12449, 90, &rule14},+	{12539, 1, &rule2},+	{12540, 3, &rule89},+	{12543, 1, &rule14},+	{12549, 41, &rule14},+	{12593, 94, &rule14},+	{12688, 2, &rule13},+	{12690, 4, &rule17},+	{12694, 10, &rule13},+	{12704, 27, &rule14},+	{12736, 36, &rule13},+	{12784, 16, &rule14},+	{12800, 31, &rule13},+	{12832, 10, &rule17},+	{12842, 30, &rule13},+	{12872, 8, &rule17},+	{12880, 1, &rule13},+	{12881, 15, &rule17},+	{12896, 32, &rule13},+	{12928, 10, &rule17},+	{12938, 39, &rule13},+	{12977, 15, &rule17},+	{12992, 63, &rule13},+	{13056, 256, &rule13},+	{13312, 6582, &rule14},+	{19904, 64, &rule13},+	{19968, 20941, &rule14},+	{40960, 21, &rule14},+	{40981, 1, &rule89},+	{40982, 1143, &rule14},+	{42128, 55, &rule13},+	{42192, 40, &rule14},+	{42232, 6, &rule89},+	{42238, 2, &rule2},+	{42240, 268, &rule14},+	{42508, 1, &rule89},+	{42509, 3, &rule2},+	{42512, 16, &rule14},+	{42528, 10, &rule8},+	{42538, 2, &rule14},+	{42560, 1, &rule22},+	{42561, 1, &rule23},+	{42562, 1, &rule22},+	{42563, 1, &rule23},+	{42564, 1, &rule22},+	{42565, 1, &rule23},+	{42566, 1, &rule22},+	{42567, 1, &rule23},+	{42568, 1, &rule22},+	{42569, 1, &rule23},+	{42570, 1, &rule22},+	{42571, 1, &rule23},+	{42572, 1, &rule22},+	{42573, 1, &rule23},+	{42574, 1, &rule22},+	{42575, 1, &rule23},+	{42576, 1, &rule22},+	{42577, 1, &rule23},+	{42578, 1, &rule22},+	{42579, 1, &rule23},+	{42580, 1, &rule22},+	{42581, 1, &rule23},+	{42582, 1, &rule22},+	{42583, 1, &rule23},+	{42584, 1, &rule22},+	{42585, 1, &rule23},+	{42586, 1, &rule22},+	{42587, 1, &rule23},+	{42588, 1, &rule22},+	{42589, 1, &rule23},+	{42590, 1, &rule22},+	{42591, 1, &rule23},+	{42592, 1, &rule22},+	{42593, 1, &rule23},+	{42594, 1, &rule22},+	{42595, 1, &rule23},+	{42596, 1, &rule22},+	{42597, 1, &rule23},+	{42598, 1, &rule22},+	{42599, 1, &rule23},+	{42600, 1, &rule22},+	{42601, 1, &rule23},+	{42602, 1, &rule22},+	{42603, 1, &rule23},+	{42604, 1, &rule22},+	{42605, 1, &rule23},+	{42606, 1, &rule14},+	{42607, 1, &rule90},+	{42608, 3, &rule117},+	{42611, 1, &rule2},+	{42612, 10, &rule90},+	{42622, 1, &rule2},+	{42623, 1, &rule89},+	{42624, 1, &rule22},+	{42625, 1, &rule23},+	{42626, 1, &rule22},+	{42627, 1, &rule23},+	{42628, 1, &rule22},+	{42629, 1, &rule23},+	{42630, 1, &rule22},+	{42631, 1, &rule23},+	{42632, 1, &rule22},+	{42633, 1, &rule23},+	{42634, 1, &rule22},+	{42635, 1, &rule23},+	{42636, 1, &rule22},+	{42637, 1, &rule23},+	{42638, 1, &rule22},+	{42639, 1, &rule23},+	{42640, 1, &rule22},+	{42641, 1, &rule23},+	{42642, 1, &rule22},+	{42643, 1, &rule23},+	{42644, 1, &rule22},+	{42645, 1, &rule23},+	{42646, 1, &rule22},+	{42647, 1, &rule23},+	{42648, 1, &rule22},+	{42649, 1, &rule23},+	{42650, 1, &rule22},+	{42651, 1, &rule23},+	{42652, 2, &rule89},+	{42655, 1, &rule90},+	{42656, 70, &rule14},+	{42726, 10, &rule124},+	{42736, 2, &rule90},+	{42738, 6, &rule2},+	{42752, 23, &rule10},+	{42775, 9, &rule89},+	{42784, 2, &rule10},+	{42786, 1, &rule22},+	{42787, 1, &rule23},+	{42788, 1, &rule22},+	{42789, 1, &rule23},+	{42790, 1, &rule22},+	{42791, 1, &rule23},+	{42792, 1, &rule22},+	{42793, 1, &rule23},+	{42794, 1, &rule22},+	{42795, 1, &rule23},+	{42796, 1, &rule22},+	{42797, 1, &rule23},+	{42798, 1, &rule22},+	{42799, 1, &rule23},+	{42800, 2, &rule20},+	{42802, 1, &rule22},+	{42803, 1, &rule23},+	{42804, 1, &rule22},+	{42805, 1, &rule23},+	{42806, 1, &rule22},+	{42807, 1, &rule23},+	{42808, 1, &rule22},+	{42809, 1, &rule23},+	{42810, 1, &rule22},+	{42811, 1, &rule23},+	{42812, 1, &rule22},+	{42813, 1, &rule23},+	{42814, 1, &rule22},+	{42815, 1, &rule23},+	{42816, 1, &rule22},+	{42817, 1, &rule23},+	{42818, 1, &rule22},+	{42819, 1, &rule23},+	{42820, 1, &rule22},+	{42821, 1, &rule23},+	{42822, 1, &rule22},+	{42823, 1, &rule23},+	{42824, 1, &rule22},+	{42825, 1, &rule23},+	{42826, 1, &rule22},+	{42827, 1, &rule23},+	{42828, 1, &rule22},+	{42829, 1, &rule23},+	{42830, 1, &rule22},+	{42831, 1, &rule23},+	{42832, 1, &rule22},+	{42833, 1, &rule23},+	{42834, 1, &rule22},+	{42835, 1, &rule23},+	{42836, 1, &rule22},+	{42837, 1, &rule23},+	{42838, 1, &rule22},+	{42839, 1, &rule23},+	{42840, 1, &rule22},+	{42841, 1, &rule23},+	{42842, 1, &rule22},+	{42843, 1, &rule23},+	{42844, 1, &rule22},+	{42845, 1, &rule23},+	{42846, 1, &rule22},+	{42847, 1, &rule23},+	{42848, 1, &rule22},+	{42849, 1, &rule23},+	{42850, 1, &rule22},+	{42851, 1, &rule23},+	{42852, 1, &rule22},+	{42853, 1, &rule23},+	{42854, 1, &rule22},+	{42855, 1, &rule23},+	{42856, 1, &rule22},+	{42857, 1, &rule23},+	{42858, 1, &rule22},+	{42859, 1, &rule23},+	{42860, 1, &rule22},+	{42861, 1, &rule23},+	{42862, 1, &rule22},+	{42863, 1, &rule23},+	{42864, 1, &rule89},+	{42865, 8, &rule20},+	{42873, 1, &rule22},+	{42874, 1, &rule23},+	{42875, 1, &rule22},+	{42876, 1, &rule23},+	{42877, 1, &rule169},+	{42878, 1, &rule22},+	{42879, 1, &rule23},+	{42880, 1, &rule22},+	{42881, 1, &rule23},+	{42882, 1, &rule22},+	{42883, 1, &rule23},+	{42884, 1, &rule22},+	{42885, 1, &rule23},+	{42886, 1, &rule22},+	{42887, 1, &rule23},+	{42888, 1, &rule89},+	{42889, 2, &rule10},+	{42891, 1, &rule22},+	{42892, 1, &rule23},+	{42893, 1, &rule170},+	{42894, 1, &rule20},+	{42896, 1, &rule22},+	{42897, 1, &rule23},+	{42898, 1, &rule22},+	{42899, 1, &rule23},+	{42900, 2, &rule20},+	{42902, 1, &rule22},+	{42903, 1, &rule23},+	{42904, 1, &rule22},+	{42905, 1, &rule23},+	{42906, 1, &rule22},+	{42907, 1, &rule23},+	{42908, 1, &rule22},+	{42909, 1, &rule23},+	{42910, 1, &rule22},+	{42911, 1, &rule23},+	{42912, 1, &rule22},+	{42913, 1, &rule23},+	{42914, 1, &rule22},+	{42915, 1, &rule23},+	{42916, 1, &rule22},+	{42917, 1, &rule23},+	{42918, 1, &rule22},+	{42919, 1, &rule23},+	{42920, 1, &rule22},+	{42921, 1, &rule23},+	{42922, 1, &rule171},+	{42923, 1, &rule172},+	{42924, 1, &rule173},+	{42925, 1, &rule174},+	{42928, 1, &rule175},+	{42929, 1, &rule176},+	{42999, 1, &rule14},+	{43000, 2, &rule89},+	{43002, 1, &rule20},+	{43003, 7, &rule14},+	{43010, 1, &rule90},+	{43011, 3, &rule14},+	{43014, 1, &rule90},+	{43015, 4, &rule14},+	{43019, 1, &rule90},+	{43020, 23, &rule14},+	{43043, 2, &rule122},+	{43045, 2, &rule90},+	{43047, 1, &rule122},+	{43048, 4, &rule13},+	{43056, 6, &rule17},+	{43062, 2, &rule13},+	{43064, 1, &rule3},+	{43065, 1, &rule13},+	{43072, 52, &rule14},+	{43124, 4, &rule2},+	{43136, 2, &rule122},+	{43138, 50, &rule14},+	{43188, 16, &rule122},+	{43204, 1, &rule90},+	{43214, 2, &rule2},+	{43216, 10, &rule8},+	{43232, 18, &rule90},+	{43250, 6, &rule14},+	{43256, 3, &rule2},+	{43259, 1, &rule14},+	{43264, 10, &rule8},+	{43274, 28, &rule14},+	{43302, 8, &rule90},+	{43310, 2, &rule2},+	{43312, 23, &rule14},+	{43335, 11, &rule90},+	{43346, 2, &rule122},+	{43359, 1, &rule2},+	{43360, 29, &rule14},+	{43392, 3, &rule90},+	{43395, 1, &rule122},+	{43396, 47, &rule14},+	{43443, 1, &rule90},+	{43444, 2, &rule122},+	{43446, 4, &rule90},+	{43450, 2, &rule122},+	{43452, 1, &rule90},+	{43453, 4, &rule122},+	{43457, 13, &rule2},+	{43471, 1, &rule89},+	{43472, 10, &rule8},+	{43486, 2, &rule2},+	{43488, 5, &rule14},+	{43493, 1, &rule90},+	{43494, 1, &rule89},+	{43495, 9, &rule14},+	{43504, 10, &rule8},+	{43514, 5, &rule14},+	{43520, 41, &rule14},+	{43561, 6, &rule90},+	{43567, 2, &rule122},+	{43569, 2, &rule90},+	{43571, 2, &rule122},+	{43573, 2, &rule90},+	{43584, 3, &rule14},+	{43587, 1, &rule90},+	{43588, 8, &rule14},+	{43596, 1, &rule90},+	{43597, 1, &rule122},+	{43600, 10, &rule8},+	{43612, 4, &rule2},+	{43616, 16, &rule14},+	{43632, 1, &rule89},+	{43633, 6, &rule14},+	{43639, 3, &rule13},+	{43642, 1, &rule14},+	{43643, 1, &rule122},+	{43644, 1, &rule90},+	{43645, 1, &rule122},+	{43646, 50, &rule14},+	{43696, 1, &rule90},+	{43697, 1, &rule14},+	{43698, 3, &rule90},+	{43701, 2, &rule14},+	{43703, 2, &rule90},+	{43705, 5, &rule14},+	{43710, 2, &rule90},+	{43712, 1, &rule14},+	{43713, 1, &rule90},+	{43714, 1, &rule14},+	{43739, 2, &rule14},+	{43741, 1, &rule89},+	{43742, 2, &rule2},+	{43744, 11, &rule14},+	{43755, 1, &rule122},+	{43756, 2, &rule90},+	{43758, 2, &rule122},+	{43760, 2, &rule2},+	{43762, 1, &rule14},+	{43763, 2, &rule89},+	{43765, 1, &rule122},+	{43766, 1, &rule90},+	{43777, 6, &rule14},+	{43785, 6, &rule14},+	{43793, 6, &rule14},+	{43808, 7, &rule14},+	{43816, 7, &rule14},+	{43824, 43, &rule20},+	{43867, 1, &rule10},+	{43868, 4, &rule89},+	{43876, 2, &rule20},+	{43968, 35, &rule14},+	{44003, 2, &rule122},+	{44005, 1, &rule90},+	{44006, 2, &rule122},+	{44008, 1, &rule90},+	{44009, 2, &rule122},+	{44011, 1, &rule2},+	{44012, 1, &rule122},+	{44013, 1, &rule90},+	{44016, 10, &rule8},+	{44032, 11172, &rule14},+	{55216, 23, &rule14},+	{55243, 49, &rule14},+	{55296, 896, &rule177},+	{56192, 128, &rule177},+	{56320, 1024, &rule177},+	{57344, 6400, &rule178},+	{63744, 366, &rule14},+	{64112, 106, &rule14},+	{64256, 7, &rule20},+	{64275, 5, &rule20},+	{64285, 1, &rule14},+	{64286, 1, &rule90},+	{64287, 10, &rule14},+	{64297, 1, &rule6},+	{64298, 13, &rule14},+	{64312, 5, &rule14},+	{64318, 1, &rule14},+	{64320, 2, &rule14},+	{64323, 2, &rule14},+	{64326, 108, &rule14},+	{64434, 16, &rule10},+	{64467, 363, &rule14},+	{64830, 1, &rule5},+	{64831, 1, &rule4},+	{64848, 64, &rule14},+	{64914, 54, &rule14},+	{65008, 12, &rule14},+	{65020, 1, &rule3},+	{65021, 1, &rule13},+	{65024, 16, &rule90},+	{65040, 7, &rule2},+	{65047, 1, &rule4},+	{65048, 1, &rule5},+	{65049, 1, &rule2},+	{65056, 14, &rule90},+	{65072, 1, &rule2},+	{65073, 2, &rule7},+	{65075, 2, &rule11},+	{65077, 1, &rule4},+	{65078, 1, &rule5},+	{65079, 1, &rule4},+	{65080, 1, &rule5},+	{65081, 1, &rule4},+	{65082, 1, &rule5},+	{65083, 1, &rule4},+	{65084, 1, &rule5},+	{65085, 1, &rule4},+	{65086, 1, &rule5},+	{65087, 1, &rule4},+	{65088, 1, &rule5},+	{65089, 1, &rule4},+	{65090, 1, &rule5},+	{65091, 1, &rule4},+	{65092, 1, &rule5},+	{65093, 2, &rule2},+	{65095, 1, &rule4},+	{65096, 1, &rule5},+	{65097, 4, &rule2},+	{65101, 3, &rule11},+	{65104, 3, &rule2},+	{65108, 4, &rule2},+	{65112, 1, &rule7},+	{65113, 1, &rule4},+	{65114, 1, &rule5},+	{65115, 1, &rule4},+	{65116, 1, &rule5},+	{65117, 1, &rule4},+	{65118, 1, &rule5},+	{65119, 3, &rule2},+	{65122, 1, &rule6},+	{65123, 1, &rule7},+	{65124, 3, &rule6},+	{65128, 1, &rule2},+	{65129, 1, &rule3},+	{65130, 2, &rule2},+	{65136, 5, &rule14},+	{65142, 135, &rule14},+	{65279, 1, &rule16},+	{65281, 3, &rule2},+	{65284, 1, &rule3},+	{65285, 3, &rule2},+	{65288, 1, &rule4},+	{65289, 1, &rule5},+	{65290, 1, &rule2},+	{65291, 1, &rule6},+	{65292, 1, &rule2},+	{65293, 1, &rule7},+	{65294, 2, &rule2},+	{65296, 10, &rule8},+	{65306, 2, &rule2},+	{65308, 3, &rule6},+	{65311, 2, &rule2},+	{65313, 26, &rule9},+	{65339, 1, &rule4},+	{65340, 1, &rule2},+	{65341, 1, &rule5},+	{65342, 1, &rule10},+	{65343, 1, &rule11},+	{65344, 1, &rule10},+	{65345, 26, &rule12},+	{65371, 1, &rule4},+	{65372, 1, &rule6},+	{65373, 1, &rule5},+	{65374, 1, &rule6},+	{65375, 1, &rule4},+	{65376, 1, &rule5},+	{65377, 1, &rule2},+	{65378, 1, &rule4},+	{65379, 1, &rule5},+	{65380, 2, &rule2},+	{65382, 10, &rule14},+	{65392, 1, &rule89},+	{65393, 45, &rule14},+	{65438, 2, &rule89},+	{65440, 31, &rule14},+	{65474, 6, &rule14},+	{65482, 6, &rule14},+	{65490, 6, &rule14},+	{65498, 3, &rule14},+	{65504, 2, &rule3},+	{65506, 1, &rule6},+	{65507, 1, &rule10},+	{65508, 1, &rule13},+	{65509, 2, &rule3},+	{65512, 1, &rule13},+	{65513, 4, &rule6},+	{65517, 2, &rule13},+	{65529, 3, &rule16},+	{65532, 2, &rule13},+	{65536, 12, &rule14},+	{65549, 26, &rule14},+	{65576, 19, &rule14},+	{65596, 2, &rule14},+	{65599, 15, &rule14},+	{65616, 14, &rule14},+	{65664, 123, &rule14},+	{65792, 3, &rule2},+	{65799, 45, &rule17},+	{65847, 9, &rule13},+	{65856, 53, &rule124},+	{65909, 4, &rule17},+	{65913, 17, &rule13},+	{65930, 2, &rule17},+	{65932, 1, &rule13},+	{65936, 12, &rule13},+	{65952, 1, &rule13},+	{66000, 45, &rule13},+	{66045, 1, &rule90},+	{66176, 29, &rule14},+	{66208, 49, &rule14},+	{66272, 1, &rule90},+	{66273, 27, &rule17},+	{66304, 32, &rule14},+	{66336, 4, &rule17},+	{66352, 17, &rule14},+	{66369, 1, &rule124},+	{66370, 8, &rule14},+	{66378, 1, &rule124},+	{66384, 38, &rule14},+	{66422, 5, &rule90},+	{66432, 30, &rule14},+	{66463, 1, &rule2},+	{66464, 36, &rule14},+	{66504, 8, &rule14},+	{66512, 1, &rule2},+	{66513, 5, &rule124},+	{66560, 40, &rule179},+	{66600, 40, &rule180},+	{66640, 78, &rule14},+	{66720, 10, &rule8},+	{66816, 40, &rule14},+	{66864, 52, &rule14},+	{66927, 1, &rule2},+	{67072, 311, &rule14},+	{67392, 22, &rule14},+	{67424, 8, &rule14},+	{67584, 6, &rule14},+	{67592, 1, &rule14},+	{67594, 44, &rule14},+	{67639, 2, &rule14},+	{67644, 1, &rule14},+	{67647, 23, &rule14},+	{67671, 1, &rule2},+	{67672, 8, &rule17},+	{67680, 23, &rule14},+	{67703, 2, &rule13},+	{67705, 7, &rule17},+	{67712, 31, &rule14},+	{67751, 9, &rule17},+	{67840, 22, &rule14},+	{67862, 6, &rule17},+	{67871, 1, &rule2},+	{67872, 26, &rule14},+	{67903, 1, &rule2},+	{67968, 56, &rule14},+	{68030, 2, &rule14},+	{68096, 1, &rule14},+	{68097, 3, &rule90},+	{68101, 2, &rule90},+	{68108, 4, &rule90},+	{68112, 4, &rule14},+	{68117, 3, &rule14},+	{68121, 27, &rule14},+	{68152, 3, &rule90},+	{68159, 1, &rule90},+	{68160, 8, &rule17},+	{68176, 9, &rule2},+	{68192, 29, &rule14},+	{68221, 2, &rule17},+	{68223, 1, &rule2},+	{68224, 29, &rule14},+	{68253, 3, &rule17},+	{68288, 8, &rule14},+	{68296, 1, &rule13},+	{68297, 28, &rule14},+	{68325, 2, &rule90},+	{68331, 5, &rule17},+	{68336, 7, &rule2},+	{68352, 54, &rule14},+	{68409, 7, &rule2},+	{68416, 22, &rule14},+	{68440, 8, &rule17},+	{68448, 19, &rule14},+	{68472, 8, &rule17},+	{68480, 18, &rule14},+	{68505, 4, &rule2},+	{68521, 7, &rule17},+	{68608, 73, &rule14},+	{69216, 31, &rule17},+	{69632, 1, &rule122},+	{69633, 1, &rule90},+	{69634, 1, &rule122},+	{69635, 53, &rule14},+	{69688, 15, &rule90},+	{69703, 7, &rule2},+	{69714, 20, &rule17},+	{69734, 10, &rule8},+	{69759, 3, &rule90},+	{69762, 1, &rule122},+	{69763, 45, &rule14},+	{69808, 3, &rule122},+	{69811, 4, &rule90},+	{69815, 2, &rule122},+	{69817, 2, &rule90},+	{69819, 2, &rule2},+	{69821, 1, &rule16},+	{69822, 4, &rule2},+	{69840, 25, &rule14},+	{69872, 10, &rule8},+	{69888, 3, &rule90},+	{69891, 36, &rule14},+	{69927, 5, &rule90},+	{69932, 1, &rule122},+	{69933, 8, &rule90},+	{69942, 10, &rule8},+	{69952, 4, &rule2},+	{69968, 35, &rule14},+	{70003, 1, &rule90},+	{70004, 2, &rule2},+	{70006, 1, &rule14},+	{70016, 2, &rule90},+	{70018, 1, &rule122},+	{70019, 48, &rule14},+	{70067, 3, &rule122},+	{70070, 9, &rule90},+	{70079, 2, &rule122},+	{70081, 4, &rule14},+	{70085, 4, &rule2},+	{70093, 1, &rule2},+	{70096, 10, &rule8},+	{70106, 1, &rule14},+	{70113, 20, &rule17},+	{70144, 18, &rule14},+	{70163, 25, &rule14},+	{70188, 3, &rule122},+	{70191, 3, &rule90},+	{70194, 2, &rule122},+	{70196, 1, &rule90},+	{70197, 1, &rule122},+	{70198, 2, &rule90},+	{70200, 6, &rule2},+	{70320, 47, &rule14},+	{70367, 1, &rule90},+	{70368, 3, &rule122},+	{70371, 8, &rule90},+	{70384, 10, &rule8},+	{70401, 1, &rule90},+	{70402, 2, &rule122},+	{70405, 8, &rule14},+	{70415, 2, &rule14},+	{70419, 22, &rule14},+	{70442, 7, &rule14},+	{70450, 2, &rule14},+	{70453, 5, &rule14},+	{70460, 1, &rule90},+	{70461, 1, &rule14},+	{70462, 2, &rule122},+	{70464, 1, &rule90},+	{70465, 4, &rule122},+	{70471, 2, &rule122},+	{70475, 3, &rule122},+	{70487, 1, &rule122},+	{70493, 5, &rule14},+	{70498, 2, &rule122},+	{70502, 7, &rule90},+	{70512, 5, &rule90},+	{70784, 48, &rule14},+	{70832, 3, &rule122},+	{70835, 6, &rule90},+	{70841, 1, &rule122},+	{70842, 1, &rule90},+	{70843, 4, &rule122},+	{70847, 2, &rule90},+	{70849, 1, &rule122},+	{70850, 2, &rule90},+	{70852, 2, &rule14},+	{70854, 1, &rule2},+	{70855, 1, &rule14},+	{70864, 10, &rule8},+	{71040, 47, &rule14},+	{71087, 3, &rule122},+	{71090, 4, &rule90},+	{71096, 4, &rule122},+	{71100, 2, &rule90},+	{71102, 1, &rule122},+	{71103, 2, &rule90},+	{71105, 9, &rule2},+	{71168, 48, &rule14},+	{71216, 3, &rule122},+	{71219, 8, &rule90},+	{71227, 2, &rule122},+	{71229, 1, &rule90},+	{71230, 1, &rule122},+	{71231, 2, &rule90},+	{71233, 3, &rule2},+	{71236, 1, &rule14},+	{71248, 10, &rule8},+	{71296, 43, &rule14},+	{71339, 1, &rule90},+	{71340, 1, &rule122},+	{71341, 1, &rule90},+	{71342, 2, &rule122},+	{71344, 6, &rule90},+	{71350, 1, &rule122},+	{71351, 1, &rule90},+	{71360, 10, &rule8},+	{71840, 32, &rule9},+	{71872, 32, &rule12},+	{71904, 10, &rule8},+	{71914, 9, &rule17},+	{71935, 1, &rule14},+	{72384, 57, &rule14},+	{73728, 921, &rule14},+	{74752, 111, &rule124},+	{74864, 5, &rule2},+	{77824, 1071, &rule14},+	{92160, 569, &rule14},+	{92736, 31, &rule14},+	{92768, 10, &rule8},+	{92782, 2, &rule2},+	{92880, 30, &rule14},+	{92912, 5, &rule90},+	{92917, 1, &rule2},+	{92928, 48, &rule14},+	{92976, 7, &rule90},+	{92983, 5, &rule2},+	{92988, 4, &rule13},+	{92992, 4, &rule89},+	{92996, 1, &rule2},+	{92997, 1, &rule13},+	{93008, 10, &rule8},+	{93019, 7, &rule17},+	{93027, 21, &rule14},+	{93053, 19, &rule14},+	{93952, 69, &rule14},+	{94032, 1, &rule14},+	{94033, 46, &rule122},+	{94095, 4, &rule90},+	{94099, 13, &rule89},+	{110592, 2, &rule14},+	{113664, 107, &rule14},+	{113776, 13, &rule14},+	{113792, 9, &rule14},+	{113808, 10, &rule14},+	{113820, 1, &rule13},+	{113821, 2, &rule90},+	{113823, 1, &rule2},+	{113824, 4, &rule16},+	{118784, 246, &rule13},+	{119040, 39, &rule13},+	{119081, 60, &rule13},+	{119141, 2, &rule122},+	{119143, 3, &rule90},+	{119146, 3, &rule13},+	{119149, 6, &rule122},+	{119155, 8, &rule16},+	{119163, 8, &rule90},+	{119171, 2, &rule13},+	{119173, 7, &rule90},+	{119180, 30, &rule13},+	{119210, 4, &rule90},+	{119214, 48, &rule13},+	{119296, 66, &rule13},+	{119362, 3, &rule90},+	{119365, 1, &rule13},+	{119552, 87, &rule13},+	{119648, 18, &rule17},+	{119808, 26, &rule105},+	{119834, 26, &rule20},+	{119860, 26, &rule105},+	{119886, 7, &rule20},+	{119894, 18, &rule20},+	{119912, 26, &rule105},+	{119938, 26, &rule20},+	{119964, 1, &rule105},+	{119966, 2, &rule105},+	{119970, 1, &rule105},+	{119973, 2, &rule105},+	{119977, 4, &rule105},+	{119982, 8, &rule105},+	{119990, 4, &rule20},+	{119995, 1, &rule20},+	{119997, 7, &rule20},+	{120005, 11, &rule20},+	{120016, 26, &rule105},+	{120042, 26, &rule20},+	{120068, 2, &rule105},+	{120071, 4, &rule105},+	{120077, 8, &rule105},+	{120086, 7, &rule105},+	{120094, 26, &rule20},+	{120120, 2, &rule105},+	{120123, 4, &rule105},+	{120128, 5, &rule105},+	{120134, 1, &rule105},+	{120138, 7, &rule105},+	{120146, 26, &rule20},+	{120172, 26, &rule105},+	{120198, 26, &rule20},+	{120224, 26, &rule105},+	{120250, 26, &rule20},+	{120276, 26, &rule105},+	{120302, 26, &rule20},+	{120328, 26, &rule105},+	{120354, 26, &rule20},+	{120380, 26, &rule105},+	{120406, 26, &rule20},+	{120432, 26, &rule105},+	{120458, 28, &rule20},+	{120488, 25, &rule105},+	{120513, 1, &rule6},+	{120514, 25, &rule20},+	{120539, 1, &rule6},+	{120540, 6, &rule20},+	{120546, 25, &rule105},+	{120571, 1, &rule6},+	{120572, 25, &rule20},+	{120597, 1, &rule6},+	{120598, 6, &rule20},+	{120604, 25, &rule105},+	{120629, 1, &rule6},+	{120630, 25, &rule20},+	{120655, 1, &rule6},+	{120656, 6, &rule20},+	{120662, 25, &rule105},+	{120687, 1, &rule6},+	{120688, 25, &rule20},+	{120713, 1, &rule6},+	{120714, 6, &rule20},+	{120720, 25, &rule105},+	{120745, 1, &rule6},+	{120746, 25, &rule20},+	{120771, 1, &rule6},+	{120772, 6, &rule20},+	{120778, 1, &rule105},+	{120779, 1, &rule20},+	{120782, 50, &rule8},+	{124928, 197, &rule14},+	{125127, 9, &rule17},+	{125136, 7, &rule90},+	{126464, 4, &rule14},+	{126469, 27, &rule14},+	{126497, 2, &rule14},+	{126500, 1, &rule14},+	{126503, 1, &rule14},+	{126505, 10, &rule14},+	{126516, 4, &rule14},+	{126521, 1, &rule14},+	{126523, 1, &rule14},+	{126530, 1, &rule14},+	{126535, 1, &rule14},+	{126537, 1, &rule14},+	{126539, 1, &rule14},+	{126541, 3, &rule14},+	{126545, 2, &rule14},+	{126548, 1, &rule14},+	{126551, 1, &rule14},+	{126553, 1, &rule14},+	{126555, 1, &rule14},+	{126557, 1, &rule14},+	{126559, 1, &rule14},+	{126561, 2, &rule14},+	{126564, 1, &rule14},+	{126567, 4, &rule14},+	{126572, 7, &rule14},+	{126580, 4, &rule14},+	{126585, 4, &rule14},+	{126590, 1, &rule14},+	{126592, 10, &rule14},+	{126603, 17, &rule14},+	{126625, 3, &rule14},+	{126629, 5, &rule14},+	{126635, 17, &rule14},+	{126704, 2, &rule6},+	{126976, 44, &rule13},+	{127024, 100, &rule13},+	{127136, 15, &rule13},+	{127153, 15, &rule13},+	{127169, 15, &rule13},+	{127185, 37, &rule13},+	{127232, 13, &rule17},+	{127248, 31, &rule13},+	{127280, 60, &rule13},+	{127344, 43, &rule13},+	{127462, 29, &rule13},+	{127504, 43, &rule13},+	{127552, 9, &rule13},+	{127568, 2, &rule13},+	{127744, 45, &rule13},+	{127792, 78, &rule13},+	{127872, 79, &rule13},+	{127956, 36, &rule13},+	{128000, 255, &rule13},+	{128256, 75, &rule13},+	{128336, 42, &rule13},+	{128379, 41, &rule13},+	{128421, 158, &rule13},+	{128581, 139, &rule13},+	{128736, 13, &rule13},+	{128752, 4, &rule13},+	{128768, 116, &rule13},+	{128896, 85, &rule13},+	{129024, 12, &rule13},+	{129040, 56, &rule13},+	{129104, 10, &rule13},+	{129120, 40, &rule13},+	{129168, 30, &rule13},+	{131072, 42711, &rule14},+	{173824, 4149, &rule14},+	{177984, 222, &rule14},+	{194560, 542, &rule14},+	{917505, 1, &rule16},+	{917536, 96, &rule16},+	{917760, 240, &rule90},+	{983040, 65534, &rule178},+	{1048576, 65534, &rule178}+};+static const struct _charblock_ convchars[]={+	{65, 26, &rule9},+	{97, 26, &rule12},+	{181, 1, &rule18},+	{192, 23, &rule9},+	{216, 7, &rule9},+	{224, 23, &rule12},+	{248, 7, &rule12},+	{255, 1, &rule21},+	{256, 1, &rule22},+	{257, 1, &rule23},+	{258, 1, &rule22},+	{259, 1, &rule23},+	{260, 1, &rule22},+	{261, 1, &rule23},+	{262, 1, &rule22},+	{263, 1, &rule23},+	{264, 1, &rule22},+	{265, 1, &rule23},+	{266, 1, &rule22},+	{267, 1, &rule23},+	{268, 1, &rule22},+	{269, 1, &rule23},+	{270, 1, &rule22},+	{271, 1, &rule23},+	{272, 1, &rule22},+	{273, 1, &rule23},+	{274, 1, &rule22},+	{275, 1, &rule23},+	{276, 1, &rule22},+	{277, 1, &rule23},+	{278, 1, &rule22},+	{279, 1, &rule23},+	{280, 1, &rule22},+	{281, 1, &rule23},+	{282, 1, &rule22},+	{283, 1, &rule23},+	{284, 1, &rule22},+	{285, 1, &rule23},+	{286, 1, &rule22},+	{287, 1, &rule23},+	{288, 1, &rule22},+	{289, 1, &rule23},+	{290, 1, &rule22},+	{291, 1, &rule23},+	{292, 1, &rule22},+	{293, 1, &rule23},+	{294, 1, &rule22},+	{295, 1, &rule23},+	{296, 1, &rule22},+	{297, 1, &rule23},+	{298, 1, &rule22},+	{299, 1, &rule23},+	{300, 1, &rule22},+	{301, 1, &rule23},+	{302, 1, &rule22},+	{303, 1, &rule23},+	{304, 1, &rule24},+	{305, 1, &rule25},+	{306, 1, &rule22},+	{307, 1, &rule23},+	{308, 1, &rule22},+	{309, 1, &rule23},+	{310, 1, &rule22},+	{311, 1, &rule23},+	{313, 1, &rule22},+	{314, 1, &rule23},+	{315, 1, &rule22},+	{316, 1, &rule23},+	{317, 1, &rule22},+	{318, 1, &rule23},+	{319, 1, &rule22},+	{320, 1, &rule23},+	{321, 1, &rule22},+	{322, 1, &rule23},+	{323, 1, &rule22},+	{324, 1, &rule23},+	{325, 1, &rule22},+	{326, 1, &rule23},+	{327, 1, &rule22},+	{328, 1, &rule23},+	{330, 1, &rule22},+	{331, 1, &rule23},+	{332, 1, &rule22},+	{333, 1, &rule23},+	{334, 1, &rule22},+	{335, 1, &rule23},+	{336, 1, &rule22},+	{337, 1, &rule23},+	{338, 1, &rule22},+	{339, 1, &rule23},+	{340, 1, &rule22},+	{341, 1, &rule23},+	{342, 1, &rule22},+	{343, 1, &rule23},+	{344, 1, &rule22},+	{345, 1, &rule23},+	{346, 1, &rule22},+	{347, 1, &rule23},+	{348, 1, &rule22},+	{349, 1, &rule23},+	{350, 1, &rule22},+	{351, 1, &rule23},+	{352, 1, &rule22},+	{353, 1, &rule23},+	{354, 1, &rule22},+	{355, 1, &rule23},+	{356, 1, &rule22},+	{357, 1, &rule23},+	{358, 1, &rule22},+	{359, 1, &rule23},+	{360, 1, &rule22},+	{361, 1, &rule23},+	{362, 1, &rule22},+	{363, 1, &rule23},+	{364, 1, &rule22},+	{365, 1, &rule23},+	{366, 1, &rule22},+	{367, 1, &rule23},+	{368, 1, &rule22},+	{369, 1, &rule23},+	{370, 1, &rule22},+	{371, 1, &rule23},+	{372, 1, &rule22},+	{373, 1, &rule23},+	{374, 1, &rule22},+	{375, 1, &rule23},+	{376, 1, &rule26},+	{377, 1, &rule22},+	{378, 1, &rule23},+	{379, 1, &rule22},+	{380, 1, &rule23},+	{381, 1, &rule22},+	{382, 1, &rule23},+	{383, 1, &rule27},+	{384, 1, &rule28},+	{385, 1, &rule29},+	{386, 1, &rule22},+	{387, 1, &rule23},+	{388, 1, &rule22},+	{389, 1, &rule23},+	{390, 1, &rule30},+	{391, 1, &rule22},+	{392, 1, &rule23},+	{393, 2, &rule31},+	{395, 1, &rule22},+	{396, 1, &rule23},+	{398, 1, &rule32},+	{399, 1, &rule33},+	{400, 1, &rule34},+	{401, 1, &rule22},+	{402, 1, &rule23},+	{403, 1, &rule31},+	{404, 1, &rule35},+	{405, 1, &rule36},+	{406, 1, &rule37},+	{407, 1, &rule38},+	{408, 1, &rule22},+	{409, 1, &rule23},+	{410, 1, &rule39},+	{412, 1, &rule37},+	{413, 1, &rule40},+	{414, 1, &rule41},+	{415, 1, &rule42},+	{416, 1, &rule22},+	{417, 1, &rule23},+	{418, 1, &rule22},+	{419, 1, &rule23},+	{420, 1, &rule22},+	{421, 1, &rule23},+	{422, 1, &rule43},+	{423, 1, &rule22},+	{424, 1, &rule23},+	{425, 1, &rule43},+	{428, 1, &rule22},+	{429, 1, &rule23},+	{430, 1, &rule43},+	{431, 1, &rule22},+	{432, 1, &rule23},+	{433, 2, &rule44},+	{435, 1, &rule22},+	{436, 1, &rule23},+	{437, 1, &rule22},+	{438, 1, &rule23},+	{439, 1, &rule45},+	{440, 1, &rule22},+	{441, 1, &rule23},+	{444, 1, &rule22},+	{445, 1, &rule23},+	{447, 1, &rule46},+	{452, 1, &rule47},+	{453, 1, &rule48},+	{454, 1, &rule49},+	{455, 1, &rule47},+	{456, 1, &rule48},+	{457, 1, &rule49},+	{458, 1, &rule47},+	{459, 1, &rule48},+	{460, 1, &rule49},+	{461, 1, &rule22},+	{462, 1, &rule23},+	{463, 1, &rule22},+	{464, 1, &rule23},+	{465, 1, &rule22},+	{466, 1, &rule23},+	{467, 1, &rule22},+	{468, 1, &rule23},+	{469, 1, &rule22},+	{470, 1, &rule23},+	{471, 1, &rule22},+	{472, 1, &rule23},+	{473, 1, &rule22},+	{474, 1, &rule23},+	{475, 1, &rule22},+	{476, 1, &rule23},+	{477, 1, &rule50},+	{478, 1, &rule22},+	{479, 1, &rule23},+	{480, 1, &rule22},+	{481, 1, &rule23},+	{482, 1, &rule22},+	{483, 1, &rule23},+	{484, 1, &rule22},+	{485, 1, &rule23},+	{486, 1, &rule22},+	{487, 1, &rule23},+	{488, 1, &rule22},+	{489, 1, &rule23},+	{490, 1, &rule22},+	{491, 1, &rule23},+	{492, 1, &rule22},+	{493, 1, &rule23},+	{494, 1, &rule22},+	{495, 1, &rule23},+	{497, 1, &rule47},+	{498, 1, &rule48},+	{499, 1, &rule49},+	{500, 1, &rule22},+	{501, 1, &rule23},+	{502, 1, &rule51},+	{503, 1, &rule52},+	{504, 1, &rule22},+	{505, 1, &rule23},+	{506, 1, &rule22},+	{507, 1, &rule23},+	{508, 1, &rule22},+	{509, 1, &rule23},+	{510, 1, &rule22},+	{511, 1, &rule23},+	{512, 1, &rule22},+	{513, 1, &rule23},+	{514, 1, &rule22},+	{515, 1, &rule23},+	{516, 1, &rule22},+	{517, 1, &rule23},+	{518, 1, &rule22},+	{519, 1, &rule23},+	{520, 1, &rule22},+	{521, 1, &rule23},+	{522, 1, &rule22},+	{523, 1, &rule23},+	{524, 1, &rule22},+	{525, 1, &rule23},+	{526, 1, &rule22},+	{527, 1, &rule23},+	{528, 1, &rule22},+	{529, 1, &rule23},+	{530, 1, &rule22},+	{531, 1, &rule23},+	{532, 1, &rule22},+	{533, 1, &rule23},+	{534, 1, &rule22},+	{535, 1, &rule23},+	{536, 1, &rule22},+	{537, 1, &rule23},+	{538, 1, &rule22},+	{539, 1, &rule23},+	{540, 1, &rule22},+	{541, 1, &rule23},+	{542, 1, &rule22},+	{543, 1, &rule23},+	{544, 1, &rule53},+	{546, 1, &rule22},+	{547, 1, &rule23},+	{548, 1, &rule22},+	{549, 1, &rule23},+	{550, 1, &rule22},+	{551, 1, &rule23},+	{552, 1, &rule22},+	{553, 1, &rule23},+	{554, 1, &rule22},+	{555, 1, &rule23},+	{556, 1, &rule22},+	{557, 1, &rule23},+	{558, 1, &rule22},+	{559, 1, &rule23},+	{560, 1, &rule22},+	{561, 1, &rule23},+	{562, 1, &rule22},+	{563, 1, &rule23},+	{570, 1, &rule54},+	{571, 1, &rule22},+	{572, 1, &rule23},+	{573, 1, &rule55},+	{574, 1, &rule56},+	{575, 2, &rule57},+	{577, 1, &rule22},+	{578, 1, &rule23},+	{579, 1, &rule58},+	{580, 1, &rule59},+	{581, 1, &rule60},+	{582, 1, &rule22},+	{583, 1, &rule23},+	{584, 1, &rule22},+	{585, 1, &rule23},+	{586, 1, &rule22},+	{587, 1, &rule23},+	{588, 1, &rule22},+	{589, 1, &rule23},+	{590, 1, &rule22},+	{591, 1, &rule23},+	{592, 1, &rule61},+	{593, 1, &rule62},+	{594, 1, &rule63},+	{595, 1, &rule64},+	{596, 1, &rule65},+	{598, 2, &rule66},+	{601, 1, &rule67},+	{603, 1, &rule68},+	{604, 1, &rule69},+	{608, 1, &rule66},+	{609, 1, &rule70},+	{611, 1, &rule71},+	{613, 1, &rule72},+	{614, 1, &rule73},+	{616, 1, &rule74},+	{617, 1, &rule75},+	{619, 1, &rule76},+	{620, 1, &rule77},+	{623, 1, &rule75},+	{625, 1, &rule78},+	{626, 1, &rule79},+	{629, 1, &rule80},+	{637, 1, &rule81},+	{640, 1, &rule82},+	{643, 1, &rule82},+	{647, 1, &rule83},+	{648, 1, &rule82},+	{649, 1, &rule84},+	{650, 2, &rule85},+	{652, 1, &rule86},+	{658, 1, &rule87},+	{670, 1, &rule88},+	{837, 1, &rule91},+	{880, 1, &rule22},+	{881, 1, &rule23},+	{882, 1, &rule22},+	{883, 1, &rule23},+	{886, 1, &rule22},+	{887, 1, &rule23},+	{891, 3, &rule41},+	{895, 1, &rule92},+	{902, 1, &rule93},+	{904, 3, &rule94},+	{908, 1, &rule95},+	{910, 2, &rule96},+	{913, 17, &rule9},+	{931, 9, &rule9},+	{940, 1, &rule97},+	{941, 3, &rule98},+	{945, 17, &rule12},+	{962, 1, &rule99},+	{963, 9, &rule12},+	{972, 1, &rule100},+	{973, 2, &rule101},+	{975, 1, &rule102},+	{976, 1, &rule103},+	{977, 1, &rule104},+	{981, 1, &rule106},+	{982, 1, &rule107},+	{983, 1, &rule108},+	{984, 1, &rule22},+	{985, 1, &rule23},+	{986, 1, &rule22},+	{987, 1, &rule23},+	{988, 1, &rule22},+	{989, 1, &rule23},+	{990, 1, &rule22},+	{991, 1, &rule23},+	{992, 1, &rule22},+	{993, 1, &rule23},+	{994, 1, &rule22},+	{995, 1, &rule23},+	{996, 1, &rule22},+	{997, 1, &rule23},+	{998, 1, &rule22},+	{999, 1, &rule23},+	{1000, 1, &rule22},+	{1001, 1, &rule23},+	{1002, 1, &rule22},+	{1003, 1, &rule23},+	{1004, 1, &rule22},+	{1005, 1, &rule23},+	{1006, 1, &rule22},+	{1007, 1, &rule23},+	{1008, 1, &rule109},+	{1009, 1, &rule110},+	{1010, 1, &rule111},+	{1011, 1, &rule112},+	{1012, 1, &rule113},+	{1013, 1, &rule114},+	{1015, 1, &rule22},+	{1016, 1, &rule23},+	{1017, 1, &rule115},+	{1018, 1, &rule22},+	{1019, 1, &rule23},+	{1021, 3, &rule53},+	{1024, 16, &rule116},+	{1040, 32, &rule9},+	{1072, 32, &rule12},+	{1104, 16, &rule110},+	{1120, 1, &rule22},+	{1121, 1, &rule23},+	{1122, 1, &rule22},+	{1123, 1, &rule23},+	{1124, 1, &rule22},+	{1125, 1, &rule23},+	{1126, 1, &rule22},+	{1127, 1, &rule23},+	{1128, 1, &rule22},+	{1129, 1, &rule23},+	{1130, 1, &rule22},+	{1131, 1, &rule23},+	{1132, 1, &rule22},+	{1133, 1, &rule23},+	{1134, 1, &rule22},+	{1135, 1, &rule23},+	{1136, 1, &rule22},+	{1137, 1, &rule23},+	{1138, 1, &rule22},+	{1139, 1, &rule23},+	{1140, 1, &rule22},+	{1141, 1, &rule23},+	{1142, 1, &rule22},+	{1143, 1, &rule23},+	{1144, 1, &rule22},+	{1145, 1, &rule23},+	{1146, 1, &rule22},+	{1147, 1, &rule23},+	{1148, 1, &rule22},+	{1149, 1, &rule23},+	{1150, 1, &rule22},+	{1151, 1, &rule23},+	{1152, 1, &rule22},+	{1153, 1, &rule23},+	{1162, 1, &rule22},+	{1163, 1, &rule23},+	{1164, 1, &rule22},+	{1165, 1, &rule23},+	{1166, 1, &rule22},+	{1167, 1, &rule23},+	{1168, 1, &rule22},+	{1169, 1, &rule23},+	{1170, 1, &rule22},+	{1171, 1, &rule23},+	{1172, 1, &rule22},+	{1173, 1, &rule23},+	{1174, 1, &rule22},+	{1175, 1, &rule23},+	{1176, 1, &rule22},+	{1177, 1, &rule23},+	{1178, 1, &rule22},+	{1179, 1, &rule23},+	{1180, 1, &rule22},+	{1181, 1, &rule23},+	{1182, 1, &rule22},+	{1183, 1, &rule23},+	{1184, 1, &rule22},+	{1185, 1, &rule23},+	{1186, 1, &rule22},+	{1187, 1, &rule23},+	{1188, 1, &rule22},+	{1189, 1, &rule23},+	{1190, 1, &rule22},+	{1191, 1, &rule23},+	{1192, 1, &rule22},+	{1193, 1, &rule23},+	{1194, 1, &rule22},+	{1195, 1, &rule23},+	{1196, 1, &rule22},+	{1197, 1, &rule23},+	{1198, 1, &rule22},+	{1199, 1, &rule23},+	{1200, 1, &rule22},+	{1201, 1, &rule23},+	{1202, 1, &rule22},+	{1203, 1, &rule23},+	{1204, 1, &rule22},+	{1205, 1, &rule23},+	{1206, 1, &rule22},+	{1207, 1, &rule23},+	{1208, 1, &rule22},+	{1209, 1, &rule23},+	{1210, 1, &rule22},+	{1211, 1, &rule23},+	{1212, 1, &rule22},+	{1213, 1, &rule23},+	{1214, 1, &rule22},+	{1215, 1, &rule23},+	{1216, 1, &rule118},+	{1217, 1, &rule22},+	{1218, 1, &rule23},+	{1219, 1, &rule22},+	{1220, 1, &rule23},+	{1221, 1, &rule22},+	{1222, 1, &rule23},+	{1223, 1, &rule22},+	{1224, 1, &rule23},+	{1225, 1, &rule22},+	{1226, 1, &rule23},+	{1227, 1, &rule22},+	{1228, 1, &rule23},+	{1229, 1, &rule22},+	{1230, 1, &rule23},+	{1231, 1, &rule119},+	{1232, 1, &rule22},+	{1233, 1, &rule23},+	{1234, 1, &rule22},+	{1235, 1, &rule23},+	{1236, 1, &rule22},+	{1237, 1, &rule23},+	{1238, 1, &rule22},+	{1239, 1, &rule23},+	{1240, 1, &rule22},+	{1241, 1, &rule23},+	{1242, 1, &rule22},+	{1243, 1, &rule23},+	{1244, 1, &rule22},+	{1245, 1, &rule23},+	{1246, 1, &rule22},+	{1247, 1, &rule23},+	{1248, 1, &rule22},+	{1249, 1, &rule23},+	{1250, 1, &rule22},+	{1251, 1, &rule23},+	{1252, 1, &rule22},+	{1253, 1, &rule23},+	{1254, 1, &rule22},+	{1255, 1, &rule23},+	{1256, 1, &rule22},+	{1257, 1, &rule23},+	{1258, 1, &rule22},+	{1259, 1, &rule23},+	{1260, 1, &rule22},+	{1261, 1, &rule23},+	{1262, 1, &rule22},+	{1263, 1, &rule23},+	{1264, 1, &rule22},+	{1265, 1, &rule23},+	{1266, 1, &rule22},+	{1267, 1, &rule23},+	{1268, 1, &rule22},+	{1269, 1, &rule23},+	{1270, 1, &rule22},+	{1271, 1, &rule23},+	{1272, 1, &rule22},+	{1273, 1, &rule23},+	{1274, 1, &rule22},+	{1275, 1, &rule23},+	{1276, 1, &rule22},+	{1277, 1, &rule23},+	{1278, 1, &rule22},+	{1279, 1, &rule23},+	{1280, 1, &rule22},+	{1281, 1, &rule23},+	{1282, 1, &rule22},+	{1283, 1, &rule23},+	{1284, 1, &rule22},+	{1285, 1, &rule23},+	{1286, 1, &rule22},+	{1287, 1, &rule23},+	{1288, 1, &rule22},+	{1289, 1, &rule23},+	{1290, 1, &rule22},+	{1291, 1, &rule23},+	{1292, 1, &rule22},+	{1293, 1, &rule23},+	{1294, 1, &rule22},+	{1295, 1, &rule23},+	{1296, 1, &rule22},+	{1297, 1, &rule23},+	{1298, 1, &rule22},+	{1299, 1, &rule23},+	{1300, 1, &rule22},+	{1301, 1, &rule23},+	{1302, 1, &rule22},+	{1303, 1, &rule23},+	{1304, 1, &rule22},+	{1305, 1, &rule23},+	{1306, 1, &rule22},+	{1307, 1, &rule23},+	{1308, 1, &rule22},+	{1309, 1, &rule23},+	{1310, 1, &rule22},+	{1311, 1, &rule23},+	{1312, 1, &rule22},+	{1313, 1, &rule23},+	{1314, 1, &rule22},+	{1315, 1, &rule23},+	{1316, 1, &rule22},+	{1317, 1, &rule23},+	{1318, 1, &rule22},+	{1319, 1, &rule23},+	{1320, 1, &rule22},+	{1321, 1, &rule23},+	{1322, 1, &rule22},+	{1323, 1, &rule23},+	{1324, 1, &rule22},+	{1325, 1, &rule23},+	{1326, 1, &rule22},+	{1327, 1, &rule23},+	{1329, 38, &rule120},+	{1377, 38, &rule121},+	{4256, 38, &rule123},+	{4295, 1, &rule123},+	{4301, 1, &rule123},+	{7545, 1, &rule125},+	{7549, 1, &rule126},+	{7680, 1, &rule22},+	{7681, 1, &rule23},+	{7682, 1, &rule22},+	{7683, 1, &rule23},+	{7684, 1, &rule22},+	{7685, 1, &rule23},+	{7686, 1, &rule22},+	{7687, 1, &rule23},+	{7688, 1, &rule22},+	{7689, 1, &rule23},+	{7690, 1, &rule22},+	{7691, 1, &rule23},+	{7692, 1, &rule22},+	{7693, 1, &rule23},+	{7694, 1, &rule22},+	{7695, 1, &rule23},+	{7696, 1, &rule22},+	{7697, 1, &rule23},+	{7698, 1, &rule22},+	{7699, 1, &rule23},+	{7700, 1, &rule22},+	{7701, 1, &rule23},+	{7702, 1, &rule22},+	{7703, 1, &rule23},+	{7704, 1, &rule22},+	{7705, 1, &rule23},+	{7706, 1, &rule22},+	{7707, 1, &rule23},+	{7708, 1, &rule22},+	{7709, 1, &rule23},+	{7710, 1, &rule22},+	{7711, 1, &rule23},+	{7712, 1, &rule22},+	{7713, 1, &rule23},+	{7714, 1, &rule22},+	{7715, 1, &rule23},+	{7716, 1, &rule22},+	{7717, 1, &rule23},+	{7718, 1, &rule22},+	{7719, 1, &rule23},+	{7720, 1, &rule22},+	{7721, 1, &rule23},+	{7722, 1, &rule22},+	{7723, 1, &rule23},+	{7724, 1, &rule22},+	{7725, 1, &rule23},+	{7726, 1, &rule22},+	{7727, 1, &rule23},+	{7728, 1, &rule22},+	{7729, 1, &rule23},+	{7730, 1, &rule22},+	{7731, 1, &rule23},+	{7732, 1, &rule22},+	{7733, 1, &rule23},+	{7734, 1, &rule22},+	{7735, 1, &rule23},+	{7736, 1, &rule22},+	{7737, 1, &rule23},+	{7738, 1, &rule22},+	{7739, 1, &rule23},+	{7740, 1, &rule22},+	{7741, 1, &rule23},+	{7742, 1, &rule22},+	{7743, 1, &rule23},+	{7744, 1, &rule22},+	{7745, 1, &rule23},+	{7746, 1, &rule22},+	{7747, 1, &rule23},+	{7748, 1, &rule22},+	{7749, 1, &rule23},+	{7750, 1, &rule22},+	{7751, 1, &rule23},+	{7752, 1, &rule22},+	{7753, 1, &rule23},+	{7754, 1, &rule22},+	{7755, 1, &rule23},+	{7756, 1, &rule22},+	{7757, 1, &rule23},+	{7758, 1, &rule22},+	{7759, 1, &rule23},+	{7760, 1, &rule22},+	{7761, 1, &rule23},+	{7762, 1, &rule22},+	{7763, 1, &rule23},+	{7764, 1, &rule22},+	{7765, 1, &rule23},+	{7766, 1, &rule22},+	{7767, 1, &rule23},+	{7768, 1, &rule22},+	{7769, 1, &rule23},+	{7770, 1, &rule22},+	{7771, 1, &rule23},+	{7772, 1, &rule22},+	{7773, 1, &rule23},+	{7774, 1, &rule22},+	{7775, 1, &rule23},+	{7776, 1, &rule22},+	{7777, 1, &rule23},+	{7778, 1, &rule22},+	{7779, 1, &rule23},+	{7780, 1, &rule22},+	{7781, 1, &rule23},+	{7782, 1, &rule22},+	{7783, 1, &rule23},+	{7784, 1, &rule22},+	{7785, 1, &rule23},+	{7786, 1, &rule22},+	{7787, 1, &rule23},+	{7788, 1, &rule22},+	{7789, 1, &rule23},+	{7790, 1, &rule22},+	{7791, 1, &rule23},+	{7792, 1, &rule22},+	{7793, 1, &rule23},+	{7794, 1, &rule22},+	{7795, 1, &rule23},+	{7796, 1, &rule22},+	{7797, 1, &rule23},+	{7798, 1, &rule22},+	{7799, 1, &rule23},+	{7800, 1, &rule22},+	{7801, 1, &rule23},+	{7802, 1, &rule22},+	{7803, 1, &rule23},+	{7804, 1, &rule22},+	{7805, 1, &rule23},+	{7806, 1, &rule22},+	{7807, 1, &rule23},+	{7808, 1, &rule22},+	{7809, 1, &rule23},+	{7810, 1, &rule22},+	{7811, 1, &rule23},+	{7812, 1, &rule22},+	{7813, 1, &rule23},+	{7814, 1, &rule22},+	{7815, 1, &rule23},+	{7816, 1, &rule22},+	{7817, 1, &rule23},+	{7818, 1, &rule22},+	{7819, 1, &rule23},+	{7820, 1, &rule22},+	{7821, 1, &rule23},+	{7822, 1, &rule22},+	{7823, 1, &rule23},+	{7824, 1, &rule22},+	{7825, 1, &rule23},+	{7826, 1, &rule22},+	{7827, 1, &rule23},+	{7828, 1, &rule22},+	{7829, 1, &rule23},+	{7835, 1, &rule127},+	{7838, 1, &rule128},+	{7840, 1, &rule22},+	{7841, 1, &rule23},+	{7842, 1, &rule22},+	{7843, 1, &rule23},+	{7844, 1, &rule22},+	{7845, 1, &rule23},+	{7846, 1, &rule22},+	{7847, 1, &rule23},+	{7848, 1, &rule22},+	{7849, 1, &rule23},+	{7850, 1, &rule22},+	{7851, 1, &rule23},+	{7852, 1, &rule22},+	{7853, 1, &rule23},+	{7854, 1, &rule22},+	{7855, 1, &rule23},+	{7856, 1, &rule22},+	{7857, 1, &rule23},+	{7858, 1, &rule22},+	{7859, 1, &rule23},+	{7860, 1, &rule22},+	{7861, 1, &rule23},+	{7862, 1, &rule22},+	{7863, 1, &rule23},+	{7864, 1, &rule22},+	{7865, 1, &rule23},+	{7866, 1, &rule22},+	{7867, 1, &rule23},+	{7868, 1, &rule22},+	{7869, 1, &rule23},+	{7870, 1, &rule22},+	{7871, 1, &rule23},+	{7872, 1, &rule22},+	{7873, 1, &rule23},+	{7874, 1, &rule22},+	{7875, 1, &rule23},+	{7876, 1, &rule22},+	{7877, 1, &rule23},+	{7878, 1, &rule22},+	{7879, 1, &rule23},+	{7880, 1, &rule22},+	{7881, 1, &rule23},+	{7882, 1, &rule22},+	{7883, 1, &rule23},+	{7884, 1, &rule22},+	{7885, 1, &rule23},+	{7886, 1, &rule22},+	{7887, 1, &rule23},+	{7888, 1, &rule22},+	{7889, 1, &rule23},+	{7890, 1, &rule22},+	{7891, 1, &rule23},+	{7892, 1, &rule22},+	{7893, 1, &rule23},+	{7894, 1, &rule22},+	{7895, 1, &rule23},+	{7896, 1, &rule22},+	{7897, 1, &rule23},+	{7898, 1, &rule22},+	{7899, 1, &rule23},+	{7900, 1, &rule22},+	{7901, 1, &rule23},+	{7902, 1, &rule22},+	{7903, 1, &rule23},+	{7904, 1, &rule22},+	{7905, 1, &rule23},+	{7906, 1, &rule22},+	{7907, 1, &rule23},+	{7908, 1, &rule22},+	{7909, 1, &rule23},+	{7910, 1, &rule22},+	{7911, 1, &rule23},+	{7912, 1, &rule22},+	{7913, 1, &rule23},+	{7914, 1, &rule22},+	{7915, 1, &rule23},+	{7916, 1, &rule22},+	{7917, 1, &rule23},+	{7918, 1, &rule22},+	{7919, 1, &rule23},+	{7920, 1, &rule22},+	{7921, 1, &rule23},+	{7922, 1, &rule22},+	{7923, 1, &rule23},+	{7924, 1, &rule22},+	{7925, 1, &rule23},+	{7926, 1, &rule22},+	{7927, 1, &rule23},+	{7928, 1, &rule22},+	{7929, 1, &rule23},+	{7930, 1, &rule22},+	{7931, 1, &rule23},+	{7932, 1, &rule22},+	{7933, 1, &rule23},+	{7934, 1, &rule22},+	{7935, 1, &rule23},+	{7936, 8, &rule129},+	{7944, 8, &rule130},+	{7952, 6, &rule129},+	{7960, 6, &rule130},+	{7968, 8, &rule129},+	{7976, 8, &rule130},+	{7984, 8, &rule129},+	{7992, 8, &rule130},+	{8000, 6, &rule129},+	{8008, 6, &rule130},+	{8017, 1, &rule129},+	{8019, 1, &rule129},+	{8021, 1, &rule129},+	{8023, 1, &rule129},+	{8025, 1, &rule130},+	{8027, 1, &rule130},+	{8029, 1, &rule130},+	{8031, 1, &rule130},+	{8032, 8, &rule129},+	{8040, 8, &rule130},+	{8048, 2, &rule131},+	{8050, 4, &rule132},+	{8054, 2, &rule133},+	{8056, 2, &rule134},+	{8058, 2, &rule135},+	{8060, 2, &rule136},+	{8064, 8, &rule129},+	{8072, 8, &rule137},+	{8080, 8, &rule129},+	{8088, 8, &rule137},+	{8096, 8, &rule129},+	{8104, 8, &rule137},+	{8112, 2, &rule129},+	{8115, 1, &rule138},+	{8120, 2, &rule130},+	{8122, 2, &rule139},+	{8124, 1, &rule140},+	{8126, 1, &rule141},+	{8131, 1, &rule138},+	{8136, 4, &rule142},+	{8140, 1, &rule140},+	{8144, 2, &rule129},+	{8152, 2, &rule130},+	{8154, 2, &rule143},+	{8160, 2, &rule129},+	{8165, 1, &rule111},+	{8168, 2, &rule130},+	{8170, 2, &rule144},+	{8172, 1, &rule115},+	{8179, 1, &rule138},+	{8184, 2, &rule145},+	{8186, 2, &rule146},+	{8188, 1, &rule140},+	{8486, 1, &rule149},+	{8490, 1, &rule150},+	{8491, 1, &rule151},+	{8498, 1, &rule152},+	{8526, 1, &rule153},+	{8544, 16, &rule154},+	{8560, 16, &rule155},+	{8579, 1, &rule22},+	{8580, 1, &rule23},+	{9398, 26, &rule156},+	{9424, 26, &rule157},+	{11264, 47, &rule120},+	{11312, 47, &rule121},+	{11360, 1, &rule22},+	{11361, 1, &rule23},+	{11362, 1, &rule158},+	{11363, 1, &rule159},+	{11364, 1, &rule160},+	{11365, 1, &rule161},+	{11366, 1, &rule162},+	{11367, 1, &rule22},+	{11368, 1, &rule23},+	{11369, 1, &rule22},+	{11370, 1, &rule23},+	{11371, 1, &rule22},+	{11372, 1, &rule23},+	{11373, 1, &rule163},+	{11374, 1, &rule164},+	{11375, 1, &rule165},+	{11376, 1, &rule166},+	{11378, 1, &rule22},+	{11379, 1, &rule23},+	{11381, 1, &rule22},+	{11382, 1, &rule23},+	{11390, 2, &rule167},+	{11392, 1, &rule22},+	{11393, 1, &rule23},+	{11394, 1, &rule22},+	{11395, 1, &rule23},+	{11396, 1, &rule22},+	{11397, 1, &rule23},+	{11398, 1, &rule22},+	{11399, 1, &rule23},+	{11400, 1, &rule22},+	{11401, 1, &rule23},+	{11402, 1, &rule22},+	{11403, 1, &rule23},+	{11404, 1, &rule22},+	{11405, 1, &rule23},+	{11406, 1, &rule22},+	{11407, 1, &rule23},+	{11408, 1, &rule22},+	{11409, 1, &rule23},+	{11410, 1, &rule22},+	{11411, 1, &rule23},+	{11412, 1, &rule22},+	{11413, 1, &rule23},+	{11414, 1, &rule22},+	{11415, 1, &rule23},+	{11416, 1, &rule22},+	{11417, 1, &rule23},+	{11418, 1, &rule22},+	{11419, 1, &rule23},+	{11420, 1, &rule22},+	{11421, 1, &rule23},+	{11422, 1, &rule22},+	{11423, 1, &rule23},+	{11424, 1, &rule22},+	{11425, 1, &rule23},+	{11426, 1, &rule22},+	{11427, 1, &rule23},+	{11428, 1, &rule22},+	{11429, 1, &rule23},+	{11430, 1, &rule22},+	{11431, 1, &rule23},+	{11432, 1, &rule22},+	{11433, 1, &rule23},+	{11434, 1, &rule22},+	{11435, 1, &rule23},+	{11436, 1, &rule22},+	{11437, 1, &rule23},+	{11438, 1, &rule22},+	{11439, 1, &rule23},+	{11440, 1, &rule22},+	{11441, 1, &rule23},+	{11442, 1, &rule22},+	{11443, 1, &rule23},+	{11444, 1, &rule22},+	{11445, 1, &rule23},+	{11446, 1, &rule22},+	{11447, 1, &rule23},+	{11448, 1, &rule22},+	{11449, 1, &rule23},+	{11450, 1, &rule22},+	{11451, 1, &rule23},+	{11452, 1, &rule22},+	{11453, 1, &rule23},+	{11454, 1, &rule22},+	{11455, 1, &rule23},+	{11456, 1, &rule22},+	{11457, 1, &rule23},+	{11458, 1, &rule22},+	{11459, 1, &rule23},+	{11460, 1, &rule22},+	{11461, 1, &rule23},+	{11462, 1, &rule22},+	{11463, 1, &rule23},+	{11464, 1, &rule22},+	{11465, 1, &rule23},+	{11466, 1, &rule22},+	{11467, 1, &rule23},+	{11468, 1, &rule22},+	{11469, 1, &rule23},+	{11470, 1, &rule22},+	{11471, 1, &rule23},+	{11472, 1, &rule22},+	{11473, 1, &rule23},+	{11474, 1, &rule22},+	{11475, 1, &rule23},+	{11476, 1, &rule22},+	{11477, 1, &rule23},+	{11478, 1, &rule22},+	{11479, 1, &rule23},+	{11480, 1, &rule22},+	{11481, 1, &rule23},+	{11482, 1, &rule22},+	{11483, 1, &rule23},+	{11484, 1, &rule22},+	{11485, 1, &rule23},+	{11486, 1, &rule22},+	{11487, 1, &rule23},+	{11488, 1, &rule22},+	{11489, 1, &rule23},+	{11490, 1, &rule22},+	{11491, 1, &rule23},+	{11499, 1, &rule22},+	{11500, 1, &rule23},+	{11501, 1, &rule22},+	{11502, 1, &rule23},+	{11506, 1, &rule22},+	{11507, 1, &rule23},+	{11520, 38, &rule168},+	{11559, 1, &rule168},+	{11565, 1, &rule168},+	{42560, 1, &rule22},+	{42561, 1, &rule23},+	{42562, 1, &rule22},+	{42563, 1, &rule23},+	{42564, 1, &rule22},+	{42565, 1, &rule23},+	{42566, 1, &rule22},+	{42567, 1, &rule23},+	{42568, 1, &rule22},+	{42569, 1, &rule23},+	{42570, 1, &rule22},+	{42571, 1, &rule23},+	{42572, 1, &rule22},+	{42573, 1, &rule23},+	{42574, 1, &rule22},+	{42575, 1, &rule23},+	{42576, 1, &rule22},+	{42577, 1, &rule23},+	{42578, 1, &rule22},+	{42579, 1, &rule23},+	{42580, 1, &rule22},+	{42581, 1, &rule23},+	{42582, 1, &rule22},+	{42583, 1, &rule23},+	{42584, 1, &rule22},+	{42585, 1, &rule23},+	{42586, 1, &rule22},+	{42587, 1, &rule23},+	{42588, 1, &rule22},+	{42589, 1, &rule23},+	{42590, 1, &rule22},+	{42591, 1, &rule23},+	{42592, 1, &rule22},+	{42593, 1, &rule23},+	{42594, 1, &rule22},+	{42595, 1, &rule23},+	{42596, 1, &rule22},+	{42597, 1, &rule23},+	{42598, 1, &rule22},+	{42599, 1, &rule23},+	{42600, 1, &rule22},+	{42601, 1, &rule23},+	{42602, 1, &rule22},+	{42603, 1, &rule23},+	{42604, 1, &rule22},+	{42605, 1, &rule23},+	{42624, 1, &rule22},+	{42625, 1, &rule23},+	{42626, 1, &rule22},+	{42627, 1, &rule23},+	{42628, 1, &rule22},+	{42629, 1, &rule23},+	{42630, 1, &rule22},+	{42631, 1, &rule23},+	{42632, 1, &rule22},+	{42633, 1, &rule23},+	{42634, 1, &rule22},+	{42635, 1, &rule23},+	{42636, 1, &rule22},+	{42637, 1, &rule23},+	{42638, 1, &rule22},+	{42639, 1, &rule23},+	{42640, 1, &rule22},+	{42641, 1, &rule23},+	{42642, 1, &rule22},+	{42643, 1, &rule23},+	{42644, 1, &rule22},+	{42645, 1, &rule23},+	{42646, 1, &rule22},+	{42647, 1, &rule23},+	{42648, 1, &rule22},+	{42649, 1, &rule23},+	{42650, 1, &rule22},+	{42651, 1, &rule23},+	{42786, 1, &rule22},+	{42787, 1, &rule23},+	{42788, 1, &rule22},+	{42789, 1, &rule23},+	{42790, 1, &rule22},+	{42791, 1, &rule23},+	{42792, 1, &rule22},+	{42793, 1, &rule23},+	{42794, 1, &rule22},+	{42795, 1, &rule23},+	{42796, 1, &rule22},+	{42797, 1, &rule23},+	{42798, 1, &rule22},+	{42799, 1, &rule23},+	{42802, 1, &rule22},+	{42803, 1, &rule23},+	{42804, 1, &rule22},+	{42805, 1, &rule23},+	{42806, 1, &rule22},+	{42807, 1, &rule23},+	{42808, 1, &rule22},+	{42809, 1, &rule23},+	{42810, 1, &rule22},+	{42811, 1, &rule23},+	{42812, 1, &rule22},+	{42813, 1, &rule23},+	{42814, 1, &rule22},+	{42815, 1, &rule23},+	{42816, 1, &rule22},+	{42817, 1, &rule23},+	{42818, 1, &rule22},+	{42819, 1, &rule23},+	{42820, 1, &rule22},+	{42821, 1, &rule23},+	{42822, 1, &rule22},+	{42823, 1, &rule23},+	{42824, 1, &rule22},+	{42825, 1, &rule23},+	{42826, 1, &rule22},+	{42827, 1, &rule23},+	{42828, 1, &rule22},+	{42829, 1, &rule23},+	{42830, 1, &rule22},+	{42831, 1, &rule23},+	{42832, 1, &rule22},+	{42833, 1, &rule23},+	{42834, 1, &rule22},+	{42835, 1, &rule23},+	{42836, 1, &rule22},+	{42837, 1, &rule23},+	{42838, 1, &rule22},+	{42839, 1, &rule23},+	{42840, 1, &rule22},+	{42841, 1, &rule23},+	{42842, 1, &rule22},+	{42843, 1, &rule23},+	{42844, 1, &rule22},+	{42845, 1, &rule23},+	{42846, 1, &rule22},+	{42847, 1, &rule23},+	{42848, 1, &rule22},+	{42849, 1, &rule23},+	{42850, 1, &rule22},+	{42851, 1, &rule23},+	{42852, 1, &rule22},+	{42853, 1, &rule23},+	{42854, 1, &rule22},+	{42855, 1, &rule23},+	{42856, 1, &rule22},+	{42857, 1, &rule23},+	{42858, 1, &rule22},+	{42859, 1, &rule23},+	{42860, 1, &rule22},+	{42861, 1, &rule23},+	{42862, 1, &rule22},+	{42863, 1, &rule23},+	{42873, 1, &rule22},+	{42874, 1, &rule23},+	{42875, 1, &rule22},+	{42876, 1, &rule23},+	{42877, 1, &rule169},+	{42878, 1, &rule22},+	{42879, 1, &rule23},+	{42880, 1, &rule22},+	{42881, 1, &rule23},+	{42882, 1, &rule22},+	{42883, 1, &rule23},+	{42884, 1, &rule22},+	{42885, 1, &rule23},+	{42886, 1, &rule22},+	{42887, 1, &rule23},+	{42891, 1, &rule22},+	{42892, 1, &rule23},+	{42893, 1, &rule170},+	{42896, 1, &rule22},+	{42897, 1, &rule23},+	{42898, 1, &rule22},+	{42899, 1, &rule23},+	{42902, 1, &rule22},+	{42903, 1, &rule23},+	{42904, 1, &rule22},+	{42905, 1, &rule23},+	{42906, 1, &rule22},+	{42907, 1, &rule23},+	{42908, 1, &rule22},+	{42909, 1, &rule23},+	{42910, 1, &rule22},+	{42911, 1, &rule23},+	{42912, 1, &rule22},+	{42913, 1, &rule23},+	{42914, 1, &rule22},+	{42915, 1, &rule23},+	{42916, 1, &rule22},+	{42917, 1, &rule23},+	{42918, 1, &rule22},+	{42919, 1, &rule23},+	{42920, 1, &rule22},+	{42921, 1, &rule23},+	{42922, 1, &rule171},+	{42923, 1, &rule172},+	{42924, 1, &rule173},+	{42925, 1, &rule174},+	{42928, 1, &rule175},+	{42929, 1, &rule176},+	{65313, 26, &rule9},+	{65345, 26, &rule12},+	{66560, 40, &rule179},+	{66600, 40, &rule180},+	{71840, 32, &rule9},+	{71872, 32, &rule12}+};+static const struct _charblock_ spacechars[]={+	{32, 1, &rule1},+	{160, 1, &rule1},+	{5760, 1, &rule1},+	{8192, 11, &rule1},+	{8239, 1, &rule1},+	{8287, 1, &rule1},+	{12288, 1, &rule1}+};++/*+	Obtain the reference to character rule by doing+	binary search over the specified array of blocks.+	To make checkattr shorter, the address of+	nullrule is returned if the search fails:+	this rule defines no category and no conversion+	distances. The compare function returns 0 when+	key->start is within the block. Otherwise+	result of comparison of key->start and start of the+	current block is returned as usual.+*/++static const struct _convrule_ nullrule={0,NUMCAT_CN,0,0,0,0};++static int blkcmp(const void *vk,const void *vb)+{+	const struct _charblock_ *key,*cur;+	key=vk;+	cur=vb;+	if((key->start>=cur->start)&&(key->start<(cur->start+cur->length)))+	{+		return 0;+	}+	if(key->start>cur->start) return 1;+	return -1;+}++static const struct _convrule_ *getrule(+	const struct _charblock_ *blocks,+	int numblocks,+	int unichar)+{+	struct _charblock_ key={unichar,1,(void *)0};+	struct _charblock_ *cb=bsearch(&key,blocks,numblocks,sizeof(key),blkcmp);+	if(cb==(void *)0) return &nullrule;+	return cb->rule;+}+	+++/*+	Check whether a character (internal code) has certain attributes.+	Attributes (category flags) may be ORed. The function ANDs+	character category flags and the mask and returns the result.+	If the character belongs to one of the categories requested,+	the result will be nonzero.+*/++inline static int checkattr(int c,unsigned int catmask)+{+	return (catmask & (getrule(allchars,(c<256)?NUM_LAT1BLOCKS:NUM_BLOCKS,c)->category));+}++inline static int checkattr_s(int c,unsigned int catmask)+{+        return (catmask & (getrule(spacechars,NUM_SPACEBLOCKS,c)->category));+}++/*+	Define predicate functions for some combinations of categories.+*/++#define unipred(p,m) \+HsInt p(HsInt c) \+{ \+	return checkattr(c,m); \+}++#define unipred_s(p,m) \+HsInt p(HsInt c) \+{ \+        return checkattr_s(c,m); \+}++/*+	Make these rules as close to Hugs as possible.+*/++unipred(u_iswcntrl,GENCAT_CC)+unipred(u_iswprint, (GENCAT_MC | GENCAT_NO | GENCAT_SK | GENCAT_ME | GENCAT_ND |   GENCAT_PO | GENCAT_LT | GENCAT_PC | GENCAT_SM | GENCAT_ZS |   GENCAT_LU | GENCAT_PD | GENCAT_SO | GENCAT_PE | GENCAT_PF |   GENCAT_PS | GENCAT_SC | GENCAT_LL | GENCAT_LM | GENCAT_PI |   GENCAT_NL | GENCAT_MN | GENCAT_LO))+unipred_s(u_iswspace,GENCAT_ZS)+unipred(u_iswupper,(GENCAT_LU|GENCAT_LT))+unipred(u_iswlower,GENCAT_LL)+unipred(u_iswalpha,(GENCAT_LL|GENCAT_LU|GENCAT_LT|GENCAT_LM|GENCAT_LO))+unipred(u_iswdigit,GENCAT_ND)++unipred(u_iswalnum,(GENCAT_LT|GENCAT_LU|GENCAT_LL|GENCAT_LM|GENCAT_LO|+		    GENCAT_MC|GENCAT_ME|GENCAT_MN|+		    GENCAT_NO|GENCAT_ND|GENCAT_NL))++#define caseconv(p,to) \+HsInt p(HsInt c) \+{ \+	const struct _convrule_ *rule=getrule(convchars,NUM_CONVBLOCKS,c);\+	if(rule==&nullrule) return c;\+	return c+rule->to;\+}++caseconv(u_towupper,updist)+caseconv(u_towlower,lowdist)+caseconv(u_towtitle,titledist)++HsInt u_gencat(HsInt c) { 	return getrule(allchars,NUM_BLOCKS,c)->catnumber; }
+ cbits/rts.c view
@@ -0,0 +1,42 @@+#include "Rts.h"+#include "rts/Flags.h"++GC_FLAGS *getGcFlags()+{+    return &RtsFlags.GcFlags;+}++CONCURRENT_FLAGS *getConcFlags()+{+    return &RtsFlags.ConcFlags;+}++MISC_FLAGS *getMiscFlags()+{+    return &RtsFlags.MiscFlags;+}++DEBUG_FLAGS *getDebugFlags()+{+    return &RtsFlags.DebugFlags;+}++COST_CENTRE_FLAGS *getCcFlags()+{+    return &RtsFlags.CcFlags;+}++PROFILING_FLAGS *getProfFlags()+{+    return &RtsFlags.ProfFlags;+}++TRACE_FLAGS *getTraceFlags()+{+    return &RtsFlags.TraceFlags;+}++TICKY_FLAGS *getTickyFlags()+{+    return &RtsFlags.TickyFlags;+}
changelog.md view
@@ -1,5 +1,152 @@ # Changelog for [`base` package](http://hackage.haskell.org/package/base) +## 4.8.0.0  *Mar 2015*++  * Bundled with GHC 7.10.1++  * Make `Applicative` a superclass of `Monad`++  * Add reverse application operator `Data.Function.(&)`++  * Add `Data.List.sortOn` sorting function++  * Add `System.Exit.die`++  * Deprecate `versionTags` field of `Data.Version.Version`.+    Add `makeVersion :: [Int] -> Version` constructor function to aid+    migration to a future `versionTags`-less `Version`.++  * Add `IsList Version` instance++  * Weaken RealFloat constraints on some `Data.Complex` functions++  * Add `Control.Monad.(<$!>)` as a strict version of `(<$>)`++  * The `Data.Monoid` module now has the `PolyKinds` extension+    enabled, so that the `Monoid` instance for `Proxy` are polykinded+    like `Proxy` itself is.++  * Make `abs` and `signum` handle (-0.0) correctly per IEEE-754.++  * Re-export `Data.Word.Word` from `Prelude`++  * Add `countLeadingZeros` and `countTrailingZeros` methods to+    `Data.Bits.FiniteBits` class++  * Add `Data.List.uncons` list destructor (#9550)++  * Export `Monoid(..)` from `Prelude`++  * Export `Foldable(..)` from `Prelude`+    (hiding `fold`, `foldl'`, `foldr'`, and `toList`)++  * Export `Traversable(..)` from `Prelude`++  * Set fixity for `Data.Foldable.{elem,notElem}` to match the+    conventional one set for `Data.List.{elem,notElem}` (#9610)++  * Turn `toList`, `elem`, `sum`, `product`, `maximum`, and `minimum`+    into `Foldable` methods (#9621)++  * Replace the `Data.List`-exported functions++    ```+    all, and, any, concat, concatMap, elem, find, product, sum,+    mapAccumL, mapAccumR+    ```++    by re-exports of their generalised `Data.Foldable`/`Data.Traversable`+    counterparts.  In other words, unqualified imports of `Data.List`+    and `Data.Foldable`/`Data.Traversable` no longer lead to conflicting+    definitions. (#9586)++  * New (unofficial) module `GHC.OldList` containing only list-specialised+    versions of the functions from `Data.List` (in other words, `GHC.OldList`+    corresponds to `base-4.7.0.2`'s `Data.List`)++  * Replace the `Control.Monad`-exported functions++    ```+    sequence_, msum, mapM_, forM_,+    forM, mapM, sequence+    ```++    by re-exports of their generalised `Data.Foldable`/`Data.Traversable`+    counterparts.  In other words, unqualified imports of `Control.Monad`+    and `Data.Foldable`/`Data.Traversable` no longer lead to conflicting+    definitions. (#9586)++  * Generalise `Control.Monad.{when,unless,guard}` from `Monad` to+    `Applicative` and from `MonadPlus` to `Alternative` respectively.++  * Generalise `Control.Monad.{foldM,foldM_}` to `Foldable`++  * `scanr`, `mapAccumL` and `filterM` now take part in list fusion (#9355,+    #9502, #9546)++  * Remove deprecated `Data.OldTypeable` (#9639)++  * New module `Data.Bifunctor` providing the `Bifunctor(bimap,first,second)`+    class (previously defined in `bifunctors` package) (#9682)++  * New module `Data.Void` providing the canonical uninhabited type `Void`+    (previously defined in `void` package) (#9814)++  * Update Unicode class definitions to Unicode version 7.0++  * Add `Alt`, an `Alternative` wrapper, to `Data.Monoid`. (#9759)++  * Add `isSubsequenceOf` to `Data.List` (#9767)++  * The arguments to `==` and `eq` in `Data.List.nub` and `Data.List.nubBy`+    are swapped, such that `Data.List.nubBy (<) [1,2]` now returns `[1]`+    instead of `[1,2]` (#2528, #3280, #7913)++  * New module `Data.Functor.Identity` (previously provided by `transformers`+    package). (#9664)++  * Add `scanl'`, a strictly accumulating version of `scanl`, to `Data.List`+    and `Data.OldList`. (#9368)++  * Add `fillBytes` to `Foreign.Marshal.Utils`.++  * Add new `displayException` method to `Exception` typeclass. (#9822)++  * Add `Data.Bits.toIntegralSized`, a size-checked version of+    `fromIntegral`. (#9816)++  * New module `Numeric.Natural` providing new `Natural` type+    representing non-negative arbitrary-precision integers.  The `GHC.Natural`+    module exposes additional GHC-specific primitives. (#9818)++  * Add `(Storable a, Integeral a) => Storable (Ratio a)` instance (#9826)++  * Add `Storable a => Storable (Complex a)` instance (#9826)++  * New module `GHC.RTS.Flags` that provides accessors to runtime flags.++  * Expose functions for per-thread allocation counters and limits in `GHC.Conc`++        disableAllocationLimit :: IO ()+        enableAllocationLimit :: IO ()+        getAllocationCounter :: IO Int64+        setAllocationCounter :: Int64 -> IO ()++    together with a new exception `AllocationLimitExceeded`.++  * Make `read . show = id` for `Data.Fixed` (#9240)++  * Add `calloc` and `callocBytes` to `Foreign.Marshal.Alloc`. (#9859)++  * Add `callocArray` and `callocArray0` to `Foreign.Marshal.Array`. (#9859)++  * Restore invariant in `Data (Ratio a)` instance (#10011)++  * Add/expose `rnfTypeRep`, `rnfTyCon`, `typeRepFingerprint`, and+    `tyConFingerprint` helpers to `Data.Typeable`.++  * Define proper `MINIMAL` pragma for `class Ix`. (#10142)+ ## 4.7.0.2  *Dec 2014*    * Bundled with GHC 7.8.4@@ -21,7 +168,7 @@    * Fix `fdReady` to honor `FD_SETSIZE` (#9168) -## 4.7.0.0  *Mar 2014*+## 4.7.0.0  *Apr 2014*    * Bundled with GHC 7.8.1 @@ -36,7 +183,8 @@   * There are now `Foldable` and `Traversable` instances for `Either a`,    `Const r`, and `(,) a`. -  * There is now a `Monoid`, `Generic`, and `Generic1` instance for `Const`.+  * There are now `Show`, `Read`, `Eq`, `Ord`, `Monoid`, `Generic`, and+    `Generic1` instances for `Const`.    * There is now a `Data` instance for `Data.Version`. 
config.guess view
@@ -1,8 +1,8 @@ #! /bin/sh # Attempt to guess a canonical system name.-#   Copyright 1992-2013 Free Software Foundation, Inc.+#   Copyright 1992-2014 Free Software Foundation, Inc. -timestamp='2013-06-10'+timestamp='2014-03-23'  # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by@@ -50,7 +50,7 @@ GNU config.guess ($timestamp)  Originally written by Per Bothner.-Copyright 1992-2013 Free Software Foundation, Inc.+Copyright 1992-2014 Free Software Foundation, Inc.  This is free software; see the source for copying conditions.  There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."@@ -149,7 +149,7 @@ 	LIBC=gnu 	#endif 	EOF-	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC'`+	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC' | sed 's, ,,g'` 	;; esac @@ -826,7 +826,7 @@     *:MINGW*:*) 	echo ${UNAME_MACHINE}-pc-mingw32 	exit ;;-    i*:MSYS*:*)+    *:MSYS*:*) 	echo ${UNAME_MACHINE}-pc-msys 	exit ;;     i*:windows32*:*)@@ -969,10 +969,10 @@ 	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'` 	test x"${CPU}" != x && { echo "${CPU}-unknown-linux-${LIBC}"; exit; } 	;;-    or1k:Linux:*:*)-	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}+    openrisc*:Linux:*:*)+	echo or1k-unknown-linux-${LIBC} 	exit ;;-    or32:Linux:*:*)+    or32:Linux:*:* | or1k*:Linux:*:*) 	echo ${UNAME_MACHINE}-unknown-linux-${LIBC} 	exit ;;     padre:Linux:*:*)@@ -1260,16 +1260,26 @@ 	if test "$UNAME_PROCESSOR" = unknown ; then 	    UNAME_PROCESSOR=powerpc 	fi-	if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then-	    if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \-		(CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \-		grep IS_64BIT_ARCH >/dev/null-	    then-		case $UNAME_PROCESSOR in-		    i386) UNAME_PROCESSOR=x86_64 ;;-		    powerpc) UNAME_PROCESSOR=powerpc64 ;;-		esac+	if test `echo "$UNAME_RELEASE" | sed -e 's/\..*//'` -le 10 ; then+	    if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then+		if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \+		    (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \+		    grep IS_64BIT_ARCH >/dev/null+		then+		    case $UNAME_PROCESSOR in+			i386) UNAME_PROCESSOR=x86_64 ;;+			powerpc) UNAME_PROCESSOR=powerpc64 ;;+		    esac+		fi 	    fi+	elif test "$UNAME_PROCESSOR" = i386 ; then+	    # Avoid executing cc on OS X 10.9, as it ships with a stub+	    # that puts up a graphical alert prompting to install+	    # developer tools.  Any system running Mac OS X 10.7 or+	    # later (Darwin 11 and later) is required to have a 64-bit+	    # processor. This is not true of the ARM version of Darwin+	    # that Apple uses in portable devices.+	    UNAME_PROCESSOR=x86_64 	fi 	echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} 	exit ;;@@ -1360,154 +1370,6 @@ 	echo ${UNAME_MACHINE}-unknown-esx 	exit ;; esac--eval $set_cc_for_build-cat >$dummy.c <<EOF-#ifdef _SEQUENT_-# include <sys/types.h>-# include <sys/utsname.h>-#endif-main ()-{-#if defined (sony)-#if defined (MIPSEB)-  /* BFD wants "bsd" instead of "newsos".  Perhaps BFD should be changed,-     I don't know....  */-  printf ("mips-sony-bsd\n"); exit (0);-#else-#include <sys/param.h>-  printf ("m68k-sony-newsos%s\n",-#ifdef NEWSOS4-	"4"-#else-	""-#endif-	); exit (0);-#endif-#endif--#if defined (__arm) && defined (__acorn) && defined (__unix)-  printf ("arm-acorn-riscix\n"); exit (0);-#endif--#if defined (hp300) && !defined (hpux)-  printf ("m68k-hp-bsd\n"); exit (0);-#endif--#if defined (NeXT)-#if !defined (__ARCHITECTURE__)-#define __ARCHITECTURE__ "m68k"-#endif-  int version;-  version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`;-  if (version < 4)-    printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version);-  else-    printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version);-  exit (0);-#endif--#if defined (MULTIMAX) || defined (n16)-#if defined (UMAXV)-  printf ("ns32k-encore-sysv\n"); exit (0);-#else-#if defined (CMU)-  printf ("ns32k-encore-mach\n"); exit (0);-#else-  printf ("ns32k-encore-bsd\n"); exit (0);-#endif-#endif-#endif--#if defined (__386BSD__)-  printf ("i386-pc-bsd\n"); exit (0);-#endif--#if defined (sequent)-#if defined (i386)-  printf ("i386-sequent-dynix\n"); exit (0);-#endif-#if defined (ns32000)-  printf ("ns32k-sequent-dynix\n"); exit (0);-#endif-#endif--#if defined (_SEQUENT_)-    struct utsname un;--    uname(&un);--    if (strncmp(un.version, "V2", 2) == 0) {-	printf ("i386-sequent-ptx2\n"); exit (0);-    }-    if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */-	printf ("i386-sequent-ptx1\n"); exit (0);-    }-    printf ("i386-sequent-ptx\n"); exit (0);--#endif--#if defined (vax)-# if !defined (ultrix)-#  include <sys/param.h>-#  if defined (BSD)-#   if BSD == 43-      printf ("vax-dec-bsd4.3\n"); exit (0);-#   else-#    if BSD == 199006-      printf ("vax-dec-bsd4.3reno\n"); exit (0);-#    else-      printf ("vax-dec-bsd\n"); exit (0);-#    endif-#   endif-#  else-    printf ("vax-dec-bsd\n"); exit (0);-#  endif-# else-    printf ("vax-dec-ultrix\n"); exit (0);-# endif-#endif--#if defined (alliant) && defined (i860)-  printf ("i860-alliant-bsd\n"); exit (0);-#endif--  exit (1);-}-EOF--$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` &&-	{ echo "$SYSTEM_NAME"; exit; }--# Apollos put the system type in the environment.--test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; }--# Convex versions that predate uname can use getsysinfo(1)--if [ -x /usr/convex/getsysinfo ]-then-    case `getsysinfo -f cpu_type` in-    c1*)-	echo c1-convex-bsd-	exit ;;-    c2*)-	if getsysinfo -f scalar_acc-	then echo c32-convex-bsd-	else echo c2-convex-bsd-	fi-	exit ;;-    c34*)-	echo c34-convex-bsd-	exit ;;-    c38*)-	echo c38-convex-bsd-	exit ;;-    c4*)-	echo c4-convex-bsd-	exit ;;-    esac-fi  cat >&2 <<EOF $0: unable to guess system type
config.sub view
@@ -1,8 +1,8 @@ #! /bin/sh # Configuration validation subroutine script.-#   Copyright 1992-2013 Free Software Foundation, Inc.+#   Copyright 1992-2014 Free Software Foundation, Inc. -timestamp='2013-08-10'+timestamp='2014-05-01'  # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by@@ -68,7 +68,7 @@ version="\ GNU config.sub ($timestamp) -Copyright 1992-2013 Free Software Foundation, Inc.+Copyright 1992-2014 Free Software Foundation, Inc.  This is free software; see the source for copying conditions.  There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."@@ -265,6 +265,7 @@ 	| hexagon \ 	| i370 | i860 | i960 | ia64 \ 	| ip2k | iq2000 \+	| k1om \ 	| le32 | le64 \ 	| lm32 \ 	| m32c | m32r | m32rle | m68000 | m68k | m88k \@@ -282,8 +283,10 @@ 	| mips64vr5900 | mips64vr5900el \ 	| mipsisa32 | mipsisa32el \ 	| mipsisa32r2 | mipsisa32r2el \+	| mipsisa32r6 | mipsisa32r6el \ 	| mipsisa64 | mipsisa64el \ 	| mipsisa64r2 | mipsisa64r2el \+	| mipsisa64r6 | mipsisa64r6el \ 	| mipsisa64sb1 | mipsisa64sb1el \ 	| mipsisa64sr71k | mipsisa64sr71kel \ 	| mipsr5900 | mipsr5900el \@@ -295,8 +298,7 @@ 	| nds32 | nds32le | nds32be \ 	| nios | nios2 | nios2eb | nios2el \ 	| ns16k | ns32k \-	| open8 \-	| or1k | or32 \+	| open8 | or1k | or1knd | or32 \ 	| pdp10 | pdp11 | pj | pjl \ 	| powerpc | powerpc64 | powerpc64le | powerpcle \ 	| pyramid \@@ -324,7 +326,7 @@ 	c6x) 		basic_machine=tic6x-unknown 		;;-	m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x | picochip)+	m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x | nvptx | picochip) 		basic_machine=$basic_machine-unknown 		os=-none 		;;@@ -381,6 +383,7 @@ 	| hexagon-* \ 	| i*86-* | i860-* | i960-* | ia64-* \ 	| ip2k-* | iq2000-* \+	| k1om-* \ 	| le32-* | le64-* \ 	| lm32-* \ 	| m32c-* | m32r-* | m32rle-* \@@ -400,8 +403,10 @@ 	| mips64vr5900-* | mips64vr5900el-* \ 	| mipsisa32-* | mipsisa32el-* \ 	| mipsisa32r2-* | mipsisa32r2el-* \+	| mipsisa32r6-* | mipsisa32r6el-* \ 	| mipsisa64-* | mipsisa64el-* \ 	| mipsisa64r2-* | mipsisa64r2el-* \+	| mipsisa64r6-* | mipsisa64r6el-* \ 	| mipsisa64sb1-* | mipsisa64sb1el-* \ 	| mipsisa64sr71k-* | mipsisa64sr71kel-* \ 	| mipsr5900-* | mipsr5900el-* \@@ -413,6 +418,7 @@ 	| nios-* | nios2-* | nios2eb-* | nios2el-* \ 	| none-* | np1-* | ns16k-* | ns32k-* \ 	| open8-* \+	| or1k*-* \ 	| orion-* \ 	| pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ 	| powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* \@@ -1374,7 +1380,7 @@ 	      | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \ 	      | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \ 	      | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \-	      | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es*)+	      | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es* | -tirtos*) 	# Remember, each alternative MUST END IN *, to match a version number. 		;; 	-qnx*)@@ -1590,9 +1596,6 @@ 		os=-elf 		;; 	mips*-*)-		os=-elf-		;;-	or1k-*) 		os=-elf 		;; 	or32-*)
configure view
@@ -3303,7 +3303,7 @@ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for WINDOWS platform" >&5 $as_echo_n "checking for WINDOWS platform... " >&6; } case $host in-    *mingw32*|*mingw64*|*cygwin*)+    *mingw32*|*mingw64*|*cygwin*|*msys*)         WINDOWS=YES;;     *)         WINDOWS=NO;;
configure.ac view
@@ -16,7 +16,7 @@  AC_MSG_CHECKING(for WINDOWS platform) case $host in-    *mingw32*|*mingw64*|*cygwin*)+    *mingw32*|*mingw64*|*cygwin*|*msys*)         WINDOWS=YES;;     *)         WINDOWS=NO;;
− include/OldTypeable.h
@@ -1,29 +0,0 @@-{- ---------------------------------------------------------------------------// Macros to help make Typeable instances.-//-// INSTANCE_TYPEABLEn(tc,tcname,"tc") defines-//-//	instance Typeable/n/ tc-//	instance Typeable a => Typeable/n-1/ (tc a)-//	instance (Typeable a, Typeable b) => Typeable/n-2/ (tc a b)-//	...-//	instance (Typeable a1, ..., Typeable an) => Typeable (tc a1 ... an)-// ----------------------------------------------------------------------------}--#ifndef TYPEABLE_H-#define TYPEABLE_H----  // For GHC, we can use DeriveDataTypeable + StandaloneDeriving to---  // generate the instances.--#define INSTANCE_TYPEABLE0(tycon,tcname,str) deriving instance Typeable tycon-#define INSTANCE_TYPEABLE1(tycon,tcname,str) deriving instance Typeable1 tycon-#define INSTANCE_TYPEABLE2(tycon,tcname,str) deriving instance Typeable2 tycon-#define INSTANCE_TYPEABLE3(tycon,tcname,str) deriving instance Typeable3 tycon-#define INSTANCE_TYPEABLE4(tycon,tcname,str) deriving instance Typeable4 tycon-#define INSTANCE_TYPEABLE5(tycon,tcname,str) deriving instance Typeable5 tycon-#define INSTANCE_TYPEABLE6(tycon,tcname,str) deriving instance Typeable6 tycon-#define INSTANCE_TYPEABLE7(tycon,tcname,str) deriving instance Typeable7 tycon--#endif
include/WCsubst.h view
@@ -2,23 +2,24 @@  #define WCSUBST_INCL +#include "HsFFI.h" #include <stdlib.h> -int u_iswupper(int wc);-int u_iswdigit(int wc);-int u_iswalpha(int wc);-int u_iswcntrl(int wc);-int u_iswspace(int wc);-int u_iswprint(int wc);-int u_iswlower(int wc);+HsInt u_iswupper(HsInt wc);+HsInt u_iswdigit(HsInt wc);+HsInt u_iswalpha(HsInt wc);+HsInt u_iswcntrl(HsInt wc);+HsInt u_iswspace(HsInt wc);+HsInt u_iswprint(HsInt wc);+HsInt u_iswlower(HsInt wc); -int u_iswalnum(int wc);+HsInt u_iswalnum(HsInt wc); -int u_towlower(int wc);-int u_towupper(int wc);-int u_towtitle(int wc);+HsInt u_towlower(HsInt wc);+HsInt u_towupper(HsInt wc);+HsInt u_towtitle(HsInt wc); -int u_gencat(int wc);+HsInt u_gencat(HsInt wc);  #endif