From: Don Stewart Date: Mon, 10 Mar 2008 00:54:55 +0000 (+0000) Subject: untabify X-Git-Tag: 2008-05-28~33 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=b4e1c2c5b2c00dd415b19ddbfb2bf950e6c4e61c;hp=ae5ae0b98d49556f26b5813b92f3e886076dd13c;p=ghc-base.git untabify --- diff --git a/Control/Monad/ST/Lazy.hs b/Control/Monad/ST/Lazy.hs index 5bf1265..00aa4f0 100644 --- a/Control/Monad/ST/Lazy.hs +++ b/Control/Monad/ST/Lazy.hs @@ -15,21 +15,21 @@ ----------------------------------------------------------------------------- module Control.Monad.ST.Lazy ( - -- * The 'ST' monad - ST, - runST, - fixST, + -- * The 'ST' monad + ST, + runST, + fixST, - -- * Converting between strict and lazy 'ST' - strictToLazyST, lazyToStrictST, + -- * Converting between strict and lazy 'ST' + strictToLazyST, lazyToStrictST, - -- * Converting 'ST' To 'IO' - RealWorld, - stToIO, + -- * Converting 'ST' To 'IO' + RealWorld, + stToIO, - -- * Unsafe operations - unsafeInterleaveST, - unsafeIOToST + -- * Unsafe operations + unsafeInterleaveST, + unsafeIOToST ) where import Prelude @@ -80,7 +80,7 @@ instance Monad (ST s) where return a = ST $ \ s -> (a,s) m >> k = m >>= \ _ -> k - fail s = error s + fail s = error s (ST m) >>= k = ST $ \ s -> @@ -102,15 +102,15 @@ runST st = case st of ST the_st -> let (r,_) = the_st (S# realWorld#) in r -- Note that if @f@ is strict, @'fixST' f = _|_@. fixST :: (a -> ST s a) -> ST s a fixST m = ST (\ s -> - let - ST m_r = m r - (r,s') = m_r s - in - (r,s')) + let + ST m_r = m r + (r,s') = m_r s + in + (r,s')) #endif instance MonadFix (ST s) where - mfix = fixST + mfix = fixST -- --------------------------------------------------------------------------- -- Strict <--> Lazy @@ -124,11 +124,11 @@ the lazy state thread it returns is demanded. strictToLazyST :: ST.ST s a -> ST s a strictToLazyST m = ST $ \s -> let - pr = case s of { S# s# -> GHC.ST.liftST m s# } - r = case pr of { GHC.ST.STret _ v -> v } - s' = case pr of { GHC.ST.STret s2# _ -> S# s2# } - in - (r, s') + pr = case s of { S# s# -> GHC.ST.liftST m s# } + r = case pr of { GHC.ST.STret _ v -> v } + s' = case pr of { GHC.ST.STret s2# _ -> S# s2# } + in + (r, s') {-| Convert a lazy 'ST' computation into a strict one. diff --git a/Control/Monad/ST/Strict.hs b/Control/Monad/ST/Strict.hs index c492766..a899616 100644 --- a/Control/Monad/ST/Strict.hs +++ b/Control/Monad/ST/Strict.hs @@ -13,7 +13,7 @@ ----------------------------------------------------------------------------- module Control.Monad.ST.Strict ( - module Control.Monad.ST + module Control.Monad.ST ) where import Prelude diff --git a/Data/Complex.hs b/Data/Complex.hs index 3b37f6c..7d29e77 100644 --- a/Data/Complex.hs +++ b/Data/Complex.hs @@ -13,30 +13,30 @@ ----------------------------------------------------------------------------- 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 - - -- Complex instances: - -- - -- (RealFloat a) => Eq (Complex a) - -- (RealFloat a) => Read (Complex a) - -- (RealFloat a) => Show (Complex a) - -- (RealFloat a) => Num (Complex a) - -- (RealFloat a) => Fractional (Complex a) - -- (RealFloat a) => Floating (Complex a) - -- + ( + -- * 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 + + -- Complex instances: + -- + -- (RealFloat a) => Eq (Complex a) + -- (RealFloat a) => Read (Complex a) + -- (RealFloat a) => Show (Complex a) + -- (RealFloat a) => Num (Complex a) + -- (RealFloat a) => Fractional (Complex a) + -- (RealFloat a) => Floating (Complex a) + -- -- Implementation checked wrt. Haskell 98 lib report, 1/99. ) where @@ -63,12 +63,12 @@ infix 6 :+ -- but oriented in the positive real direction, whereas @'signum' z@ -- has the phase of @z@, but unit magnitude. data (RealFloat a) => Complex a - = !a :+ !a -- ^ forms a complex number from its real and imaginary - -- rectangular components. + = !a :+ !a -- ^ forms a complex number from its real and imaginary + -- rectangular components. # if __GLASGOW_HASKELL__ - deriving (Eq, Show, Read, Data) + deriving (Eq, Show, Read, Data) # else - deriving (Eq, Show, Read) + deriving (Eq, Show, Read) # endif -- ----------------------------------------------------------------------------- @@ -84,42 +84,42 @@ imagPart (_ :+ y) = y -- | The conjugate of a complex number. {-# SPECIALISE conjugate :: Complex Double -> Complex Double #-} -conjugate :: (RealFloat a) => Complex a -> Complex a +conjugate :: (RealFloat 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 r theta = r * cos theta :+ r * sin theta +mkPolar :: (RealFloat 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 theta = cos theta :+ sin theta +cis :: (RealFloat a) => a -> Complex a +cis theta = cos theta :+ sin theta -- | The function 'polar' takes a complex number and -- returns a (magnitude, phase) pair in canonical form: -- the magnitude is nonnegative, and the phase in the range @(-'pi', 'pi']@; -- if the magnitude is zero, then so is the phase. {-# SPECIALISE polar :: Complex Double -> (Double,Double) #-} -polar :: (RealFloat a) => Complex a -> (a,a) -polar z = (magnitude z, phase z) +polar :: (RealFloat a) => Complex a -> (a,a) +polar z = (magnitude z, phase z) -- | The nonnegative magnitude of a complex number. {-# SPECIALISE magnitude :: Complex Double -> Double #-} magnitude :: (RealFloat a) => Complex a -> a magnitude (x:+y) = scaleFloat k - (sqrt ((scaleFloat mk x)^(2::Int) + (scaleFloat mk y)^(2::Int))) - where k = max (exponent x) (exponent y) - mk = - k + (sqrt ((scaleFloat mk x)^(2::Int) + (scaleFloat mk y)^(2::Int))) + where k = max (exponent x) (exponent y) + mk = - k -- | The phase of a complex number, in the range @(-'pi', 'pi']@. -- If the magnitude is zero, then so is the phase. {-# SPECIALISE phase :: Complex Double -> Double #-} phase :: (RealFloat a) => Complex a -> a -phase (0 :+ 0) = 0 -- SLPJ July 97 from John Peterson -phase (x:+y) = atan2 y x +phase (0 :+ 0) = 0 -- SLPJ July 97 from John Peterson +phase (x:+y) = atan2 y x -- ----------------------------------------------------------------------------- @@ -131,33 +131,33 @@ INSTANCE_TYPEABLE1(Complex,complexTc,"Complex") instance (RealFloat a) => Num (Complex a) where {-# SPECIALISE instance Num (Complex Float) #-} {-# SPECIALISE instance Num (Complex Double) #-} - (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) = 0 - signum z@(x:+y) = x/r :+ y/r where r = magnitude z - fromInteger n = fromInteger n :+ 0 + (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) = 0 + signum z@(x:+y) = x/r :+ y/r where r = magnitude z + fromInteger n = fromInteger n :+ 0 #ifdef __HUGS__ - fromInt n = fromInt n :+ 0 + fromInt n = fromInt n :+ 0 #endif instance (RealFloat a) => Fractional (Complex a) where {-# SPECIALISE instance Fractional (Complex Float) #-} {-# SPECIALISE instance Fractional (Complex Double) #-} - (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'' + (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 + fromRational a = fromRational a :+ 0 #ifdef __HUGS__ - fromDouble a = fromDouble a :+ 0 + fromDouble a = fromDouble a :+ 0 #endif -instance (RealFloat a) => Floating (Complex a) where +instance (RealFloat a) => Floating (Complex a) where {-# SPECIALISE instance Floating (Complex Float) #-} {-# SPECIALISE instance Floating (Complex Double) #-} pi = pi :+ 0 diff --git a/Data/Foldable.hs b/Data/Foldable.hs index 52b31ca..97880ba 100644 --- a/Data/Foldable.hs +++ b/Data/Foldable.hs @@ -17,47 +17,47 @@ -- for this module. module Data.Foldable ( - -- * Folds - Foldable(..), - -- ** Special biased folds - foldr', - foldl', - foldrM, - foldlM, - -- ** Folding actions - -- *** Applicative actions - traverse_, - for_, - sequenceA_, - asum, - -- *** Monadic actions - mapM_, - forM_, - sequence_, - msum, - -- ** Specialized folds - toList, - concat, - concatMap, - and, - or, - any, - all, - sum, - product, - maximum, - maximumBy, - minimum, - minimumBy, - -- ** Searches - elem, - notElem, - find - ) where + -- * Folds + Foldable(..), + -- ** Special biased folds + foldr', + foldl', + foldrM, + foldlM, + -- ** Folding actions + -- *** Applicative actions + traverse_, + for_, + sequenceA_, + asum, + -- *** Monadic actions + mapM_, + forM_, + 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) + elem, notElem, concat, concatMap, and, or, any, all, + sum, product, maximum, minimum) import qualified Prelude (foldl, foldr, foldl1, foldr1) import Control.Applicative import Control.Monad (MonadPlus(..)) @@ -91,61 +91,61 @@ import GHC.Exts (build) -- to satisfy the monoid laws. -- class Foldable t where - -- | Combine the elements of a structure using a monoid. - fold :: Monoid m => t m -> m - fold = foldMap id - - -- | Map each element of the structure to a monoid, - -- and combine the results. - foldMap :: Monoid m => (a -> m) -> t a -> m - foldMap f = foldr (mappend . f) mempty - - -- | Right-associative fold of a structure. - -- - -- @'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 - - -- | Left-associative fold of a structure. - -- - -- @'foldl' f z = 'Prelude.foldl' f z . 'toList'@ - foldl :: (a -> b -> a) -> a -> t b -> a - foldl f z t = appEndo (getDual (foldMap (Dual . Endo . flip f) t)) z - - -- | A variant of 'foldr' that has no base case, - -- and thus may only be applied to non-empty structures. - -- - -- @'foldr1' f = 'Prelude.foldr1' f . 'toList'@ - foldr1 :: (a -> a -> a) -> t a -> a - 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) - - -- | A variant of 'foldl' that has no base case, - -- and thus may only be applied to non-empty structures. - -- - -- @'foldl1' f = 'Prelude.foldl1' f . 'toList'@ - foldl1 :: (a -> a -> a) -> t a -> a - 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) + -- | Combine the elements of a structure using a monoid. + fold :: Monoid m => t m -> m + fold = foldMap id + + -- | Map each element of the structure to a monoid, + -- and combine the results. + foldMap :: Monoid m => (a -> m) -> t a -> m + foldMap f = foldr (mappend . f) mempty + + -- | Right-associative fold of a structure. + -- + -- @'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 + + -- | Left-associative fold of a structure. + -- + -- @'foldl' f z = 'Prelude.foldl' f z . 'toList'@ + foldl :: (a -> b -> a) -> a -> t b -> a + foldl f z t = appEndo (getDual (foldMap (Dual . Endo . flip f) t)) z + + -- | A variant of 'foldr' that has no base case, + -- and thus may only be applied to non-empty structures. + -- + -- @'foldr1' f = 'Prelude.foldr1' f . 'toList'@ + foldr1 :: (a -> a -> a) -> t a -> a + 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) + + -- | A variant of 'foldl' that has no base case, + -- and thus may only be applied to non-empty structures. + -- + -- @'foldl1' f = 'Prelude.foldl1' f . 'toList'@ + foldl1 :: (a -> a -> a) -> t a -> a + 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) -- instances for Prelude types instance Foldable Maybe where - foldr f z Nothing = z - foldr f z (Just x) = f x z + foldr f z Nothing = z + foldr f z (Just x) = f x z - foldl f z Nothing = z - foldl f z (Just x) = f z x + foldl f z Nothing = z + foldl f z (Just x) = f z x instance Foldable [] where - foldr = Prelude.foldr - foldl = Prelude.foldl - foldr1 = Prelude.foldr1 - foldl1 = Prelude.foldl1 + foldr = Prelude.foldr + foldl = Prelude.foldl + foldr1 = Prelude.foldr1 + foldl1 = Prelude.foldl1 -- | Fold over the elements of a structure, -- associating to the right, but strictly. @@ -267,8 +267,8 @@ maximum = foldr1 max maximumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a maximumBy cmp = foldr1 max' where max' x y = case cmp x y of - GT -> x - _ -> y + GT -> x + _ -> y -- | The least element of a non-empty structure. minimum :: (Foldable t, Ord a) => t a -> a @@ -279,8 +279,8 @@ minimum = foldr1 min minimumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a minimumBy cmp = foldr1 min' where min' x y = case cmp x y of - GT -> y - _ -> x + GT -> y + _ -> x -- | Does the element occur in the structure? elem :: (Foldable t, Eq a) => a -> t a -> Bool diff --git a/Data/Ix.hs b/Data/Ix.hs index f9ce182..7205a01 100644 --- a/Data/Ix.hs +++ b/Data/Ix.hs @@ -16,12 +16,12 @@ 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 - ) + 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 + ) -- Ix instances: -- -- Ix Char @@ -46,13 +46,13 @@ module Data.Ix -- is the same numbering defined by the 'Enum' class. For example, given -- the datatype: -- - -- > data Colour = Red | Orange | Yellow | Green | Blue | Indigo | Violet + -- > 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 + -- > 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 in Figure 1 diff --git a/Data/Ratio.hs b/Data/Ratio.hs index 22f3abe..d64297f 100644 --- a/Data/Ratio.hs +++ b/Data/Ratio.hs @@ -15,10 +15,10 @@ 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 + , (%) -- :: (Integral a) => a -> a -> Ratio a + , numerator -- :: (Integral a) => Ratio a -> a + , denominator -- :: (Integral a) => Ratio a -> a + , approxRational -- :: (RealFrac a) => a -> a -> Rational -- Ratio instances: -- (Integral a) => Eq (Ratio a) @@ -27,16 +27,16 @@ module Data.Ratio -- (Integral a) => Real (Ratio a) -- (Integral a) => Fractional (Ratio a) -- (Integral a) => RealFrac (Ratio a) - -- (Integral a) => Enum (Ratio a) + -- (Integral a) => Enum (Ratio a) -- (Read a, Integral a) => Read (Ratio a) - -- (Integral a) => Show (Ratio a) + -- (Integral a) => Show (Ratio a) ) where import Prelude #ifdef __GLASGOW_HASKELL__ -import GHC.Real -- The basic defns for Ratio +import GHC.Real -- The basic defns for Ratio #endif #ifdef __HUGS__ @@ -68,27 +68,27 @@ import Ratio (Ratio(..), (%), numerator, denominator, approxRational) -- and abs r' < d', and the simplest rational is q%1 + the reciprocal of -- the simplest rational between d'%r' and d%r. -approxRational :: (RealFrac a) => a -> a -> Rational -approxRational rat eps = simplest (rat-eps) (rat+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 = toRational x - n = numerator xr - d = denominator xr - nd' = toRational y - n' = numerator nd' - d' = denominator nd' +approxRational :: (RealFrac a) => a -> a -> Rational +approxRational rat eps = simplest (rat-eps) (rat+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 = toRational x + n = numerator xr + d = denominator xr + nd' = toRational y + n' = numerator nd' + d' = denominator nd' - 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' - nd'' = simplest' d' r' d r - n'' = numerator nd'' - d'' = denominator nd'' + 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' + nd'' = simplest' d' r' d r + n'' = numerator nd'' + d'' = denominator nd'' #endif diff --git a/Data/STRef.hs b/Data/STRef.hs index 10853be..288cbe7 100644 --- a/Data/STRef.hs +++ b/Data/STRef.hs @@ -13,12 +13,12 @@ ----------------------------------------------------------------------------- module Data.STRef ( - -- * STRefs - STRef, -- abstract, instance Eq - newSTRef, -- :: a -> ST s (STRef s a) - readSTRef, -- :: STRef s a -> ST s a - writeSTRef, -- :: STRef s a -> a -> ST s () - modifySTRef -- :: STRef s a -> (a -> a) -> ST s () + -- * STRefs + STRef, -- abstract, instance Eq + newSTRef, -- :: a -> ST s (STRef s a) + readSTRef, -- :: STRef s a -> ST s a + writeSTRef, -- :: STRef s a -> a -> ST s () + modifySTRef -- :: STRef s a -> (a -> a) -> ST s () ) where import Prelude diff --git a/Data/STRef/Lazy.hs b/Data/STRef/Lazy.hs index 79a6529..3218310 100644 --- a/Data/STRef/Lazy.hs +++ b/Data/STRef/Lazy.hs @@ -12,12 +12,12 @@ -- ----------------------------------------------------------------------------- module Data.STRef.Lazy ( - -- * STRefs - ST.STRef, -- abstract, instance Eq - newSTRef, -- :: a -> ST s (STRef s a) - readSTRef, -- :: STRef s a -> ST s a - writeSTRef, -- :: STRef s a -> a -> ST s () - modifySTRef -- :: STRef s a -> (a -> a) -> ST s () + -- * STRefs + ST.STRef, -- abstract, instance Eq + newSTRef, -- :: a -> ST s (STRef s a) + readSTRef, -- :: STRef s a -> ST s a + writeSTRef, -- :: STRef s a -> a -> ST s () + modifySTRef -- :: STRef s a -> (a -> a) -> ST s () ) where import Control.Monad.ST.Lazy diff --git a/Data/STRef/Strict.hs b/Data/STRef/Strict.hs index 81f13cd..61ac9b8 100644 --- a/Data/STRef/Strict.hs +++ b/Data/STRef/Strict.hs @@ -13,7 +13,7 @@ ----------------------------------------------------------------------------- module Data.STRef.Strict ( - module Data.STRef + module Data.STRef ) where import Prelude diff --git a/Data/Traversable.hs b/Data/Traversable.hs index 52c44ab..841e278 100644 --- a/Data/Traversable.hs +++ b/Data/Traversable.hs @@ -28,12 +28,12 @@ -- or qualify uses of these function names with an alias for this module. module Data.Traversable ( - Traversable(..), - for, - forM, - fmapDefault, - foldMapDefault, - ) where + Traversable(..), + for, + forM, + fmapDefault, + foldMapDefault, + ) where import Prelude hiding (mapM, sequence, foldr) import qualified Prelude (mapM, foldr) @@ -53,9 +53,9 @@ import Data.Monoid (Monoid) -- a suitable instance would be -- -- > instance Traversable Tree --- > traverse f Empty = pure Empty --- > traverse f (Leaf x) = Leaf <$> f x --- > traverse f (Node l k r) = Node <$> traverse f l <*> f k <*> traverse f r +-- > traverse f Empty = pure Empty +-- > traverse f (Leaf x) = Leaf <$> f x +-- > traverse f (Node l k r) = Node <$> traverse f l <*> f k <*> traverse f r -- -- This is suitable even for abstract types, as the laws for '<*>' -- imply a form of associativity. @@ -70,37 +70,37 @@ import Data.Monoid (Monoid) -- ('foldMapDefault'). -- class (Functor t, Foldable t) => Traversable t where - -- | Map each element of a structure to an action, evaluate - -- these actions from left to right, and collect the results. - 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. - 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. - mapM :: Monad m => (a -> m b) -> t a -> m (t b) - mapM f = unwrapMonad . traverse (WrapMonad . f) - - -- | Evaluate each monadic action in the structure from left to right, - -- and collect the results. - sequence :: Monad m => t (m a) -> m (t a) - sequence = mapM id + -- | Map each element of a structure to an action, evaluate + -- these actions from left to right, and collect the results. + 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. + 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. + mapM :: Monad m => (a -> m b) -> t a -> m (t b) + mapM f = unwrapMonad . traverse (WrapMonad . f) + + -- | Evaluate each monadic action in the structure from left to right, + -- and collect the results. + sequence :: Monad m => t (m a) -> m (t a) + sequence = mapM id -- instances for Prelude types instance Traversable Maybe where - traverse f Nothing = pure Nothing - traverse f (Just x) = Just <$> f x + traverse f Nothing = pure Nothing + traverse f (Just x) = Just <$> f x instance Traversable [] where - traverse f = Prelude.foldr cons_f (pure []) - where cons_f x ys = (:) <$> f x <*> ys + traverse f = Prelude.foldr cons_f (pure []) + where cons_f x ys = (:) <$> f x <*> ys - mapM = Prelude.mapM + mapM = Prelude.mapM -- general functions @@ -128,8 +128,8 @@ foldMapDefault f = getConst . traverse (Const . f) newtype Id a = Id { getId :: a } instance Functor Id where - fmap f (Id x) = Id (f x) + fmap f (Id x) = Id (f x) instance Applicative Id where - pure = Id - Id f <*> Id x = Id (f x) + pure = Id + Id f <*> Id x = Id (f x) diff --git a/Data/Version.hs b/Data/Version.hs index 1b02c6f..18701f7 100644 --- a/Data/Version.hs +++ b/Data/Version.hs @@ -24,10 +24,10 @@ ----------------------------------------------------------------------------- module Data.Version ( - -- * The @Version@ type - Version(..), - -- * A concrete representation of @Version@ - showVersion, parseVersion, + -- * The @Version@ type + Version(..), + -- * A concrete representation of @Version@ + showVersion, parseVersion, ) where import Prelude -- necessary to get dependencies right @@ -44,16 +44,16 @@ import Distribution.Compat.ReadP #endif #if !__GLASGOW_HASKELL__ -import Data.Typeable ( Typeable, TyCon, mkTyCon, mkTyConApp ) +import Data.Typeable ( Typeable, TyCon, mkTyCon, mkTyConApp ) #elif __GLASGOW_HASKELL__ < 602 -import Data.Dynamic ( Typeable(..), TyCon, mkTyCon, mkAppTy ) +import Data.Dynamic ( Typeable(..), TyCon, mkTyCon, mkAppTy ) #else -import Data.Typeable ( Typeable ) +import Data.Typeable ( Typeable ) #endif -import Data.List ( intersperse, sort ) -import Control.Monad ( liftM ) -import Data.Char ( isDigit, isAlphaNum ) +import Data.List ( intersperse, sort ) +import Control.Monad ( liftM ) +import Data.Char ( isDigit, isAlphaNum ) {- | A 'Version' represents the version of a software entity. @@ -80,29 +80,29 @@ representation may be more appropriate. -} data Version = Version { versionBranch :: [Int], - -- ^ The numeric branch for this version. This reflects the - -- fact that most software versions are tree-structured; there - -- is a main trunk which is tagged with versions at various - -- points (1,2,3...), and the first branch off the trunk after - -- 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 - -- the natural ordering of branches. - - versionTags :: [String] -- really a bag - -- ^ A version can be tagged with an arbitrary list of strings. - -- The interpretation of the list of tags is entirely dependent - -- on the entity that this version applies to. - } + -- ^ The numeric branch for this version. This reflects the + -- fact that most software versions are tree-structured; there + -- is a main trunk which is tagged with versions at various + -- points (1,2,3...), and the first branch off the trunk after + -- 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 + -- the natural ordering of branches. + + versionTags :: [String] -- really a bag + -- ^ A version can be tagged with an arbitrary list of strings. + -- The interpretation of the list of tags is entirely dependent + -- on the entity that this version applies to. + } deriving (Read,Show #if __GLASGOW_HASKELL__ >= 602 - ,Typeable + ,Typeable #endif - ) + ) #if !__GLASGOW_HASKELL__ versionTc :: TyCon diff --git a/System/CPUTime.hsc b/System/CPUTime.hsc index 2846d4c..b5d86d8 100644 --- a/System/CPUTime.hsc +++ b/System/CPUTime.hsc @@ -13,9 +13,9 @@ ----------------------------------------------------------------------------- module System.CPUTime - ( + ( getCPUTime, -- :: IO Integer - cpuTimePrecision -- :: Integer + cpuTimePrecision -- :: Integer ) where import Prelude @@ -67,7 +67,7 @@ getCPUTime = do let realToInteger = round . realToFrac :: Real a => a -> Integer return ((realToInteger u_sec * 1000000 + realToInteger u_usec + realToInteger s_sec * 1000000 + realToInteger s_usec) - * 1000000) + * 1000000) type CRUsage = () foreign import ccall unsafe getrusage :: CInt -> Ptr CRUsage -> IO CInt @@ -79,15 +79,15 @@ foreign import ccall unsafe getrusage :: CInt -> Ptr CRUsage -> IO CInt s_ticks <- (#peek struct tms,tms_stime) p_tms :: IO CClock let realToInteger = round . realToFrac :: Real a => a -> Integer return (( (realToInteger u_ticks + realToInteger s_ticks) * 1000000000000) - `div` fromIntegral clockTicks) + `div` fromIntegral clockTicks) type CTms = () foreign import ccall unsafe times :: Ptr CTms -> IO CClock # else ioException (IOError Nothing UnsupportedOperation - "getCPUTime" - "can't get CPU time" - Nothing) + "getCPUTime" + "can't get CPU time" + Nothing) # endif #endif @@ -106,12 +106,12 @@ foreign import ccall unsafe times :: Ptr CTms -> IO CClock return (ut + kt) else return 0 where - ft2psecs :: Ptr FILETIME -> IO Integer + ft2psecs :: Ptr FILETIME -> IO Integer ft2psecs ft = do high <- (#peek FILETIME,dwHighDateTime) ft :: IO Word32 low <- (#peek FILETIME,dwLowDateTime) ft :: IO Word32 - -- Convert 100-ns units to picosecs (10^-12) - -- => multiply by 10^5. + -- Convert 100-ns units to picosecs (10^-12) + -- => multiply by 10^5. return (((fromIntegral high) * (2^32) + (fromIntegral low)) * 100000) -- ToDo: pin down elapsed times to just the OS thread(s) that