haskell2010 (empty) → 1.0.0.0
raw patch · 34 files changed
+2252/−0 lines, 34 filesdep +arraydep +basedep +ghc-primsetup-changed
Dependencies added: array, base, ghc-prim
Files
- Control/Monad.hs +89/−0
- Data/Array.hs +185/−0
- Data/Bits.hs +22/−0
- Data/Char.hs +39/−0
- Data/Complex.hs +116/−0
- Data/Int.hs +39/−0
- Data/Ix.hs +67/−0
- Data/List.hs +184/−0
- Data/Maybe.hs +66/−0
- Data/Ratio.hs +113/−0
- Data/Word.hs +49/−0
- Foreign.hs +22/−0
- Foreign/C.hs +13/−0
- Foreign/C/Error.hs +84/−0
- Foreign/C/String.hs +83/−0
- Foreign/C/Types.hs +88/−0
- Foreign/ForeignPtr.hs +71/−0
- Foreign/Marshal.hs +43/−0
- Foreign/Marshal/Alloc.hs +42/−0
- Foreign/Marshal/Array.hs +69/−0
- Foreign/Marshal/Error.hs +15/−0
- Foreign/Marshal/Utils.hs +34/−0
- Foreign/Ptr.hs +38/−0
- Foreign/StablePtr.hs +26/−0
- Foreign/Storable.hs +12/−0
- LICENSE +12/−0
- Numeric.hs +43/−0
- Prelude.hs +183/−0
- Setup.hs +2/−0
- System/Environment.hs +6/−0
- System/Exit.hs +39/−0
- System/IO.hs +204/−0
- System/IO/Error.hs +86/−0
- haskell2010.cabal +68/−0
+ Control/Monad.hs view
@@ -0,0 +1,89 @@+-- |+-- The "Control.Monad" module provides the 'Functor', 'Monad' and+-- 'MonadPlus' classes, together with some useful operations on monads.++module Control.Monad (+ -- * Functor and monad classes++ Functor(fmap)+ , Monad((>>=), (>>), return, fail)++ , MonadPlus ( -- class context: Monad+ mzero -- :: (MonadPlus m) => m a+ , mplus -- :: (MonadPlus m) => m a -> m a -> m a+ )+ -- * Functions++ -- ** Naming conventions+ -- $naming++ -- ** Basic @Monad@ functions++ , mapM -- :: (Monad m) => (a -> m b) -> [a] -> m [b]+ , mapM_ -- :: (Monad m) => (a -> m b) -> [a] -> m ()+ , forM -- :: (Monad m) => [a] -> (a -> m b) -> m [b]+ , forM_ -- :: (Monad m) => [a] -> (a -> m b) -> m ()+ , sequence -- :: (Monad m) => [m a] -> m [a]+ , sequence_ -- :: (Monad m) => [m a] -> m ()+ , (=<<) -- :: (Monad m) => (a -> m b) -> m a -> m b+ , (>=>) -- :: (Monad m) => (a -> m b) -> (b -> m c) -> (a -> m c)+ , (<=<) -- :: (Monad m) => (b -> m c) -> (a -> m b) -> (a -> m c)+ , forever -- :: (Monad m) => m a -> m b+ , void++ -- ** Generalisations of list functions++ , join -- :: (Monad m) => m (m a) -> m a+ , msum -- :: (MonadPlus m) => [m a] -> m a+ , filterM -- :: (Monad m) => (a -> m Bool) -> [a] -> m [a]+ , mapAndUnzipM -- :: (Monad m) => (a -> m (b,c)) -> [a] -> m ([b], [c])+ , zipWithM -- :: (Monad m) => (a -> b -> m c) -> [a] -> [b] -> m [c]+ , zipWithM_ -- :: (Monad m) => (a -> b -> m c) -> [a] -> [b] -> m ()+ , foldM -- :: (Monad m) => (a -> b -> m a) -> a -> [b] -> m a + , foldM_ -- :: (Monad m) => (a -> b -> m a) -> a -> [b] -> m ()+ , replicateM -- :: (Monad m) => Int -> m a -> m [a]+ , replicateM_ -- :: (Monad m) => Int -> m a -> m ()++ -- ** Conditional execution of monadic expressions++ , guard -- :: (MonadPlus m) => Bool -> m ()+ , when -- :: (Monad m) => Bool -> m () -> m ()+ , unless -- :: (Monad m) => Bool -> m () -> m ()++ -- ** Monadic lifting operators++ , liftM -- :: (Monad m) => (a -> b) -> (m a -> m b)+ , liftM2 -- :: (Monad m) => (a -> b -> c) -> (m a -> m b -> m c)+ , liftM3 -- :: ...+ , liftM4 -- :: ...+ , liftM5 -- :: ...++ , ap -- :: (Monad m) => m (a -> b) -> m a -> m b++ ) where+import "base" Control.Monad++{- $naming++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, ++> 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: ++> 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: ++> sum :: Num a => [a] -> a+> msum :: MonadPlus m => [m a] -> m a++-}
+ Data/Array.hs view
@@ -0,0 +1,185 @@+module Data.Array (+ -- * Immutable non-strict arrays+ -- $intro+ module Data.Ix -- export all of Ix + , Array -- Array type is abstract++ -- * Array construction+ , array -- :: (Ix a) => (a,a) -> [(a,b)] -> Array a b+ , listArray -- :: (Ix a) => (a,a) -> [b] -> Array a b+ , accumArray -- :: (Ix a) => (b -> c -> b) -> b -> (a,a) -> [(a,c)] -> Array a b+ -- * Accessing arrays+ , (!) -- :: (Ix a) => Array a b -> a -> b+ , bounds -- :: (Ix a) => Array a b -> (a,a)+ , indices -- :: (Ix a) => Array a b -> [a]+ , elems -- :: (Ix a) => Array a b -> [b]+ , assocs -- :: (Ix a) => Array a b -> [(a,b)]+ -- * Incremental array updates+ , (//) -- :: (Ix a) => Array a b -> [(a,b)] -> Array a b+ , accum -- :: (Ix a) => (b -> c -> b) -> Array a b -> [(a,c)] -> Array a b+ -- * Derived arrays+ , ixmap -- :: (Ix a, Ix b) => (a,a) -> (a -> b) -> Array b c -> Array a b++ -- * Specification++ -- $code+ ) where++import qualified "array" Data.Array as Array+import "array" Data.Array hiding (array, (//))+import "base" Data.Ix++{- $intro+Haskell provides indexable /arrays/, which may be thought of as functions+whose domains are isomorphic to contiguous subsets of the integers.+Functions restricted in this way can be implemented efficiently;+in particular, a programmer may reasonably expect rapid access to+the components. To ensure the possibility of such an implementation,+arrays are treated as data, not as general functions.++Since most array functions involve the class 'Ix', the contents of the+module "Data.Ix" are re-exported from "Data.Array" for convenience:+-}++-- SDM: copied documentation for 'array' to remove GHC reference++-- | 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. If any+-- two associations in the list have the same index, the value at that+-- index is undefined (i.e. bottom).+--+-- 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.+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 = Array.array++-- SDM copied docs for (//) to remove GHC reference++-- | 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':+-- the resulting array is undefined (i.e. bottom),+(//) :: Ix i => Array i e -> [(i, e)] -> Array i e+(//) = (Array.//)++{- $code+> module Array ( +> module Data.Ix, -- export all of Data.Ix+> Array, array, listArray, (!), bounds, indices, elems, assocs, +> accumArray, (//), accum, ixmap ) where+> +> import Data.Ix+> import Data.List( (\\) )+> +> infixl 9 !, //+> +> data (Ix a) => Array a b = MkArray (a,a) (a -> b) deriving ()+> +> array :: (Ix a) => (a,a) -> [(a,b)] -> Array a b+> array b ivs+> | any (not . inRange b. fst) ivs+> = error "Data.Array.array: out-of-range array association"+> | otherwise+> = MkArray b arr+> where+> arr j = case [ v | (i,v) <- ivs, i == j ] of+> [v] -> v+> [] -> error "Data.Array.!: undefined array element"+> _ -> error "Data.Array.!: multiply defined array element"+> +> listArray :: (Ix a) => (a,a) -> [b] -> Array a b+> listArray b vs = array b (zipWith (\ a b -> (a,b)) (range b) vs)+> +> (!) :: (Ix a) => Array a b -> a -> b+> (!) (MkArray _ f) = f+> +> bounds :: (Ix a) => Array a b -> (a,a)+> bounds (MkArray b _) = b+> +> indices :: (Ix a) => Array a b -> [a]+> indices = range . bounds+> +> elems :: (Ix a) => Array a b -> [b]+> elems a = [a!i | i <- indices a]+> +> assocs :: (Ix a) => Array a b -> [(a,b)]+> assocs a = [(i, a!i) | i <- indices a]+> +> (//) :: (Ix a) => Array a b -> [(a,b)] -> Array a b+> a // new_ivs = array (bounds a) (old_ivs ++ new_ivs)+> where+> old_ivs = [(i,a!i) | i <- indices a,+> i `notElem` new_is]+> new_is = [i | (i,_) <- new_ivs]+> +> accum :: (Ix a) => (b -> c -> b) -> Array a b -> [(a,c)]+> -> Array a b+> accum f = foldl (\a (i,v) -> a // [(i,f (a!i) v)])+> +> accumArray :: (Ix a) => (b -> c -> b) -> b -> (a,a) -> [(a,c)]+> -> Array a b+> accumArray f z b = accum f (array b [(i,z) | i <- range b])+> +> ixmap :: (Ix a, Ix b) => (a,a) -> (a -> b) -> Array b c+> -> Array a c+> ixmap b f a = array b [(i, a ! f i) | i <- range b]+> +> instance (Ix a) => Functor (Array a) where+> fmap fn (MkArray b f) = MkArray b (fn . f) +> +> instance (Ix a, Eq b) => Eq (Array a b) where+> a == a' = assocs a == assocs a'+> +> instance (Ix a, Ord b) => Ord (Array a b) where+> a <= a' = assocs a <= assocs a'+> +> instance (Ix a, Show a, Show b) => Show (Array a b) where+> showsPrec p a = showParen (p > arrPrec) (+> showString "array " .+> showsPrec (arrPrec+1) (bounds a) . showChar ' ' .+> showsPrec (arrPrec+1) (assocs a) )+> +> instance (Ix a, Read a, Read b) => Read (Array a b) where+> readsPrec p = readParen (p > arrPrec)+> (\r -> [ (array b as, u) +> | ("array",s) <- lex r,+> (b,t) <- readsPrec (arrPrec+1) s,+> (as,u) <- readsPrec (arrPrec+1) t ])+> +> -- Precedence of the 'array' function is that of application itself+> arrPrec = 10+-}
+ Data/Bits.hs view
@@ -0,0 +1,22 @@+-- |+-- This module defines bitwise operations for signed and unsigned+-- integers.++module Data.Bits (+ Bits(+ (.&.), (.|.), xor, -- :: a -> a -> a+ complement, -- :: a -> a+ shift, -- :: a -> Int -> a+ rotate, -- :: a -> Int -> a+ bit, -- :: Int -> a+ setBit, -- :: a -> Int -> a+ clearBit, -- :: a -> Int -> a+ complementBit, -- :: a -> Int -> a+ testBit, -- :: a -> Int -> Bool+ bitSize, -- :: a -> Int+ isSigned, -- :: a -> Bool+ shiftL, shiftR, -- :: a -> Int -> a+ rotateL, rotateR -- :: a -> Int -> a+ )+ ) where+import "base" Data.Bits
+ Data/Char.hs view
@@ -0,0 +1,39 @@+module Data.Char (+ -- * Characters and strings+ Char++ , String++ -- * Character classification+ -- | Unicode characters are divided into letters, numbers, marks,+ -- punctuation, symbols, separators (including spaces) and others+ -- (including control characters).+ , isControl, isSpace+ , isLower, isUpper, isAlpha, isAlphaNum, isPrint+ , isDigit, isOctDigit, isHexDigit+ , isLetter, isMark, isNumber, isPunctuation, isSymbol, isSeparator++ -- ** Subranges+ , isAscii, isLatin1+ , isAsciiUpper, isAsciiLower++ -- ** Unicode general categories+ , GeneralCategory(..), generalCategory++ -- * Case conversion+ , toUpper, toLower, toTitle -- :: Char -> Char++ -- * Single digit characters+ , digitToInt -- :: Char -> Int+ , intToDigit -- :: Int -> Char++ -- * Numeric representations+ , ord -- :: Char -> Int+ , chr -- :: Int -> Char++ -- * String representations+ , showLitChar -- :: Char -> ShowS+ , lexLitChar -- :: ReadS String+ , readLitChar -- :: ReadS Char + ) where+import "base" Data.Char
+ Data/Complex.hs view
@@ -0,0 +1,116 @@+module Data.Complex (+ -- * Rectangular form+ Complex((:+))++ , realPart -- :: (RealFloat a) => Complex a -> a+ , imagPart -- :: (RealFloat a) => Complex a -> a+ -- * Polar form+ , mkPolar -- :: (RealFloat a) => a -> a -> Complex a+ , cis -- :: (RealFloat a) => a -> Complex a+ , polar -- :: (RealFloat a) => Complex a -> (a,a)+ , magnitude -- :: (RealFloat a) => Complex a -> a+ , phase -- :: (RealFloat a) => Complex a -> a+ -- * Conjugate+ , conjugate -- :: (RealFloat a) => Complex a -> Complex a++ -- * Specification++ -- $code+ ) where+import "base" Data.Complex++{- $code+> module Data.Complex(Complex((:+)), realPart, imagPart, conjugate, mkPolar,+> cis, polar, magnitude, phase) where+> +> infix 6 :++> +> data (RealFloat a) => Complex a = !a :+ !a deriving (Eq,Read,Show)+> +> +> realPart, imagPart :: (RealFloat a) => Complex a -> a+> realPart (x:+y) = x+> imagPart (x:+y) = y+> +> conjugate :: (RealFloat a) => Complex a -> Complex a+> conjugate (x:+y) = x :+ (-y)+> +> mkPolar :: (RealFloat a) => a -> a -> Complex a+> mkPolar r theta = r * cos theta :+ r * sin theta+> +> cis :: (RealFloat a) => a -> Complex a+> cis theta = cos theta :+ sin theta+> +> polar :: (RealFloat a) => Complex a -> (a,a)+> polar z = (magnitude z, phase z)+> +> magnitude :: (RealFloat a) => Complex a -> a+> magnitude (x:+y) = scaleFloat k+> (sqrt ((scaleFloat mk x)^2 + (scaleFloat mk y)^2))+> where k = max (exponent x) (exponent y)+> mk = - k+> +> phase :: (RealFloat a) => Complex a -> a+> phase (0 :+ 0) = 0+> phase (x :+ y) = atan2 y x+> +> +> instance (RealFloat a) => Num (Complex a) where+> (x:+y) + (x':+y') = (x+x') :+ (y+y')+> (x:+y) - (x':+y') = (x-x') :+ (y-y')+> (x:+y) * (x':+y') = (x*x'-y*y') :+ (x*y'+y*x')+> negate (x:+y) = negate x :+ negate y+> abs z = magnitude z :+ 0+> signum 0 = 0+> signum z@(x:+y) = x/r :+ y/r where r = magnitude z+> fromInteger n = fromInteger n :+ 0+> +> instance (RealFloat a) => Fractional (Complex a) where+> (x:+y) / (x':+y') = (x*x''+y*y'') / d :+ (y*x''-x*y'') / d+> where x'' = scaleFloat k x'+> y'' = scaleFloat k y'+> k = - max (exponent x') (exponent y')+> d = x'*x'' + y'*y''+>+> fromRational a = fromRational a :+ 0+> +> instance (RealFloat a) => Floating (Complex a) where+> pi = pi :+ 0+> exp (x:+y) = expx * cos y :+ expx * sin y+> where expx = exp x+> log z = log (magnitude z) :+ phase z+> +> sqrt 0 = 0+> sqrt z@(x:+y) = u :+ (if y < 0 then -v else v)+> where (u,v) = if x < 0 then (v',u') else (u',v')+> v' = abs y / (u'*2)+> u' = sqrt ((magnitude z + abs x) / 2)+> +> sin (x:+y) = sin x * cosh y :+ cos x * sinh y+> cos (x:+y) = cos x * cosh y :+ (- sin x * sinh y)+> tan (x:+y) = (sinx*coshy:+cosx*sinhy)/(cosx*coshy:+(-sinx*sinhy))+> where sinx = sin x+> cosx = cos x+> sinhy = sinh y+> coshy = cosh y+> +> sinh (x:+y) = cos y * sinh x :+ sin y * cosh x+> cosh (x:+y) = cos y * cosh x :+ sin y * sinh x+> tanh (x:+y) = (cosy*sinhx:+siny*coshx)/(cosy*coshx:+siny*sinhx)+> where siny = sin y+> cosy = cos y+> sinhx = sinh x+> coshx = cosh x+> +> asin z@(x:+y) = y':+(-x')+> where (x':+y') = log (((-y):+x) + sqrt (1 - z*z))+> acos z@(x:+y) = y'':+(-x'')+> where (x'':+y'') = log (z + ((-y'):+x'))+> (x':+y') = sqrt (1 - z*z)+> atan z@(x:+y) = y':+(-x')+> where (x':+y') = log (((1-y):+x) / sqrt (1+z*z))+> +> asinh z = log (z + sqrt (1+z*z))+> acosh z = log (z + (z+1) * sqrt ((z-1)/(z+1)))+> atanh z = log ((1+z) / sqrt (1-z*z))+> -}
+ Data/Int.hs view
@@ -0,0 +1,39 @@+module Data.Int (+ -- * Signed integer types++ -- $notes++ Int,+ Int8, Int16, Int32, Int64,++ ) where+import "base" Data.Int++-- SDM: removed after 'Prelude.fromIntegral':+-- ..., which is specialized for all the common cases+-- so should be fast enough++{- $notes++This module provides signed integer types of unspecified width ('Int')+and fixed widths ('Int8', 'Int16', 'Int32' and 'Int64'). All+arithmetic is performed modulo 2^n, where @n@ is the number of bits in+the type.++For coercing between any two integer types, use+'Prelude.fromIntegral'. Coercing word types (see "Data.Word") to and+from integer types preserves representation, not sign.++The rules that hold for 'Prelude.Enum' instances over a bounded type+such as 'Int' (see the section of the Haskell language report dealing with+arithmetic sequences) also hold for the 'Prelude.Enum' instances over+the various 'Int' types defined here.++Right and left shifts by amounts greater than or equal to the width of+the type result in either zero or -1, depending on the sign of the+value being shifted. This is contrary to the behaviour in C, which is+undefined; a common interpretation is to truncate the shift count to+the width of the type, for example @1 \<\< 32 == 1@ in some C+implementations.+-}+
+ Data/Ix.hs view
@@ -0,0 +1,67 @@+module Data.Ix (+ -- * The 'Ix' class+ Ix+ ( range -- :: (Ix a) => (a,a) -> [a]+ , index -- :: (Ix a) => (a,a) -> a -> Int+ , inRange -- :: (Ix a) => (a,a) -> a -> Bool+ , rangeSize -- :: (Ix a) => (a,a) -> Int+ )++ -- * Deriving Instances of @Ix@+ + -- $derived+ ) where+import "base" Data.Ix++{- $derived+It is possible to derive an instance of @Ix@ automatically, using+a @deriving@ clause on a @data@ declaration.+Such derived instance declarations for the class @Ix@ are only possible+for enumerations (i.e. datatypes having+only nullary constructors) and single-constructor datatypes,+whose constituent types are instances of @Ix@. A Haskell implementation+must provide @Ix@ instances for tuples up to at least size 15.++For an /enumeration/, the nullary constructors are assumed to be+numbered left-to-right with the indices being 0 to n-1 inclusive.+This is the same numbering defined by the @Enum@ class. For example,+given the datatype:++> data Colour = Red | Orange | Yellow | Green | Blue | Indigo | Violet++we would have:++> range (Yellow,Blue) == [Yellow,Green,Blue]+> index (Yellow,Blue) Green == 1+> inRange (Yellow,Blue) Red == False++For /single-constructor datatypes/, the derived instance declarations+are as shown for tuples:++> instance (Ix a, Ix b) => Ix (a,b) where+> range ((l,l'),(u,u'))+> = [(i,i') | i <- range (l,u), i' <- range (l',u')]+> index ((l,l'),(u,u')) (i,i')+> = index (l,u) i * rangeSize (l',u') + index (l',u') i'+> inRange ((l,l'),(u,u')) (i,i')+> = inRange (l,u) i && inRange (l',u') i'+> +> -- Instances for other tuples are obtained from this scheme:+> --+> -- instance (Ix a1, Ix a2, ... , Ix ak) => Ix (a1,a2,...,ak) where+> -- range ((l1,l2,...,lk),(u1,u2,...,uk)) =+> -- [(i1,i2,...,ik) | i1 <- range (l1,u1),+> -- i2 <- range (l2,u2),+> -- ...+> -- ik <- range (lk,uk)]+> --+> -- index ((l1,l2,...,lk),(u1,u2,...,uk)) (i1,i2,...,ik) =+> -- index (lk,uk) ik + rangeSize (lk,uk) * (+> -- index (lk-1,uk-1) ik-1 + rangeSize (lk-1,uk-1) * (+> -- ...+> -- index (l1,u1)))+> --+> -- inRange ((l1,l2,...lk),(u1,u2,...,uk)) (i1,i2,...,ik) =+> -- inRange (l1,u1) i1 && inRange (l2,u2) i2 &&+> -- ... && inRange (lk,uk) ik+-}
+ Data/List.hs view
@@ -0,0 +1,184 @@+module Data.List (+ -- * Basic functions++ (++) -- :: [a] -> [a] -> [a]+ , head -- :: [a] -> a+ , last -- :: [a] -> a+ , tail -- :: [a] -> [a]+ , init -- :: [a] -> [a]+ , null -- :: [a] -> Bool+ , length -- :: [a] -> Int++ -- * List transformations+ , map -- :: (a -> b) -> [a] -> [b]+ , reverse -- :: [a] -> [a]++ , intersperse -- :: a -> [a] -> [a]+ , intercalate -- :: [a] -> [[a]] -> [a]+ , transpose -- :: [[a]] -> [[a]]+ + , subsequences -- :: [a] -> [[a]]+ , permutations -- :: [a] -> [[a]]++ -- * Reducing lists (folds)++ , foldl -- :: (a -> b -> a) -> a -> [b] -> a+ , foldl' -- :: (a -> b -> a) -> a -> [b] -> a+ , foldl1 -- :: (a -> a -> a) -> [a] -> a+ , foldl1' -- :: (a -> a -> a) -> [a] -> a+ , foldr -- :: (a -> b -> b) -> b -> [a] -> b+ , foldr1 -- :: (a -> a -> a) -> [a] -> a++ -- ** Special folds++ , concat -- :: [[a]] -> [a]+ , concatMap -- :: (a -> [b]) -> [a] -> [b]+ , and -- :: [Bool] -> Bool+ , or -- :: [Bool] -> Bool+ , any -- :: (a -> Bool) -> [a] -> Bool+ , all -- :: (a -> Bool) -> [a] -> Bool+ , sum -- :: (Num a) => [a] -> a+ , product -- :: (Num a) => [a] -> a+ , maximum -- :: (Ord a) => [a] -> a+ , minimum -- :: (Ord a) => [a] -> a++ -- * Building lists++ -- ** Scans+ , scanl -- :: (a -> b -> a) -> a -> [b] -> [a]+ , scanl1 -- :: (a -> a -> a) -> [a] -> [a]+ , scanr -- :: (a -> b -> b) -> b -> [a] -> [b]+ , scanr1 -- :: (a -> a -> a) -> [a] -> [a]++ -- ** Accumulating maps+ , mapAccumL -- :: (a -> b -> (a,c)) -> a -> [b] -> (a,[c])+ , mapAccumR -- :: (a -> b -> (a,c)) -> a -> [b] -> (a,[c])++ -- ** Infinite lists+ , iterate -- :: (a -> a) -> a -> [a]+ , repeat -- :: a -> [a]+ , replicate -- :: Int -> a -> [a]+ , cycle -- :: [a] -> [a]++ -- ** Unfolding+ , unfoldr -- :: (b -> Maybe (a, b)) -> b -> [a]++ -- * Sublists++ -- ** Extracting sublists+ , take -- :: Int -> [a] -> [a]+ , drop -- :: Int -> [a] -> [a]+ , splitAt -- :: Int -> [a] -> ([a], [a])++ , takeWhile -- :: (a -> Bool) -> [a] -> [a]+ , dropWhile -- :: (a -> Bool) -> [a] -> [a]+ , span -- :: (a -> Bool) -> [a] -> ([a], [a])+ , break -- :: (a -> Bool) -> [a] -> ([a], [a])++ , stripPrefix -- :: Eq a => [a] -> [a] -> Maybe [a]++ , group -- :: Eq a => [a] -> [[a]]++ , inits -- :: [a] -> [[a]]+ , tails -- :: [a] -> [[a]]++ -- ** Predicates+ , isPrefixOf -- :: (Eq a) => [a] -> [a] -> Bool+ , isSuffixOf -- :: (Eq a) => [a] -> [a] -> Bool+ , isInfixOf -- :: (Eq a) => [a] -> [a] -> Bool++ -- * Searching lists++ -- ** Searching by equality+ , elem -- :: a -> [a] -> Bool+ , notElem -- :: a -> [a] -> Bool+ , lookup -- :: (Eq a) => a -> [(a,b)] -> Maybe b++ -- ** Searching with a predicate+ , find -- :: (a -> Bool) -> [a] -> Maybe a+ , filter -- :: (a -> Bool) -> [a] -> [a]+ , partition -- :: (a -> Bool) -> [a] -> ([a], [a])++ -- * Indexing lists+ -- | These functions treat a list @xs@ as a indexed collection,+ -- with indices ranging from 0 to @'length' xs - 1@.++ , (!!) -- :: [a] -> Int -> a++ , elemIndex -- :: (Eq a) => a -> [a] -> Maybe Int+ , elemIndices -- :: (Eq a) => a -> [a] -> [Int]++ , findIndex -- :: (a -> Bool) -> [a] -> Maybe Int+ , findIndices -- :: (a -> Bool) -> [a] -> [Int]++ -- * Zipping and unzipping lists++ , zip -- :: [a] -> [b] -> [(a,b)]+ , zip3+ , zip4, zip5, zip6, zip7++ , zipWith -- :: (a -> b -> c) -> [a] -> [b] -> [c]+ , zipWith3+ , zipWith4, zipWith5, zipWith6, zipWith7++ , unzip -- :: [(a,b)] -> ([a],[b])+ , unzip3+ , unzip4, unzip5, unzip6, unzip7++ -- * Special lists++ -- ** Functions on strings+ , lines -- :: String -> [String]+ , words -- :: String -> [String]+ , unlines -- :: [String] -> String+ , unwords -- :: [String] -> String++ -- ** \"Set\" operations++ , nub -- :: (Eq a) => [a] -> [a]++ , delete -- :: (Eq a) => a -> [a] -> [a]+ , (\\) -- :: (Eq a) => [a] -> [a] -> [a]++ , union -- :: (Eq a) => [a] -> [a] -> [a]+ , intersect -- :: (Eq a) => [a] -> [a] -> [a]++ -- ** Ordered lists+ , sort -- :: (Ord a) => [a] -> [a]+ , insert -- :: (Ord a) => a -> [a] -> [a]++ -- * Generalized functions++ -- ** The \"@By@\" operations+ -- | By convention, overloaded functions have a non-overloaded+ -- counterpart whose name is suffixed with \`@By@\'.++ -- *** User-supplied equality (replacing an @Eq@ context)+ -- | The predicate is assumed to define an equivalence.+ , nubBy -- :: (a -> a -> Bool) -> [a] -> [a]+ , deleteBy -- :: (a -> a -> Bool) -> a -> [a] -> [a]+ , deleteFirstsBy -- :: (a -> a -> Bool) -> [a] -> [a] -> [a]+ , unionBy -- :: (a -> a -> Bool) -> [a] -> [a] -> [a]+ , intersectBy -- :: (a -> a -> Bool) -> [a] -> [a] -> [a]+ , groupBy -- :: (a -> a -> Bool) -> [a] -> [[a]]++ -- *** User-supplied comparison (replacing an @Ord@ context)+ -- | The function is assumed to define a total ordering.+ , sortBy -- :: (a -> a -> Ordering) -> [a] -> [a]+ , insertBy -- :: (a -> a -> Ordering) -> a -> [a] -> [a]+ , maximumBy -- :: (a -> a -> Ordering) -> [a] -> a+ , minimumBy -- :: (a -> a -> Ordering) -> [a] -> a++ -- ** The \"@generic@\" operations+ -- | The prefix \`@generic@\' indicates an overloaded function that+ -- is a generalized version of a "Prelude" function.++ , genericLength -- :: (Integral a) => [b] -> a+ , genericTake -- :: (Integral a) => a -> [b] -> [b]+ , genericDrop -- :: (Integral a) => a -> [b] -> [b]+ , genericSplitAt -- :: (Integral a) => a -> [b] -> ([b], [b])+ , genericIndex -- :: (Integral a) => [b] -> a -> b+ , genericReplicate -- :: (Integral a) => a -> b -> [b]++ ) where+import "base" Data.List
+ Data/Maybe.hs view
@@ -0,0 +1,66 @@+module Data.Maybe (+ -- * The @Maybe@ type and operations++ Maybe(Nothing,Just)-- instance of: Eq, Ord, Show, Read,+ -- Functor, Monad, MonadPlus++ , maybe -- :: b -> (a -> b) -> Maybe a -> b++ , isJust -- :: Maybe a -> Bool+ , isNothing -- :: Maybe a -> Bool+ , fromJust -- :: Maybe a -> a+ , fromMaybe -- :: a -> Maybe a -> a+ , listToMaybe -- :: [a] -> Maybe a+ , maybeToList -- :: Maybe a -> [a]+ , catMaybes -- :: [Maybe a] -> [a]+ , mapMaybe -- :: (a -> Maybe b) -> [a] -> [b]++ -- * Specification+ + -- $code++ ) where+import "base" Data.Maybe++{- $code+> module Data.Maybe(+> Maybe(Nothing, Just),+> isJust, isNothing,+> fromJust, fromMaybe, listToMaybe, maybeToList,+> catMaybes, mapMaybe,+> maybe+> ) where+> +> maybe :: b -> (a -> b) -> Maybe a -> b+> maybe n _ Nothing = n+> maybe _ f (Just x) = f x+> +> isJust :: Maybe a -> Bool+> isJust (Just a) = True+> isJust Nothing = False+> +> isNothing :: Maybe a -> Bool+> isNothing = not . isJust+> +> fromJust :: Maybe a -> a+> fromJust (Just a) = a+> fromJust Nothing = error "Maybe.fromJust: Nothing"+> +> fromMaybe :: a -> Maybe a -> a+> fromMaybe d Nothing = d+> fromMaybe d (Just a) = a+> +> maybeToList :: Maybe a -> [a]+> maybeToList Nothing = []+> maybeToList (Just a) = [a]+> +> listToMaybe :: [a] -> Maybe a+> listToMaybe [] = Nothing+> listToMaybe (a:_) = Just a+> +> catMaybes :: [Maybe a] -> [a]+> catMaybes ms = [ m | Just m <- ms ]+> +> mapMaybe :: (a -> Maybe b) -> [a] -> [b]+> mapMaybe f = catMaybes . map f+-}
+ Data/Ratio.hs view
@@ -0,0 +1,113 @@+module Data.Ratio (+ Ratio+ , Rational+ , (%) -- :: (Integral a) => a -> a -> Ratio a+ , numerator -- :: (Integral a) => Ratio a -> a+ , denominator -- :: (Integral a) => Ratio a -> a+ , approxRational -- :: (RealFrac a) => a -> a -> Rational++ -- * Specification++ -- $code+ ) where+import "base" Data.Ratio++{- $code+> module Data.Ratio (+> Ratio, Rational, (%), numerator, denominator, approxRational ) where+> +> infixl 7 %+> +> ratPrec = 7 :: Int+> +> data (Integral a) => Ratio a = !a :% !a deriving (Eq)+> type Rational = Ratio Integer+> +> (%) :: (Integral a) => a -> a -> Ratio a+> numerator, denominator :: (Integral a) => Ratio a -> a+> approxRational :: (RealFrac a) => a -> a -> Rational+> +> +> -- "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.+> --+> -- E.g., 12 `reduce` 8 == 3 :% 2+> -- 12 `reduce` (-8) == 3 :% (-2)+> +> reduce _ 0 = error "Data.Ratio.% : zero denominator"+> 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+> +> +> instance (Integral a) => Ord (Ratio a) where+> (x:%y) <= (x':%y') = x * y' <= x' * y+> (x:%y) < (x':%y') = x * y' < x' * y+> +> instance (Integral a) => Num (Ratio a) where+> (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:%y) = signum x :% 1+> fromInteger x = fromInteger x :% 1+> +> instance (Integral a) => Real (Ratio a) where+> toRational (x:%y) = toInteger x :% toInteger y+> +> instance (Integral a) => Fractional (Ratio a) where+> (x:%y) / (x':%y') = (x*y') % (y*x')+> recip (x:%y) = y % x+> fromRational (x:%y) = fromInteger x :% fromInteger y+> +> instance (Integral a) => RealFrac (Ratio a) where+> properFraction (x:%y) = (fromIntegral q, r:%y)+> where (q,r) = quotRem x y+> +> instance (Integral a) => Enum (Ratio a) where+> succ x = x+1+> pred x = x-1+> toEnum = fromIntegral+> fromEnum = fromInteger . truncate -- May overflow+> enumFrom = numericEnumFrom -- These numericEnumXXX functions+> enumFromThen = numericEnumFromThen -- are as defined in Prelude.hs+> enumFromTo = numericEnumFromTo -- but not exported from it!+> enumFromThenTo = numericEnumFromThenTo+> +> instance (Read a, Integral a) => Read (Ratio a) where+> readsPrec p = readParen (p > ratPrec)+> (\r -> [(x%y,u) | (x,s) <- readsPrec (ratPrec+1) r,+> ("%",t) <- lex s,+> (y,u) <- readsPrec (ratPrec+1) t ])+> +> instance (Integral a) => Show (Ratio a) where+> showsPrec p (x:%y) = showParen (p > ratPrec)+> showsPrec (ratPrec+1) x . +> showString " % " . +> showsPrec (ratPrec+1) y)+> +> +> +> approxRational x eps = simplest (x-eps) (x+eps)+> where simplest x y | y < x = simplest y x+> | x == y = xr+> | x > 0 = simplest' n d n' d'+> | y < 0 = - simplest' (-n') d' (-n) d+> | otherwise = 0 :% 1+> where xr@(n:%d) = toRational x+> (n':%d') = toRational y+> +> simplest' n d n' d' -- assumes 0 < n%d < n'%d'+> | r == 0 = q :% 1+> | q /= q' = (q+1) :% 1+> | otherwise = (q*n''+d'') :% n''+> where (q,r) = quotRem n d+> (q',r') = quotRem n' d'+> (n'':%d'') = simplest' d' r' d r+-}
+ Data/Word.hs view
@@ -0,0 +1,49 @@+module Data.Word (+ -- * Unsigned integral types++ -- $notes++ Word,+ Word8, Word16, Word32, Word64,++ ) where+import "base" Data.Word++-- SDM: removed after 'Prelude.fromIntegral':+-- ..., which is specialized for all the common cases+-- so should be fast enough++-- SDM: removed: 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.++-- SDM: removed, after "All arithmetic is performed module 2^n...". Neither+-- Ian Lynagh nor I understand what this means:+-- One non-obvious consequence of this is that 'Prelude.negate'+-- should /not/ raise an error on negative arguments.++{- $notes++This module provides unsigned integer types of unspecified width ('Word')+and fixed widths ('Word8', 'Word16', 'Word32' and 'Word64'). All+arithmetic is performed modulo 2^n, where @n@ is the number of bits in+the type.++For coercing between any two integer types, use+'Prelude.fromIntegral'. Coercing word types to and from integer+types preserves representation, not sign.++The rules that hold for 'Prelude.Enum' instances over a bounded type+such as 'Prelude.Int' (see the section of the Haskell language report dealing+with arithmetic sequences) also hold for the 'Prelude.Enum' instances+over the various 'Word' types defined here.++Right and left shifts by amounts greater than or equal to the width of+the type result in a zero result. This is contrary to the behaviour+in C, which is undefined; a common interpretation is to truncate the+shift count to the width of the type, for example @1 \<\< 32 == 1@ in+some C implementations.++-}+
+ Foreign.hs view
@@ -0,0 +1,22 @@+module Foreign (+ -- | The module @Foreign@ combines the interfaces of all+ -- modules providing language-independent marshalling support,+ -- namely+ module Data.Bits+ , module Data.Int+ , module Data.Word+ , module Foreign.Ptr+ , module Foreign.ForeignPtr+ , module Foreign.StablePtr+ , module Foreign.Storable+ , module Foreign.Marshal+ ) where++import "this" Data.Bits+import "this" Data.Int+import "this" Data.Word+import "this" Foreign.Ptr+import "this" Foreign.ForeignPtr+import "this" Foreign.StablePtr+import "this" Foreign.Storable+import "this" Foreign.Marshal
+ Foreign/C.hs view
@@ -0,0 +1,13 @@+module Foreign.C (++ -- | The module "Foreign.C" combines the interfaces of all+ -- modules providing C-specific marshalling support, namely++ module Foreign.C.Types+ , module Foreign.C.String+ , module Foreign.C.Error+ ) where++import "this" Foreign.C.Types+import "this" Foreign.C.String+import "this" Foreign.C.Error
+ Foreign/C/Error.hs view
@@ -0,0 +1,84 @@+-- | The module "Foreign.C.Error" facilitates C-specific error+-- handling of @errno@.+module Foreign.C.Error (++ -- * Haskell representations of @errno@ values++ Errno(..), -- instance: Eq++ -- ** Common @errno@ symbols+ -- | Different operating systems and\/or C libraries often support+ -- 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, + eNOTBLK, eNOTCONN, eNOTDIR, eNOTEMPTY, eNOTSOCK, 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, + eTOOMANYREFS, eTXTBSY, eUSERS, eWOULDBLOCK, eXDEV,++ -- ** 'Errno' functions+ -- :: Errno+ isValidErrno, -- :: Errno -> Bool++ -- access to the current thread's "errno" value+ --+ getErrno, -- :: IO Errno+ resetErrno, -- :: IO ()++ -- conversion of an "errno" value into IO error+ --+ errnoToIOError, -- :: String -- location+ -- -> Errno -- errno+ -- -> Maybe Handle -- handle+ -- -> Maybe String -- filename+ -- -> IOError++ -- throw current "errno" value+ --+ throwErrno, -- :: String -> IO a++ -- ** Guards for IO operations that may fail++ throwErrnoIf, -- :: (a -> Bool) -> String -> IO a -> IO a+ throwErrnoIf_, -- :: (a -> Bool) -> String -> IO a -> IO ()+ throwErrnoIfRetry, -- :: (a -> Bool) -> String -> IO a -> IO a+ throwErrnoIfRetry_, -- :: (a -> Bool) -> String -> IO a -> IO ()+ throwErrnoIfMinus1, -- :: Num a + -- => String -> IO a -> IO a+ throwErrnoIfMinus1_, -- :: Num a + -- => String -> IO a -> IO ()+ throwErrnoIfMinus1Retry,+ -- :: Num a + -- => String -> IO a -> IO a+ throwErrnoIfMinus1Retry_, + -- :: Num a + -- => String -> IO a -> IO ()+ throwErrnoIfNull, -- :: String -> IO (Ptr a) -> IO (Ptr a)+ throwErrnoIfNullRetry,-- :: String -> IO (Ptr a) -> IO (Ptr a)++ throwErrnoIfRetryMayBlock, + throwErrnoIfRetryMayBlock_,+ throwErrnoIfMinus1RetryMayBlock,+ throwErrnoIfMinus1RetryMayBlock_, + throwErrnoIfNullRetryMayBlock,++ throwErrnoPath,+ throwErrnoPathIf,+ throwErrnoPathIf_,+ throwErrnoPathIfNull,+ throwErrnoPathIfMinus1,+ throwErrnoPathIfMinus1_,++ ) where++import "base" Foreign.C.Error
+ Foreign/C/String.hs view
@@ -0,0 +1,83 @@+-- |+-- Utilities for primitive marshalling of C strings.+--+-- The marshalling converts each Haskell character, representing a Unicode+-- code point, to one or more bytes in a manner that, by default, is+-- determined by the current locale. As a consequence, no guarantees+-- can be made about the relative length of a Haskell string and its+-- corresponding C string, and therefore all the marshalling routines+-- include memory allocation. The translation between Unicode and the+-- encoding of the current locale may be lossy.++module Foreign.C.String (++ -- * C strings++ CString, -- = Ptr CChar+ CStringLen, -- = (Ptr CChar, Int)++ -- ** Using a locale-dependent encoding++ -- | Currently these functions are identical to their @CAString@ counterparts;+ -- eventually they will use an encoding determined by the current locale.++ -- conversion of C strings into Haskell strings+ --+ peekCString, -- :: CString -> IO String+ peekCStringLen, -- :: CStringLen -> IO String++ -- conversion of Haskell strings into C strings+ --+ newCString, -- :: String -> IO CString+ newCStringLen, -- :: String -> IO CStringLen++ -- conversion of Haskell strings into C strings using temporary storage+ --+ withCString, -- :: String -> (CString -> IO a) -> IO a+ withCStringLen, -- :: String -> (CStringLen -> IO a) -> IO a++ charIsRepresentable, -- :: Char -> IO Bool++ -- ** Using 8-bit characters++ -- | These variants of the above functions are for use with C libraries+ -- that are ignorant of Unicode. These functions should be used with+ -- care, as a loss of information can occur.++ castCharToCChar, -- :: Char -> CChar+ castCCharToChar, -- :: CChar -> Char++ castCharToCUChar, -- :: Char -> CUChar+ castCUCharToChar, -- :: CUChar -> Char+ castCharToCSChar, -- :: Char -> CSChar+ castCSCharToChar, -- :: CSChar -> Char++ peekCAString, -- :: CString -> IO String+ peekCAStringLen, -- :: CStringLen -> IO String+ newCAString, -- :: String -> IO CString+ newCAStringLen, -- :: String -> IO CStringLen+ withCAString, -- :: String -> (CString -> IO a) -> IO a+ withCAStringLen, -- :: String -> (CStringLen -> IO a) -> IO a++ -- * C wide strings++ -- | These variants of the above functions are for use with C libraries+ -- that encode Unicode using the C @wchar_t@ type in a system-dependent+ -- way. The only encodings supported are+ --+ -- * UTF-32 (the C compiler defines @__STDC_ISO_10646__@), or+ --+ -- * UTF-16 (as used on Windows systems).++ CWString, -- = Ptr CWchar+ CWStringLen, -- = (Ptr CWchar, Int)++ peekCWString, -- :: CWString -> IO String+ peekCWStringLen, -- :: CWStringLen -> IO String+ newCWString, -- :: String -> IO CWString+ newCWStringLen, -- :: String -> IO CWStringLen+ withCWString, -- :: String -> (CWString -> IO a) -> IO a+ withCWStringLen, -- :: String -> (CWStringLen -> IO a) -> IO a++ ) where+import "base" Foreign.C.String
+ Foreign/C/Types.hs view
@@ -0,0 +1,88 @@+module Foreign.C.Types+ ( -- * Representations of C types+ -- $ctypes++ -- ** Integral types+ -- | These types are are represented as @newtype@s of+ -- types in "Data.Int" and "Data.Word", and are instances of+ -- 'Prelude.Eq', 'Prelude.Ord', 'Prelude.Num', 'Prelude.Read',+ -- 'Prelude.Show', 'Prelude.Enum', 'Storable',+ -- 'Prelude.Bounded', 'Prelude.Real', 'Prelude.Integral' and+ -- 'Bits'.+ CChar, CSChar, CUChar+ , CShort, CUShort, CInt, CUInt+ , CLong, CULong+ , CPtrdiff, CSize, CWchar, CSigAtomic+ , CLLong, CULLong+ , CIntPtr, CUIntPtr+ , CIntMax, CUIntMax++ -- ** Numeric types+ -- | These types are are represented as @newtype@s of basic+ -- foreign types, and are instances of+ -- 'Prelude.Eq', 'Prelude.Ord', 'Prelude.Num', 'Prelude.Read',+ -- 'Prelude.Show', 'Prelude.Enum' and 'Storable'.+ , CClock, CTime++ -- ** Floating types+ -- | These types are are represented as @newtype@s of+ -- 'Prelude.Float' and 'Prelude.Double', and are instances of+ -- 'Prelude.Eq', 'Prelude.Ord', 'Prelude.Num', 'Prelude.Read',+ -- 'Prelude.Show', 'Prelude.Enum', 'Storable',+ -- 'Prelude.Real', 'Prelude.Fractional', 'Prelude.Floating',+ -- 'Prelude.RealFrac' and 'Prelude.RealFloat'.+ , CFloat, CDouble+-- GHC doesn't support CLDouble yet+#ifdef HASKELL_REPORT+ , CLDouble+#endif+ -- ** Other types++ -- Instances of: Eq and Storable+ , CFile, CFpos, CJmpBuf++ ) where+import "base" Foreign.C.Types++{- $ctypes++These types are needed to accurately represent C function prototypes,+in order to access C library interfaces in Haskell. The Haskell system+is not required to represent those types exactly as C does, but the+following guarantees are provided concerning a Haskell type @CT@+representing a C type @t@:++* If a C function prototype has @t@ as an argument or result type, the+ use of @CT@ in the corresponding position in a foreign declaration+ permits the Haskell program to access the full range of values encoded+ by the C type; and conversely, any Haskell value for @CT@ has a valid+ representation in C.++* @'sizeOf' ('Prelude.undefined' :: CT)@ will yield the same value as+ @sizeof (t)@ in C.++* @'alignment' ('Prelude.undefined' :: CT)@ matches the alignment+ constraint enforced by the C implementation for @t@.++* The members 'peek' and 'poke' of the 'Storable' class map all values+ of @CT@ to the corresponding value of @t@ and vice versa.++* When an instance of 'Prelude.Bounded' is defined for @CT@, the values+ of 'Prelude.minBound' and 'Prelude.maxBound' coincide with @t_MIN@+ and @t_MAX@ in C.++* When an instance of 'Prelude.Eq' or 'Prelude.Ord' is defined for @CT@,+ the predicates defined by the type class implement the same relation+ as the corresponding predicate in C on @t@.++* When an instance of 'Prelude.Num', 'Prelude.Read', 'Prelude.Integral',+ 'Prelude.Fractional', 'Prelude.Floating', 'Prelude.RealFrac', or+ 'Prelude.RealFloat' is defined for @CT@, the arithmetic operations+ defined by the type class implement the same function as the+ corresponding arithmetic operations (if available) in C on @t@.++* When an instance of 'Bits' is defined for @CT@, the bitwise operation+ defined by the type class implement the same function as the+ corresponding bitwise operation in C on @t@.++-}
+ Foreign/ForeignPtr.hs view
@@ -0,0 +1,71 @@+module Foreign.ForeignPtr (+ -- * Finalised data pointers+ ForeignPtr+ , FinalizerPtr+ , FinalizerEnvPtr++ -- ** Basic operations+ , newForeignPtr+ , newForeignPtr_+ , addForeignPtrFinalizer+ , newForeignPtrEnv+ , addForeignPtrFinalizerEnv+ , withForeignPtr+ , finalizeForeignPtr++ -- ** Low-level operations+ , unsafeForeignPtrToPtr+ , touchForeignPtr+ , castForeignPtr++ -- ** Allocating managed memory+ , mallocForeignPtr+ , mallocForeignPtrBytes+ , mallocForeignPtrArray+ , mallocForeignPtrArray0+ ) where++import qualified "base" Foreign.ForeignPtr as Base+import "base" Foreign.ForeignPtr hiding (mallocForeignPtr, touchForeignPtr)+import "base" Foreign (Storable)++-- SDM: local copy of the docs for mallocForeignPtr, to omit the+-- GHC-specific bits.++mallocForeignPtr :: Storable a => IO (ForeignPtr a)+-- ^ Allocate some memory and return a 'ForeignPtr' to it. The memory+-- will be released automatically when the 'ForeignPtr' is discarded.+--+-- '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'.+mallocForeignPtr = Base.mallocForeignPtr++-- SDM: reproduced documentation for touchForeignPtr without reference+-- to Haskell finalizers and MVars.++touchForeignPtr :: ForeignPtr a -> IO ()+-- ^This function ensures that the foreign object in+-- question is alive at the given place in the sequence of IO+-- 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+-- 'ForeignPtr' @F2@, then the only guarantee is that the finalizer+-- for @F2@ is never started before the finalizer for @F1@. They+-- might be started together if for example both @F1@ and @F2@ are+-- otherwise unreachable.+--+-- In general, it is not recommended to use finalizers on separate+-- objects with ordering constraints between them. To express the+-- ordering robustly requires explicit synchronisation between+-- finalizers.+--+touchForeignPtr = Base.touchForeignPtr
+ Foreign/Marshal.hs view
@@ -0,0 +1,43 @@+module Foreign.Marshal (+ -- | The module "Foreign.Marshal" re-exports the other modules in the+ -- @Foreign.Marshal@ hierarchy:++ module Foreign.Marshal.Alloc,+ module Foreign.Marshal.Array,+ module Foreign.Marshal.Error,+ -- Not in Haskell 2010:+ -- , module Foreign.Marshal.Pool+ module Foreign.Marshal.Utils,+ -- | and provides one function:+ unsafeLocalState+ ) where++import "this" Foreign.Marshal.Alloc+import "this" Foreign.Marshal.Array+import "this" Foreign.Marshal.Error+-- Not in Haskell 2010:+-- import "this" Foreign.Marshal.Pool+import "this" Foreign.Marshal.Utils++import "base" System.IO.Unsafe++{- |+Sometimes an external entity is a pure function, except that it passes+arguments and/or results via pointers. The function+@unsafeLocalState@ permits the packaging of such entities as pure+functions. ++The only IO operations allowed in the IO action passed to+@unsafeLocalState@ are (a) local allocation (@alloca@, @allocaBytes@+and derived operations such as @withArray@ and @withCString@), and (b)+pointer operations (@Foreign.Storable@ and @Foreign.Ptr@) on the+pointers to local storage, and (c) foreign functions whose only+observable effect is to read and/or write the locally allocated+memory. Passing an IO operation that does not obey these rules+results in undefined behaviour.++It is expected that this operation will be+replaced in a future revision of Haskell.+-}+unsafeLocalState :: IO a -> a+unsafeLocalState = unsafePerformIO
+ Foreign/Marshal/Alloc.hs view
@@ -0,0 +1,42 @@+{- |+The module "Foreign.Marshal.Alloc" provides operations to allocate and+deallocate blocks of raw memory (i.e., unstructured chunks of memory+outside of the area maintained by the Haskell storage manager). These+memory blocks are commonly used to pass compound data structures to+foreign functions or to provide space in which compound result values+are obtained from foreign functions.++If any of the allocation functions fails, a value of 'nullPtr' is+produced. If 'free' or 'reallocBytes' is applied to a memory area+that has been allocated with 'alloca' or 'allocaBytes', the+behaviour is undefined. Any further access to memory areas allocated with+'alloca' or 'allocaBytes', after the computation that was passed to+the allocation function has terminated, leads to undefined behaviour. Any+further access to the memory area referenced by a pointer passed to+'realloc', 'reallocBytes', or 'free' entails undefined+behaviour.++All storage allocated by functions that allocate based on a /size in bytes/+must be sufficiently aligned for any of the basic foreign types+that fits into the newly allocated storage. All storage allocated by+functions that allocate based on a specific type must be sufficiently+aligned for that type. Array allocation routines need to obey the same+alignment constraints for each array element.+-}+module Foreign.Marshal.Alloc (+ -- * Memory allocation+ -- ** Local allocation+ alloca, -- :: Storable a => (Ptr a -> IO b) -> IO b+ allocaBytes, -- :: Int -> (Ptr a -> IO b) -> IO b++ -- ** Dynamic allocation+ malloc, -- :: Storable a => IO (Ptr a)+ mallocBytes, -- :: Int -> IO (Ptr a)++ realloc, -- :: Storable b => Ptr a -> IO (Ptr b)+ reallocBytes, -- :: Ptr a -> Int -> IO (Ptr a)++ free, -- :: Ptr a -> IO ()+ finalizerFree -- :: FinalizerPtr a+ ) where+import "base" Foreign.Marshal.Alloc
+ Foreign/Marshal/Array.hs view
@@ -0,0 +1,69 @@+{- |+The module "Foreign.Marshal.Array" provides operations for marshalling Haskell+lists into monolithic arrays and vice versa. Most functions come in two+flavours: one for arrays terminated by a special termination element and one+where an explicit length parameter is used to determine the extent of an+array. The typical example for the former case are C's NUL terminated+strings. However, please note that C strings should usually be marshalled+using the functions provided by "Foreign.C.String" as+the Unicode encoding has to be taken into account. All functions specifically+operating on arrays that are terminated by a special termination element have+a name ending on @0@---e.g., 'mallocArray' allocates space for an+array of the given size, whereas 'mallocArray0' allocates space for one+more element to ensure that there is room for the terminator.+-}+module Foreign.Marshal.Array (+ -- * Marshalling arrays++ -- ** Allocation+ --+ mallocArray, -- :: Storable a => Int -> IO (Ptr a)+ mallocArray0, -- :: Storable a => Int -> IO (Ptr a)++ allocaArray, -- :: Storable a => Int -> (Ptr a -> IO b) -> IO b+ allocaArray0, -- :: Storable a => Int -> (Ptr a -> IO b) -> IO b++ reallocArray, -- :: Storable a => Ptr a -> Int -> IO (Ptr a)+ reallocArray0, -- :: Storable a => Ptr a -> Int -> IO (Ptr a)++ -- ** Marshalling+ --+ peekArray, -- :: Storable a => Int -> Ptr a -> IO [a]+ peekArray0, -- :: (Storable a, Eq a) => a -> Ptr a -> IO [a]++ pokeArray, -- :: Storable a => Ptr a -> [a] -> IO ()+ pokeArray0, -- :: Storable a => a -> Ptr a -> [a] -> IO ()++ -- ** Combined allocation and marshalling+ --+ newArray, -- :: Storable a => [a] -> IO (Ptr a)+ newArray0, -- :: Storable a => a -> [a] -> IO (Ptr a)++ withArray, -- :: Storable a => [a] -> (Ptr a -> IO b) -> IO b+ withArray0, -- :: Storable a => a -> [a] -> (Ptr a -> IO b) -> IO b++ withArrayLen, -- :: Storable a => [a] -> (Int -> Ptr a -> IO b) -> IO b+ withArrayLen0, -- :: Storable a => a -> [a] -> (Int -> Ptr a -> IO b) -> IO b++ -- ** Copying++ -- | (argument order: destination, source)+ copyArray, -- :: Storable a => Ptr a -> Ptr a -> Int -> IO ()+ moveArray, -- :: Storable a => Ptr a -> Ptr a -> Int -> IO ()++ -- ** Finding the length+ --+ lengthArray0, -- :: (Storable a, Eq a) => a -> Ptr a -> IO Int++ -- ** Indexing+ --+ advancePtr, -- :: Storable a => Ptr a -> Int -> Ptr a+ ) where+import qualified "base" Foreign.Marshal.Array as Base+import "base" Foreign.Marshal.Array hiding (peekArray)+import "base" Foreign hiding (peekArray)++-- |Convert an array of given length into a Haskell list.+--+peekArray :: Storable a => Int -> Ptr a -> IO [a]+peekArray = Base.peekArray
+ Foreign/Marshal/Error.hs view
@@ -0,0 +1,15 @@+module Foreign.Marshal.Error (+ throwIf, -- :: (a -> Bool) -> (a -> String) -> IO a -> IO a+ throwIf_, -- :: (a -> Bool) -> (a -> String) -> IO a -> IO ()+ throwIfNeg, -- :: (Ord a, Num a) + -- => (a -> String) -> IO a -> IO a+ throwIfNeg_, -- :: (Ord a, Num a)+ -- => (a -> String) -> IO a -> IO ()+ throwIfNull, -- :: String -> IO (Ptr a) -> IO (Ptr a)++ -- Discard return value+ --+ void -- IO a -> IO ()++ ) where+import "base" Foreign.Marshal.Error
+ Foreign/Marshal/Utils.hs view
@@ -0,0 +1,34 @@+module Foreign.Marshal.Utils (+ -- * General marshalling utilities++ -- ** Combined allocation and marshalling+ --+ with, -- :: Storable a => a -> (Ptr a -> IO b) -> IO b+ new, -- :: Storable a => a -> IO (Ptr a)++ -- ** Marshalling of Boolean values (non-zero corresponds to 'True')+ --+ fromBool, -- :: Num a => Bool -> a+ toBool, -- :: Num a => a -> Bool++ -- ** Marshalling of Maybe values+ --+ maybeNew, -- :: ( a -> IO (Ptr a))+ -- -> (Maybe a -> IO (Ptr a))+ maybeWith, -- :: ( a -> (Ptr b -> IO c) -> IO c)+ -- -> (Maybe a -> (Ptr b -> IO c) -> IO c)+ maybePeek, -- :: (Ptr a -> IO b )+ -- -> (Ptr a -> IO (Maybe b))++ -- ** Marshalling lists of storable objects+ --+ withMany, -- :: (a -> (b -> res) -> res) -> [a] -> ([b] -> res) -> res++ -- ** Haskellish interface to memcpy and memmove+ -- | (argument order: destination, source)+ --+ copyBytes, -- :: Ptr a -> Ptr a -> Int -> IO ()+ moveBytes, -- :: Ptr a -> Ptr a -> Int -> IO ()++ ) where+import "base" Foreign.Marshal.Utils
+ Foreign/Ptr.hs view
@@ -0,0 +1,38 @@+-- | The module "Foreign.Ptr" provides typed pointers to foreign+-- entities. We distinguish two kinds of pointers: pointers to data+-- and pointers to functions. It is understood that these two kinds+-- of pointers may be represented differently as they may be+-- references to data and text segments, respectively.++module Foreign.Ptr (++ -- * Data pointers++ Ptr, -- data Ptr a+ nullPtr, -- :: Ptr a+ castPtr, -- :: Ptr a -> Ptr b+ plusPtr, -- :: Ptr a -> Int -> Ptr b+ alignPtr, -- :: Ptr a -> Int -> Ptr a+ minusPtr, -- :: Ptr a -> Ptr b -> Int++ -- * Function pointers++ FunPtr, -- data FunPtr a+ nullFunPtr, -- :: FunPtr a+ castFunPtr, -- :: FunPtr a -> FunPtr b+ castFunPtrToPtr, -- :: FunPtr a -> Ptr b+ castPtrToFunPtr, -- :: Ptr a -> FunPtr b++ freeHaskellFunPtr, -- :: FunPtr a -> IO ()+ -- Free the function pointer created by foreign export dynamic.++ -- * Integral types with lossless conversion to and from pointers+ IntPtr,+ ptrToIntPtr,+ intPtrToPtr,+ WordPtr,+ ptrToWordPtr,+ wordPtrToPtr++ ) where+import "base" Foreign.Ptr
+ Foreign/StablePtr.hs view
@@ -0,0 +1,26 @@+module Foreign.StablePtr+ ( -- * Stable references to Haskell values+ StablePtr -- abstract+ , newStablePtr -- :: a -> IO (StablePtr a)+ , deRefStablePtr -- :: StablePtr a -> IO a+ , freeStablePtr -- :: StablePtr a -> IO ()+ , castStablePtrToPtr -- :: StablePtr a -> Ptr ()+ , castPtrToStablePtr -- :: Ptr () -> StablePtr a+ , -- ** The C-side interface++ -- $cinterface+ ) where+import "base" Foreign.StablePtr as This___++-- $cinterface+--+-- The following definition is available to C programs inter-operating with+-- Haskell code when including the header @HsFFI.h@.+--+-- > typedef void *HsStablePtr; /* C representation of a StablePtr */+--+-- Note that no assumptions may be made about the values representing stable+-- pointers. In fact, they need not even be valid memory addresses. The only+-- guarantee provided is that if they are passed back to Haskell land, the+-- function 'deRefStablePtr' will be able to reconstruct the+-- Haskell value referred to by the stable pointer.
+ Foreign/Storable.hs view
@@ -0,0 +1,12 @@+module Foreign.Storable+ ( Storable(+ sizeOf, -- :: a -> Int+ alignment, -- :: a -> Int+ peekElemOff, -- :: Ptr a -> Int -> IO a+ pokeElemOff, -- :: Ptr a -> Int -> a -> IO ()+ peekByteOff, -- :: Ptr b -> Int -> IO a+ pokeByteOff, -- :: Ptr b -> Int -> a -> IO ()+ peek, -- :: Ptr a -> IO a+ poke) -- :: Ptr a -> a -> IO ()+ ) where+import "base" Foreign.Storable
+ LICENSE view
@@ -0,0 +1,12 @@+Code derived from the document "Report on the Programming Language+Haskell 2010", is distributed under the following license:++ Copyright (c) 2010 Simon Marlow++ The authors intend this Report to belong to the entire Haskell+ community, and so we grant permission to copy and distribute it for+ any purpose, provided that it is reproduced in its entirety,+ including this Notice. Modified versions of this Report may also be+ copied and distributed for any purpose, provided that the modified+ version is clearly presented as such, and that it does not claim to+ be a definition of the Haskell 2010 Language.
+ Numeric.hs view
@@ -0,0 +1,43 @@+module Numeric (++ -- * Showing++ showSigned, -- :: (Real a) => (a -> ShowS) -> Int -> a -> ShowS++ showIntAtBase, -- :: Integral a => a -> (a -> Char) -> a -> ShowS+ showInt, -- :: Integral a => a -> ShowS+ showHex, -- :: Integral a => a -> ShowS+ showOct, -- :: Integral a => a -> ShowS++ showEFloat, -- :: (RealFloat a) => Maybe Int -> a -> ShowS+ showFFloat, -- :: (RealFloat a) => Maybe Int -> a -> ShowS+ showGFloat, -- :: (RealFloat a) => Maybe Int -> a -> ShowS+ showFloat, -- :: (RealFloat a) => a -> ShowS++ floatToDigits, -- :: (RealFloat a) => Integer -> a -> ([Int], Int)++ -- * Reading++ -- | /NB:/ 'readInt' is the \'dual\' of 'showIntAtBase',+ -- and 'readDec' is the \`dual\' of 'showInt'.+ -- The inconsistent naming is a historical accident.++ readSigned, -- :: (Real a) => ReadS a -> ReadS a++ readInt, -- :: (Integral a) => a -> (Char -> Bool)+ -- -> (Char -> Int) -> ReadS a+ readDec, -- :: (Integral a) => ReadS a+ readOct, -- :: (Integral a) => ReadS a+ readHex, -- :: (Integral a) => ReadS a++ readFloat, -- :: (RealFloat a) => ReadS a++ lexDigits, -- :: ReadS String++ -- * Miscellaneous++ fromRat, -- :: (RealFloat a) => Rational -> a++ ) where++import "base" Numeric
+ Prelude.hs view
@@ -0,0 +1,183 @@+{-# OPTIONS_GHC -XNoImplicitPrelude -XBangPatterns #-}+-- |+-- The Haskell 2010 Prelude: a standard module imported by default+-- into all Haskell modules. For more documentation, see the Haskell 2010+-- Report <http://www.haskell.org/onlinereport/>.++module Prelude (++ -- * Standard types, classes and related functions++ -- ** Basic data types+ Bool(False, True),+ (&&), (||), not, otherwise,++ Maybe(Nothing, Just),+ maybe,++ Either(Left, Right),+ either,++ Ordering(LT, EQ, GT),+ Char, String,++ -- *** Tuples+ fst, snd, curry, uncurry,++#if defined(__NHC__)+ []((:), []), -- Not legal Haskell 98;+ -- ... available through built-in syntax+ module Data.Tuple, -- Includes tuple types+ ()(..), -- Not legal Haskell 98+ (->), -- ... available through built-in syntax+#endif+#ifdef __HUGS__+ (:), -- Not legal Haskell 98+#endif++ -- ** Basic type classes+ Eq((==), (/=)),+ Ord(compare, (<), (<=), (>=), (>), max, min),+ Enum(succ, pred, toEnum, fromEnum, enumFrom, enumFromThen,+ enumFromTo, enumFromThenTo),+ Bounded(minBound, maxBound),++ -- ** Numbers++ -- *** Numeric types+ Int, Integer, Float, Double,+ Rational,++ -- *** Numeric type classes+ Num((+), (-), (*), negate, abs, signum, fromInteger),+ Real(toRational),+ Integral(quot, rem, div, mod, quotRem, divMod, toInteger),+ Fractional((/), recip, fromRational),+ Floating(pi, exp, log, sqrt, (**), logBase, sin, cos, tan,+ asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh),+ RealFrac(properFraction, truncate, round, ceiling, floor),+ RealFloat(floatRadix, floatDigits, floatRange, decodeFloat,+ encodeFloat, exponent, significand, scaleFloat, isNaN,+ isInfinite, isDenormalized, isIEEE, isNegativeZero, atan2),++ -- *** Numeric functions+ subtract, even, odd, gcd, lcm, (^), (^^),+ fromIntegral, realToFrac,++ -- ** Monads and functors+ Monad((>>=), (>>), return, fail),+ Functor(fmap),+ mapM, mapM_, sequence, sequence_, (=<<),++ -- ** Miscellaneous functions+ id, const, (.), flip, ($), until,+ asTypeOf, error, undefined,+ seq, ($!),++ -- * List operations+ 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,+ -- *** Infinite lists+ iterate, repeat, replicate, cycle,+ -- ** Sublists+ take, drop, splitAt, takeWhile, dropWhile, span, break,+ -- ** Searching lists+ elem, notElem, lookup,+ -- ** Zipping and unzipping lists+ zip, zip3, zipWith, zipWith3, unzip, unzip3,+ -- ** Functions on strings+ lines, words, unlines, unwords,++ -- * Converting to and from @String@+ -- ** Converting to @String@+ ShowS,+ Show(showsPrec, showList, show),+ shows,+ showChar, showString, showParen,+ -- ** Converting from @String@+ ReadS,+ Read(readsPrec, readList),+ reads, readParen, read, lex,++ -- * Basic Input and output+ IO,+ -- ** Simple I\/O operations+ -- All I/O functions defined here are character oriented. The+ -- treatment of the newline character will vary on different systems.+ -- For example, two characters of input, return and linefeed, may+ -- read as a single newline character. These functions cannot be+ -- used portably for binary I/O.+ -- *** Output functions+ putChar,+ putStr, putStrLn, print,+ -- *** Input functions+ getChar,+ getLine, getContents, interact,+ -- *** Files+ FilePath,+ readFile, writeFile, appendFile, readIO, readLn,+ -- ** Exception handling in the I\/O monad+ IOError, ioError, userError, catch++ ) where++#ifndef __HUGS__+import "base" Control.Monad+import "base" System.IO+import "base" System.IO.Error+import "base" Data.List+import "base" Data.Either+import "base" Data.Maybe+import "base" Data.Tuple+#endif++#ifdef __GLASGOW_HASKELL__+import GHC.Base+-- import GHC.IO+-- import GHC.IO.Exception+import Text.Read+import GHC.Enum+import GHC.Num+import GHC.Real+import GHC.Float+import GHC.Show+import GHC.Err ( undefined )+#endif++#ifdef __HUGS__+import Hugs.Prelude+#endif++#ifndef __HUGS__+infixr 0 $!+#endif++-- -----------------------------------------------------------------------------+-- Miscellaneous functions++-- | Strict (call-by-value) application, defined in terms of 'seq'.+($!) :: (a -> b) -> a -> b+#ifdef __GLASGOW_HASKELL__+f $! x = let !vx = x in f vx -- see #2273+#elif !defined(__HUGS__)+f $! x = x `seq` f x+#endif++#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
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ System/Environment.hs view
@@ -0,0 +1,6 @@+module System.Environment (+ getArgs, -- :: IO [String]+ getProgName, -- :: IO String+ getEnv, -- :: String -> IO String+ ) where+import "base" System.Environment
+ System/Exit.hs view
@@ -0,0 +1,39 @@+module System.Exit (+ ExitCode(ExitSuccess,ExitFailure)+ , exitWith -- :: ExitCode -> IO a+ , exitFailure -- :: IO a+ , exitSuccess -- :: IO a+ ) where+import "base" System.Exit hiding (exitWith)+import qualified "base" System.Exit as Base++-- SDM: use the Haskell 98 docs for exitWith, since the base docs talk+-- about exceptions which aren't in Haskell 2010.++-- SDM: removed:+-- Before the program terminates, any open or semi-closed handles are+-- first closed.++-- SDM: removed:+-- If a program terminates as a result of calling @error@\indextt{error} or+-- because its value is otherwise determined to be "\bot"\index{"\bot"}, then it+-- is treated identically to the computation @exitFailure@. Otherwise, if any+-- program "p" terminates without calling @exitWith@ explicitly, it is treated+-- identically to the computation+-- \bprog+-- @(@"p"@ >> exitWith ExitSuccess) `catch` \ _ -> exitFailure@+-- \eprog++{- |+Computation @'exitWith' code@ terminates the program, returning @code@+to the program's caller. +The caller may interpret the return code as it wishes, but the program+should return 'ExitSuccess' to mean normal completion, and+@'ExitFailure' n@ to mean that the program encountered a problem from+which it could not recover. The value 'exitFailure' is equal to+@'exitWith' ('ExitFailure' exitfail)@, where @exitfail@ is+implementation-dependent. 'exitWith' bypasses the error handling in+the I/O monad and cannot be intercepted by 'catch' from the @Prelude@.+-}+exitWith :: ExitCode -> IO a+exitWith = Base.exitWith
+ System/IO.hs view
@@ -0,0 +1,204 @@+module System.IO (+ -- * The IO monad++ IO, -- instance MonadFix+ fixIO, -- :: (a -> IO a) -> IO a++ -- * Files and handles++ FilePath, -- :: String++ Handle, -- abstract, instance of: Eq, Show.++ -- ** Standard handles++ -- | Three handles are allocated during program initialisation,+ -- and are initially open.++ stdin, stdout, stderr, -- :: Handle++ -- * Opening and closing files++ -- ** Opening files++ withFile,+ openFile, -- :: FilePath -> IOMode -> IO Handle+ IOMode(ReadMode,WriteMode,AppendMode,ReadWriteMode),++ -- ** Closing files++ hClose, -- :: Handle -> IO ()++ -- ** Special cases++ -- | These functions are also exported by the "Prelude".++ readFile, -- :: FilePath -> IO String+ writeFile, -- :: FilePath -> String -> IO ()+ appendFile, -- :: FilePath -> String -> IO ()++ -- ** File locking++ -- $locking++ -- * Operations on handles++ -- ** Determining and changing the size of a file++ hFileSize, -- :: Handle -> IO Integer+ hSetFileSize, -- :: Handle -> Integer -> IO ()++ -- ** Detecting the end of input++ hIsEOF, -- :: Handle -> IO Bool+ isEOF, -- :: IO Bool++ -- ** Buffering operations++ BufferMode(NoBuffering,LineBuffering,BlockBuffering),+ hSetBuffering, -- :: Handle -> BufferMode -> IO ()+ hGetBuffering, -- :: Handle -> IO BufferMode+ hFlush, -- :: Handle -> IO ()++ -- ** Repositioning handles++ hGetPosn, -- :: Handle -> IO HandlePosn+ hSetPosn, -- :: HandlePosn -> IO ()+ HandlePosn, -- abstract, instance of: Eq, Show.++ hSeek, -- :: Handle -> SeekMode -> Integer -> IO ()+ SeekMode(AbsoluteSeek,RelativeSeek,SeekFromEnd),+ hTell, -- :: Handle -> IO Integer++ -- ** Handle properties++ -- | Each of these operations returns 'True' if the handle has the+ -- the specified property, or 'False' otherwise.++ hIsOpen, hIsClosed, -- :: Handle -> IO Bool+ hIsReadable, hIsWritable, -- :: Handle -> IO Bool+ hIsSeekable, -- :: Handle -> IO Bool++ -- ** Terminal operations++ hIsTerminalDevice, -- :: Handle -> IO Bool++ hSetEcho, -- :: Handle -> Bool -> IO ()+ hGetEcho, -- :: Handle -> IO Bool++ -- ** Showing handle state+ hShow, -- :: Handle -> IO String++ -- * Text input and output++ -- ** Text input++ hWaitForInput, -- :: Handle -> Int -> IO Bool+ hReady, -- :: Handle -> IO Bool+ hGetChar, -- :: Handle -> IO Char+ hGetLine, -- :: Handle -> IO [Char]+ hLookAhead, -- :: Handle -> IO Char+ hGetContents, -- :: Handle -> IO [Char]++ -- ** Text output++ hPutChar, -- :: Handle -> Char -> IO ()+ hPutStr, -- :: Handle -> [Char] -> IO ()+ hPutStrLn, -- :: Handle -> [Char] -> IO ()+ hPrint, -- :: Show a => Handle -> a -> IO ()++ -- ** Special cases for standard input and output++ -- | These functions are also exported by the "Prelude".++ interact, -- :: (String -> String) -> IO ()+ putChar, -- :: Char -> IO ()+ putStr, -- :: String -> IO () + putStrLn, -- :: String -> IO ()+ print, -- :: Show a => a -> IO ()+ getChar, -- :: IO Char+ getLine, -- :: IO String+ getContents, -- :: IO String+ readIO, -- :: Read a => String -> IO a+ readLn, -- :: Read a => IO a++ ) where++import "base" System.IO hiding (openFile, hWaitForInput)+import qualified "base" System.IO as Base++-- $locking+-- Implementations should enforce as far as possible, at least locally to the+-- Haskell process, multiple-reader single-writer locking on files.+-- That is, /there may either be many handles on the same file which manage input, or just one handle on the file which manages output/. If any+-- open or semi-closed handle is managing a file for output, no new+-- handle can be allocated for that file. If any open or semi-closed+-- handle is managing a file for input, new handles can only be allocated+-- if they do not manage output. Whether two files are the same is+-- implementation-dependent, but they should normally be the same if they+-- have the same absolute path name and neither has been renamed, for+-- example.+--+-- /Warning/: the 'readFile' operation holds a semi-closed handle on+-- the file until the entire contents of the file have been consumed.+-- It follows that an attempt to write to a file (using 'writeFile', for+-- example) that was earlier opened by 'readFile' will usually result in+-- failure with 'System.IO.Error.isAlreadyInUseError'.+++-- SDM: custom verison of openFile docs removing reference to 'openBinaryFile'++-- | Computation 'openFile' @file mode@ allocates and returns a new, open+-- handle to manage the file @file@. It manages input if @mode@+-- is 'ReadMode', output if @mode@ is 'WriteMode' or 'AppendMode',+-- and both input and output if mode is 'ReadWriteMode'.+--+-- If the file does not exist and it is opened for output, it should be+-- created as a new file. If @mode@ is 'WriteMode' and the file+-- already exists, then it should be truncated to zero length.+-- Some operating systems delete empty files, so there is no guarantee+-- that the file will exist following an 'openFile' with @mode@+-- 'WriteMode' unless it is subsequently written to successfully.+-- The handle is positioned at the end of the file if @mode@ is+-- 'AppendMode', and otherwise at the beginning (in which case its+-- internal position is 0).+-- The initial buffer mode is implementation-dependent.+--+-- This operation may fail with:+--+-- * 'isAlreadyInUseError' if the file is already open and cannot be reopened;+--+-- * 'isDoesNotExistError' if the file does not exist; or+--+-- * 'isPermissionError' if the user does not have permission to open the file.+--+openFile :: FilePath -> IOMode -> IO Handle+openFile = Base.openFile++-- SDM: local version of docs for hWaitForInput, omitting GHC-specific notes.++-- If hWaitForInput finds anything in the Handle's buffer, it+-- immediately returns. If not, it tries to read from the underlying+-- OS handle. Notice that for buffered Handles connected to terminals+-- this means waiting until a complete line is available.++-- | Computation 'hWaitForInput' @hdl t@+-- waits until input is available on handle @hdl@.+-- It returns 'True' as soon as input is available on @hdl@,+-- or 'False' if no input is available within @t@ milliseconds. Note that+-- 'hWaitForInput' waits until one or more full /characters/ are available,+-- which means that it needs to do decoding, and hence may fail+-- with a decoding error.+--+-- If @t@ is less than zero, then @hWaitForInput@ waits indefinitely.+--+-- This operation may fail with:+--+-- * 'isEOFError' if the end of file has been reached.+--+-- * a decoding error, if the input begins with an invalid byte sequence+-- in this Handle's encoding.+--++hWaitForInput :: Handle -> Int -> IO Bool+hWaitForInput = Base.hWaitForInput
+ System/IO/Error.hs view
@@ -0,0 +1,86 @@+{-# OPTIONS_GHC -fno-warn-unused-imports #-}+-- apparent bug in GHC, reports a bogus warning for the Prelude import below+module System.IO.Error (+ -- * I\/O errors+ IOError, -- = IOException++ userError, -- :: String -> IOError++ mkIOError, -- :: IOErrorType -> String -> Maybe Handle+ -- -> Maybe FilePath -> IOError++ annotateIOError, -- :: IOError -> String -> Maybe Handle+ -- -> Maybe FilePath -> IOError++ -- ** Classifying I\/O errors+ isAlreadyExistsError, -- :: IOError -> Bool+ isDoesNotExistError,+ isAlreadyInUseError,+ isFullError, + isEOFError,+ isIllegalOperation, + isPermissionError,+ isUserError,++ -- ** Attributes of I\/O errors+ ioeGetErrorString, -- :: IOError -> String+ ioeGetHandle, -- :: IOError -> Maybe Handle+ ioeGetFileName, -- :: IOError -> Maybe FilePath++ -- * Types of I\/O error+ IOErrorType, -- abstract++ alreadyExistsErrorType, -- :: IOErrorType+ doesNotExistErrorType,+ alreadyInUseErrorType,+ fullErrorType,+ eofErrorType,+ illegalOperationErrorType, + permissionErrorType,+ userErrorType,++ -- * Throwing and catching I\/O errors++ ioError, -- :: IOError -> IO a++ catch, -- :: IO a -> (IOError -> IO a) -> IO a+ try -- :: IO a -> IO (Either IOError a)++ ) where++import "base" System.IO.Error hiding (IOError,catch,try)+import qualified "base" System.IO.Error as Base+import Prelude hiding (IOError,catch)++-- | Errors of type 'IOError' are used by the 'IO' monad. This is an+-- abstract type; the module "System.IO.Error" provides functions to+-- interrogate and construct values of type 'IOError'.+type IOError = Base.IOError++-- SDM: duplicated docs for catch and try, omitting the part about non-IO+-- exceptions.++-- | The 'catch' function establishes a handler that receives any 'IOError'+-- raised in the action protected by 'catch'. An 'IOError' is caught by+-- the most recent handler established by 'catch'. These handlers are+-- not selective: all 'IOError's are caught. Exception propagation+-- must be explicitly provided in a handler by re-raising any unwanted+-- exceptions. For example, in+--+-- > f = catch g (\e -> if IO.isEOFError e then return [] else ioError e)+--+-- the function @f@ returns @[]@ when an end-of-file exception+-- (cf. 'System.IO.Error.isEOFError') occurs in @g@; otherwise, the+-- exception is propagated to the next outer handler.+--+-- When an exception propagates outside the main program, the Haskell+-- system prints the associated 'IOError' value and exits the program.+--+catch :: IO a -> (IOError -> IO a) -> IO a+catch = Base.catch++-- | The construct 'try' @comp@ exposes IO errors which occur within a+-- computation, and which are not fully handled.+--+try :: IO a -> IO (Either IOError a)+try = Base.try
+ haskell2010.cabal view
@@ -0,0 +1,68 @@+name: haskell2010+version: 1.0.0.0+license: BSD3+license-file: LICENSE+maintainer: libraries@haskell.org+bug-reports: http://hackage.haskell.org/trac/ghc/newticket?component=libraries/haskell2010+synopsis: Compatibility with Haskell 2010+category: Haskell2010+description:+ This package provides exactly the library modules defined by+ the Haskell 2010 standard.+homepage: http://www.haskell.org/definition/+build-type: Simple+Cabal-Version: >= 1.6++Library+ build-depends: base >= 4.3 && < 5, array++ -- this hack adds a dependency on ghc-prim for Haddock. The GHC+ -- build system doesn't seem to track transitive dependencies when+ -- running Haddock, and if we don't do this then Haddock can't+ -- find the docs for things defined in ghc-prim.+ if impl(ghc) {+ build-depends: ghc-prim+ }++ exposed-modules:+ Data.Array,+ Data.Char,+ Data.Complex,+ System.IO,+ System.IO.Error,+ Data.Ix,+ Data.List,+ Data.Maybe,+ Control.Monad,+ Data.Ratio,+ System.Environment,+ System.Exit,+ Numeric,+ Prelude,++ -- FFI modules+ Data.Int,+ Data.Word,+ Data.Bits,++ Foreign,+ Foreign.Ptr,+ Foreign.ForeignPtr,+ Foreign.StablePtr,+ Foreign.Storable,+ Foreign.C,+ Foreign.C.Error,+ Foreign.C.String,+ Foreign.C.Types,+ Foreign.Marshal,+ Foreign.Marshal.Alloc,+ Foreign.Marshal.Array,+ Foreign.Marshal.Error,+ Foreign.Marshal.Utils+ exposed: False+ extensions: PackageImports, CPP++source-repository head+ type: darcs+ location: http://darcs.haskell.org/packages/haskell2010/+