Commit df3b1d43 authored by Herbert Valerio Riedel's avatar Herbert Valerio Riedel 🕺
Browse files

base: Manually unlit .lhs into .hs modules

This commit mostly converts literate comments into ordinary
Haskell comments or sometimes even Haddock comments, while also
removing literate comments in a few cases where they don't make
much sense anymore.

Moreover, in a few cases trailing whitespaces were removed as well.

Reviewed By: austin

Differential Revision: https://phabricator.haskell.org/D456
parent 832ef3fb
\begin{code}
{-# LANGUAGE Unsafe #-}
{-# LANGUAGE NoImplicitPrelude, MagicHash, UnboxedTuples #-}
{-# OPTIONS_GHC -funbox-strict-fields #-}
......@@ -52,16 +51,7 @@ import GHC.Show
infixl 9 !, //
default ()
\end{code}
%*********************************************************
%* *
\subsection{The @Ix@ class}
%* *
%*********************************************************
\begin{code}
-- | The 'Ix' class is used to map a contiguous subrange of values in
-- a type onto integers. It is used primarily for array indexing
-- (see the array package).
......@@ -116,8 +106,8 @@ class (Ord a) => Ix a where
-- tuples. E.g. (1,2) <= (2,1) but the range is empty
unsafeRangeSize b@(_l,h) = unsafeIndex b h + 1
\end{code}
{-
Note that the following is NOT right
rangeSize (l,h) | l <= h = index b h + 1
| otherwise = 0
......@@ -128,11 +118,6 @@ is nevertheless empty. Consider
Here l<h, but the second index ranges from 2..1 and
hence is empty
%*********************************************************
%* *
\subsection{Instances of @Ix@}
%* *
%*********************************************************
Note [Inlining index]
~~~~~~~~~~~~~~~~~~~~~
......@@ -179,8 +164,8 @@ Note [Out-of-bounds error messages]
The default method for 'index' generates hoplelessIndexError, because
Ix doesn't have Show as a superclass. For particular base types we
can do better, so we override the default method for index.
-}
\begin{code}
-- Abstract these errors from the relevant index functions so that
-- the guts of the function will be small enough to inline.
......@@ -369,15 +354,7 @@ instance (Ix a1, Ix a2, Ix a3, Ix a4, Ix a5) => Ix (a1,a2,a3,a4,a5) where
inRange (l5,u5) i5
-- Default method for index
\end{code}
%*********************************************************
%* *
\subsection{The @Array@ types}
%* *
%*********************************************************
\begin{code}
-- | The type of immutable non-strict (boxed) arrays
-- with indices in @i@ and elements in @e@.
data Array i e
......@@ -411,16 +388,10 @@ data STArray s i e
instance Eq (STArray s i e) where
STArray _ _ _ arr1# == STArray _ _ _ arr2# =
isTrue# (sameMutableArray# arr1# arr2#)
\end{code}
----------------------------------------------------------------------
-- Operations on immutable arrays
%*********************************************************
%* *
\subsection{Operations on immutable arrays}
%* *
%*********************************************************
\begin{code}
{-# NOINLINE arrEleBottom #-}
arrEleBottom :: a
arrEleBottom = error "(Array.!): undefined array element"
......@@ -718,16 +689,10 @@ cmpIntArray arr1@(Array l1 u1 n1 _) arr2@(Array l2 u2 n2 _) =
other -> other
{-# RULES "cmpArray/Int" cmpArray = cmpIntArray #-}
\end{code}
%*********************************************************
%* *
\subsection{Array instances}
%* *
%*********************************************************
----------------------------------------------------------------------
-- Array instances
\begin{code}
instance Ix i => Functor (Array i) where
fmap = amap
......@@ -747,15 +712,11 @@ instance (Ix a, Show a, Show b) => Show (Array a b) where
-- Precedence of 'array' is the precedence of application
-- The Read instance is in GHC.Read
\end{code}
%*********************************************************
%* *
\subsection{Operations on mutable arrays}
%* *
%*********************************************************
----------------------------------------------------------------------
-- Operations on mutable arrays
{-
Idle ADR question: What's the tradeoff here between flattening these
datatypes into @STArray ix ix (MutableArray# s elt)@ and using
it as is? As I see it, the former uses slightly less heap and
......@@ -768,8 +729,8 @@ Idle AJG answer: When I looked at the outputted code (though it was 2
years ago) it seems like you often needed the tuple, and we build
it frequently. Now we've got the overloading specialiser things
might be different, though.
-}
\begin{code}
{-# INLINE newSTArray #-}
newSTArray :: Ix i => (i,i) -> e -> ST s (STArray s i e)
newSTArray (l,u) initial = ST $ \s1# ->
......@@ -805,16 +766,10 @@ unsafeWriteSTArray :: Ix i => STArray s i e -> Int -> e -> ST s ()
unsafeWriteSTArray (STArray _ _ _ marr#) (I# i#) e = ST $ \s1# ->
case writeArray# marr# i# e s1# of
s2# -> (# s2#, () #)
\end{code}
----------------------------------------------------------------------
-- Moving between mutable and immutable
%*********************************************************
%* *
\subsection{Moving between mutable and immutable}
%* *
%*********************************************************
\begin{code}
freezeSTArray :: Ix i => STArray s i e -> ST s (Array i e)
freezeSTArray (STArray l u n@(I# n#) marr#) = ST $ \s1# ->
case newArray# n# arrEleBottom s1# of { (# s2#, marr'# #) ->
......@@ -849,4 +804,3 @@ unsafeThawSTArray :: Ix i => Array i e -> ST s (STArray s i e)
unsafeThawSTArray (Array l u n arr#) = ST $ \s1# ->
case unsafeThawArray# arr# s1# of { (# s2#, marr# #) ->
(# s2#, STArray l u n marr# #) }
\end{code}
\section[GHC.Base]{Module @GHC.Base@}
{-
The overall structure of the GHC Prelude is a bit tricky.
a) We want to avoid "orphan modules", i.e. ones with instance
......@@ -60,8 +59,8 @@ GHC.Float Classes: Floating, RealFloat
Other Prelude modules are much easier with fewer complex dependencies.
-}
\begin{code}
{-# LANGUAGE Unsafe #-}
{-# LANGUAGE CPP
, NoImplicitPrelude
......@@ -127,8 +126,8 @@ infixr 0 $, $!
infixl 4 <*>, <*, *>, <**>
default () -- Double isn't available yet
\end{code}
{-
Note [Depend on GHC.Integer]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The Integer type is special because TidyPgm uses
......@@ -159,16 +158,10 @@ Similarly, tuple syntax (or ()) creates an implicit dependency on
GHC.Tuple, so we use the same rule as for Integer --- see Note [Depend on
GHC.Integer] --- to explain this to the build system. We make GHC.Base
depend on GHC.Tuple, and everything else depends on GHC.Base or Prelude.
-}
%*********************************************************
%* *
\subsection{DEBUGGING STUFF}
%* (for use when compiling GHC.Base itself doesn't work)
%* *
%*********************************************************
\begin{code}
{-
#if 0
-- for use when compiling GHC.Base itself doesn't work
data Bool = False | True
data Ordering = LT | EQ | GT
data Char = C# Char#
......@@ -183,16 +176,7 @@ otherwise = True
build = error "urk"
foldr = error "urk"
-}
\end{code}
%*********************************************************
%* *
\subsection{The Maybe type}
%* *
%*********************************************************
\begin{code}
#endif
-- | The 'Maybe' type encapsulates an optional value. A value of type
-- @'Maybe' a@ either contains a value of type @a@ (represented as @'Just' a@),
......@@ -207,16 +191,6 @@ foldr = error "urk"
data Maybe a = Nothing | Just a
deriving (Eq, Ord)
\end{code}
%*********************************************************
%* *
\subsection{Monoids}
%* *
%*********************************************************
\begin{code}
-- ---------------------------------------------------------------------------
-- | The class of monoids (types with an associative binary operation that
-- has an identity). Instances should satisfy the following laws:
--
......@@ -309,16 +283,8 @@ instance Monoid a => Monoid (Maybe a) where
instance Monoid a => Applicative ((,) a) where
pure x = (mempty, x)
(u, f) <*> (v, x) = (u `mappend` v, f x)
\end{code}
%*********************************************************
%* *
\subsection{Monadic classes @Functor@, @Applicative@, @Monad@ }
%* *
%*********************************************************
\begin{code}
{- | The 'Functor' class is used for types that can be mapped over.
Instances of 'Functor' should satisfy the following laws:
......@@ -696,16 +662,10 @@ class (Alternative m, Monad m) => MonadPlus m where
mplus = (<|>)
instance MonadPlus Maybe
\end{code}
%*********************************************************
%* *
\subsection{The list type}
%* *
%*********************************************************
----------------------------------------------
-- The list type
\begin{code}
instance Functor [] where
fmap = map
......@@ -724,16 +684,16 @@ instance Alternative [] where
(<|>) = (++)
instance MonadPlus []
\end{code}
{-
A few list functions that appear here because they are used here.
The rest of the prelude list functions are in GHC.List.
-}
----------------------------------------------
-- foldr/build/augment
----------------------------------------------
\begin{code}
-- | 'foldr', applied to a binary operator, a starting value (typically
-- the right-identity of the operator), and a list, reduces the list
-- using the binary operator, from right to left:
......@@ -820,14 +780,11 @@ augment g xs = g (:) xs
-- This rule is true, but not (I think) useful:
-- augment g (augment h t) = augment (\cn -> g c (h c n)) t
\end{code}
----------------------------------------------
-- map
----------------------------------------------
\begin{code}
-- | 'map' @f xs@ is the list obtained by applying @f@ to each element
-- of @xs@, i.e.,
--
......@@ -877,13 +834,11 @@ mapFB c f = \x ys -> c (f x) ys
{-# RULES "map/coerce" [1] map coerce = coerce #-}
\end{code}
----------------------------------------------
-- append
----------------------------------------------
\begin{code}
-- | Append two lists, i.e.,
--
-- > [x1, ..., xm] ++ [y1, ..., yn] == [x1, ..., xm, y1, ..., yn]
......@@ -902,16 +857,7 @@ mapFB c f = \x ys -> c (f x) ys
"++" [~1] forall xs ys. xs ++ ys = augment (\c n -> foldr c n xs) ys
#-}
\end{code}
%*********************************************************
%* *
\subsection{Type @Bool@}
%* *
%*********************************************************
\begin{code}
-- |'otherwise' is defined as the value 'True'. It helps to make
-- guards more readable. eg.
--
......@@ -919,15 +865,11 @@ mapFB c f = \x ys -> c (f x) ys
-- > | otherwise = ...
otherwise :: Bool
otherwise = True
\end{code}
%*********************************************************
%* *
\subsection{Type @Char@ and @String@}
%* *
%*********************************************************
----------------------------------------------
-- Type Char and String
----------------------------------------------
\begin{code}
-- | A 'String' is a list of characters. String constants in Haskell are values
-- of type 'String'.
--
......@@ -939,11 +881,9 @@ unsafeChr (I# i#) = C# (chr# i#)
-- | The 'Prelude.fromEnum' method restricted to the type 'Data.Char.Char'.
ord :: Char -> Int
ord (C# c#) = I# (ord# c#)
\end{code}
String equality is used when desugaring pattern-matches against strings.
\begin{code}
-- | This 'String' equality predicate is used when desugaring
-- pattern-matches against strings.
eqString :: String -> String -> Bool
eqString [] [] = True
eqString (c1:cs1) (c2:cs2) = c1 == c2 && cs1 `eqString` cs2
......@@ -952,16 +892,12 @@ eqString _ _ = False
{-# RULES "eqString" (==) = eqString #-}
-- eqString also has a BuiltInRule in PrelRules.lhs:
-- eqString (unpackCString# (Lit s1)) (unpackCString# (Lit s2) = s1==s2
\end{code}
%*********************************************************
%* *
\subsection{Type @Int@}
%* *
%*********************************************************
----------------------------------------------
-- 'Int' related definitions
----------------------------------------------
\begin{code}
maxInt, minInt :: Int
{- Seems clumsy. Should perhaps put minInt and MaxInt directly into MachDeps.h -}
......@@ -975,16 +911,11 @@ maxInt = I# 0x7FFFFFFF#
minInt = I# (-0x8000000000000000#)
maxInt = I# 0x7FFFFFFFFFFFFFFF#
#endif
\end{code}
%*********************************************************
%* *
\subsection{The function type}
%* *
%*********************************************************
----------------------------------------------
-- The function type
----------------------------------------------
\begin{code}
-- | Identity function.
id :: a -> a
id x = x
......@@ -1062,15 +993,11 @@ until p f = go
-- (which is usually overloaded) to have the same type as the second.
asTypeOf :: a -> a -> a
asTypeOf = const
\end{code}
%*********************************************************
%* *
\subsection{@Functor@ and @Monad@ instances for @IO@}
%* *
%*********************************************************
----------------------------------------------
-- Functor/Applicative/Monad instances for IO
----------------------------------------------
\begin{code}
instance Functor IO where
fmap f x = x >>= (return . f)
......@@ -1098,14 +1025,8 @@ thenIO (IO m) k = IO $ \ s -> case m s of (# new_s, _ #) -> unIO k new_s
unIO :: IO a -> (State# RealWorld -> (# State# RealWorld, a #))
unIO (IO a) = a
\end{code}
%*********************************************************
%* *
\subsection{@getTag@}
%* *
%*********************************************************
{- |
Returns the 'tag' of a constructor application; this function is used
by the deriving code for Eq, Ord and Enum.
......@@ -1117,23 +1038,18 @@ dataToTag# can be an inline primop if it doesn't need to do any
evaluation, and (b) we want to expose the evaluation to the
simplifier, because it might be possible to eliminate the evaluation
in the case when the argument is already known to be evaluated.
\begin{code}
-}
{-# INLINE getTag #-}
getTag :: a -> Int#
getTag !x = dataToTag# x
\end{code}
%*********************************************************
%* *
\subsection{Numeric primops}
%* *
%*********************************************************
----------------------------------------------
-- Numeric primops
----------------------------------------------
Definitions of the boxed PrimOps; these will be
used in the case of partial applications, etc.
-- Definitions of the boxed PrimOps; these will be
-- used in the case of partial applications, etc.
\begin{code}
{-# INLINE quotInt #-}
{-# INLINE remInt #-}
......@@ -1217,14 +1133,11 @@ a `iShiftRL#` b | isTrue# (b >=# WORD_SIZE_IN_BITS#) = 0#
-- unpackFoldr "foo" c (unpackFoldr "baz" c n) = unpackFoldr "foobaz" c n
#-}
\end{code}
#ifdef __HADDOCK__
\begin{code}
-- | A special argument for the 'Control.Monad.ST.ST' type constructor,
-- indexing a state embedded in the 'Prelude.IO' monad by
-- 'Control.Monad.ST.stToIO'.
data RealWorld
\end{code}
#endif
\begin{code}
{-# LANGUAGE Unsafe #-}
{-# LANGUAGE CPP, NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
......@@ -9,13 +8,13 @@
-- Module : GHC.Conc
-- Copyright : (c) The University of Glasgow, 1994-2002
-- License : see libraries/base/LICENSE
--
--
-- Maintainer : cvs-ghc@haskell.org
-- Stability : internal
-- Portability : non-portable (GHC extensions)
--
-- Basic concurrency stuff.
--
--
-----------------------------------------------------------------------------
-- No: #hide, because bits of this module are exposed by the stm package.
......@@ -112,5 +111,3 @@ import GHC.Conc.Sync
#ifndef mingw32_HOST_OS
import GHC.Conc.Signal
#endif
\end{code}
\begin{code}
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE CPP, NoImplicitPrelude, BangPatterns, MagicHash #-}
{-# OPTIONS_HADDOCK hide #-}
......@@ -34,16 +33,7 @@ import GHC.Integer
import GHC.Num
import GHC.Show
default () -- Double isn't available yet
\end{code}
%*********************************************************
%* *
\subsection{Class declarations}
%* *
%*********************************************************
\begin{code}
-- | The 'Bounded' class is used to name the upper and lower limits of a
-- type. 'Ord' is not a superclass of 'Bounded' since types that are not
-- totally ordered may also have upper and lower bounds.
......@@ -125,9 +115,7 @@ boundedEnumFromThen n1 n2
where
i_n1 = fromEnum n1
i_n2 = fromEnum n2
\end{code}
\begin{code}
------------------------------------------------------------------------
-- Helper functions
------------------------------------------------------------------------
......@@ -157,16 +145,11 @@ succError inst_ty =
predError :: String -> a
predError inst_ty =
error $ "Enum.pred{" ++ inst_ty ++ "}: tried to take `pred' of minBound"
\end{code}
%*********************************************************
%* *
\subsection{Tuples}
%* *
%*********************************************************
------------------------------------------------------------------------
-- Tuples
------------------------------------------------------------------------
\begin{code}
instance Bounded () where
minBound = ()
maxBound = ()
......@@ -183,9 +166,7 @@ instance Enum () where
enumFromThen () () = let many = ():many in many
enumFromTo () () = [()]
enumFromThenTo () () () = let many = ():many in many
\end{code}
\begin{code}
-- Report requires instances up to 15
instance (Bounded a, Bounded b) => Bounded (a,b) where
minBound = (minBound, minBound)
......@@ -274,16 +255,11 @@ instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Boun
minBound, minBound, minBound, minBound, minBound, minBound, minBound)
maxBound = (maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound,
maxBound, maxBound, maxBound, maxBound, maxBound, maxBound, maxBound)
\end{code}
------------------------------------------------------------------------
-- Bool
------------------------------------------------------------------------
%*********************************************************
%* *
\subsection{Type @Bool@}
%* *
%*********************************************************
\begin{code}
instance Bounded Bool where
minBound = False
maxBound = True
......@@ -305,15 +281,11 @@ instance Enum Bool where
-- Use defaults for the rest
enumFrom = boundedEnumFrom
enumFromThen = boundedEnumFromThen
\end{code}
%*********************************************************
%* *
\subsection{Type @Ordering@}
%* *
%*********************************************************
------------------------------------------------------------------------
-- Ordering
------------------------------------------------------------------------
\begin{code}
instance Bounded Ordering where
minBound = LT
maxBound = GT
......@@ -339,15 +311,11 @@ instance Enum Ordering where
-- Use defaults for the rest
enumFrom = boundedEnumFrom
enumFromThen = boundedEnumFromThen
\end{code}
%*********************************************************
%* *
\subsection{Type @Char@}
%* *
%*********************************************************
------------------------------------------------------------------------
-- Char
------------------------------------------------------------------------
\begin{code}
instance Bounded Char where
minBound = '\0'
maxBound = '\x10FFFF'
......@@ -461,21 +429,19 @@ go_dn_char_list x0 delta lim
where
go_dn x | isTrue# (x <# lim) = []
| otherwise = C# (chr# x) : go_dn (x +# delta)
\end{code}
%*********************************************************
%* *
\subsection{Type @Int@}
%* *
%*********************************************************
------------------------------------------------------------------------
-- Int
------------------------------------------------------------------------
{-