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

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}
\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
------------------------------------------------------------------------
{-
Be careful about these instances.
(a) remember that you have to count down as well as up e.g. [13,12..0]
(b) be careful of Int overflow
(c) remember that Int is bounded, so [1..] terminates at maxInt
-}
\begin{code}
instance Bounded Int where
minBound = minInt
maxBound = maxInt
......@@ -628,16 +594,12 @@ efdtIntDnFB c n x1 x2 y -- Be careful about underflow!
go_dn x | isTrue# (x <# y') = I# x `c` n
| otherwise = I# x `c` go_dn (x +# delta)
in I# x1 `c` go_dn x2
\end{code}
%*********************************************************
%* *
\subsection{Type @Word@}
%* *
%*********************************************************
------------------------------------------------------------------------
-- Word
------------------------------------------------------------------------
\begin{code}
instance Bounded Word where
minBound = 0
......@@ -685,16 +647,11 @@ integerToWordX i = W# (integerToWord i)
wordToIntegerX :: Word -> Integer
wordToIntegerX (W# x#) = wordToInteger x#
\end{code}
%*********************************************************
%* *
\subsection{The @Integer@ instance for @Enum@}
%* *
%*********************************************************
------------------------------------------------------------------------
-- Integer
------------------------------------------------------------------------
\begin{code}
instance Enum Integer where
succ x = x + 1
pred x = x - 1
......@@ -772,5 +729,3 @@ dn_list x0 delta lim = go (x0 :: Integer)
where
go x | x < lim = []
| otherwise = x : go (x+delta)
\end{code}
\begin{code}
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE NoImplicitPrelude, MagicHash #-}
{-# OPTIONS_HADDOCK hide #-}
......@@ -8,18 +7,18 @@
-- Module : GHC.Err
-- Copyright : (c) The University of Glasgow, 1994-2002
-- License : see libraries/base/LICENSE
--
--
-- Maintainer : cvs-ghc@haskell.org
-- Stability : internal
-- Portability : non-portable (GHC extensions)
--
-- The "GHC.Err" module defines the code for the wired-in error functions,
-- which have a special type in the compiler (with \"open tyvars\").
--
--
-- We cannot define these functions in a module where they might be used
-- (e.g., "GHC.Base"), because the magical wired-in type will get confused
-- with what the typechecker figures out.
--
--
-----------------------------------------------------------------------------
module GHC.Err( absentErr, error, undefined ) where
......@@ -30,15 +29,7 @@ import GHC.Integer () -- Make sure Integer is compiled first
-- because GHC depends on it in a wired-in way
-- so the build system doesn't see the dependency
import {-# SOURCE #-} GHC.Exception( errorCallException )
\end{code}
%*********************************************************
%* *
\subsection{Error-ish functions}
%* *
%*********************************************************
\begin{code}
-- | 'error' stops execution and displays an error message.
error :: [Char] -> a
error s = raise# (errorCallException s)
......@@ -46,23 +37,11 @@ error s = raise# (errorCallException s)
-- | A special case of 'error'.
-- It is expected that compilers will recognize this and insert error
-- messages which are more appropriate to the context in which 'undefined'
-- appears.
-- appears.
undefined :: a
undefined = error "Prelude.undefined"
undefined = error "Prelude.undefined"
\end{code}
%*********************************************************
%* *
\subsection{Compiler generated errors + local utils}
%* *
Used for compiler-generated error message;
encoding saves bytes of string junk.
-- | Used for compiler-generated error message;
-- encoding saves bytes of string junk.
absentErr :: a
absentErr = error "Oops! The program has entered an `absent' argument!\n"
absentErr = error "Oops! The program has entered an `absent' argument!\n"
\end{code}
\begin{code}
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE NoImplicitPrelude
, ExistentialQuantification
......@@ -34,15 +33,7 @@ import Data.Typeable (Typeable, cast)
-- loop: Data.Typeable -> GHC.Err -> GHC.Exception
import GHC.Base
import GHC.Show
\end{code}
%*********************************************************
%* *
\subsection{Exceptions}
%* *
%*********************************************************
\begin{code}
{- |
The @SomeException@ type is the root of the exception type hierarchy.
When an exception of type @e@ is thrown, behind the scenes it is
......@@ -152,22 +143,12 @@ class (Typeable e, Show e) => Exception e where
instance Exception SomeException where
toException se = se
fromException = Just
\end{code}
%*********************************************************
%* *
\subsection{Primitive throw}
%* *
%*********************************************************
\begin{code}
-- | Throw an exception. Exceptions may be thrown from purely
-- functional code, but may only be caught within the 'IO' monad.
throw :: Exception e => e -> a
throw e = raise# (toException e)
\end{code}
\begin{code}
-- |This is thrown when the user calls 'error'. The @String@ is the
-- argument given to 'error'.
newtype ErrorCall = ErrorCall String
......@@ -181,8 +162,6 @@ instance Show ErrorCall where
errorCallException :: String -> SomeException
errorCallException s = toException (ErrorCall s)
-----
-- |Arithmetic exceptions.
data ArithException
= Overflow
......@@ -207,4 +186,3 @@ instance Show ArithException where
showsPrec _ DivideByZero = showString "divide by zero"
showsPrec _ Denormal = showString "denormal"
showsPrec _ RatioZeroDenominator = showString "Ratio has zero denominator"
\end{code}
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-
This SOURCE-imported hs-boot module cuts a big dependency loop:
GHC.Exception
......@@ -18,21 +22,13 @@ imports {-# SOURCE #-} GHC.Exception
However, GHC.Exceptions loop-breaking exports are all nice,
well-behaved, non-bottom values. The clients use 'raise#'
to get a visibly-bottom value.
\begin{code}
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE NoImplicitPrelude #-}
---------------------------------------------------------------------------
-- Ghc.Exception.hs-boot
---------------------------------------------------------------------------
-}
module GHC.Exception ( SomeException, errorCallException,
divZeroException, overflowException, ratioZeroDenomException
) where
divZeroException, overflowException, ratioZeroDenomException
) where
import GHC.Types( Char )
data SomeException
divZeroException, overflowException, ratioZeroDenomException :: SomeException
errorCallException :: [Char] -> SomeException
\end{code}
\begin{code}
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE CPP, NoImplicitPrelude, ScopedTypeVariables, MagicHash #-}
{-# LANGUAGE BangPatterns #-}
......@@ -41,15 +40,11 @@ import GHC.Integer (Integer)
infixl 9 !!
infix 4 `elem`, `notElem`
\end{code}
%*********************************************************
%* *
\subsection{List-manipulation functions}
%* *
%*********************************************************
--------------------------------------------------------------
-- List-manipulation functions
--------------------------------------------------------------
\begin{code}
-- | Extract the first element of a list, which must be non-empty.
head :: [a] -> a
head (x:_) = x
......@@ -844,10 +839,6 @@ concat = foldr (++) []
-- We don't bother to turn non-fusible applications of concat back into concat
#-}
\end{code}
\begin{code}
-- | List index (subscript) operator, starting from 0.
-- It is an instance of the more general 'Data.List.genericIndex',
-- which takes an index of any integral type.
......@@ -876,16 +867,11 @@ xs !! n
0 -> x
_ -> r (k-1)) tooLarge xs n
#endif
\end{code}
%*********************************************************
%* *
\subsection{The zip family}
%* *
%*********************************************************
--------------------------------------------------------------
-- The zip family
--------------------------------------------------------------
\begin{code}
foldr2 :: (a -> b -> c -> c) -> c -> [a] -> [b] -> c
foldr2 k z = go
where
......@@ -911,11 +897,10 @@ foldr2_right k _z y r (x:xs) = k x y (r xs)
"foldr2/right" forall k z xs (g::forall b.(a->b->b)->b->b) .
foldr2 k z xs (build g) = g (foldr2_right k z) (\_ -> z) xs
#-}
\end{code}
Zips for larger tuples are in the List module.
\begin{code}
-- Zips for larger tuples are in the List module.
----------------------------------------------
-- | 'zip' takes two lists and returns a list of corresponding pairs.
-- If one input list is short, excess elements of the longer list are
......@@ -945,9 +930,7 @@ zipFB c = \x y r -> (x,y) `c` r
"zip" [~1] forall xs ys. zip xs ys = build (\c n -> foldr2 (zipFB c) n xs ys)
"zipList" [1] foldr2 (zipFB (:)) [] = zip
#-}
\end{code}
\begin{code}
----------------------------------------------
-- | 'zip3' takes three lists and returns a list of triples, analogous to
-- 'zip'.
......@@ -956,13 +939,11 @@ zip3 :: [a] -> [b] -> [c] -> [(a,b,c)]
-- zip3 = zipWith3 (,,)
zip3 (a:as) (b:bs) (c:cs) = (a,b,c) : zip3 as bs cs
zip3 _ _ _ = []
\end{code}
-- The zipWith family generalises the zip family by zipping with the
-- function given as the first argument, instead of a tupling function.
\begin{code}
----------------------------------------------
-- | 'zipWith' generalises 'zip' by zipping with the function given
-- as the first argument, instead of a tupling function.
......@@ -996,9 +977,7 @@ zipWithFB c f = \x y r -> (x `f` y) `c` r
"zipWith" [~1] forall f xs ys. zipWith f xs ys = build (\c n -> foldr2 (zipWithFB c f) n xs ys)
"zipWithList" [1] forall f. foldr2 (zipWithFB (:) f) [] = zipWith f
#-}
\end{code}
\begin{code}
-- | The 'zipWith3' function takes a function which combines three
-- elements, as well as three lists and returns a list of their point-wise
-- combination, analogous to 'zipWith'.
......@@ -1019,23 +998,17 @@ unzip3 :: [(a,b,c)] -> ([a],[b],[c])
{-# INLINE unzip3 #-}
unzip3 = foldr (\(a,b,c) ~(as,bs,cs) -> (a:as,b:bs,c:cs))
([],[],[])
\end{code}
%*********************************************************
%* *
\subsection{Error code}
%* *
%*********************************************************
--------------------------------------------------------------
-- Error code
--------------------------------------------------------------
Common up near identical calls to `error' to reduce the number
constant strings created when compiled:
-- Common up near identical calls to `error' to reduce the number
-- constant strings created when compiled:
\begin{code}
errorEmptyList :: String -> a
errorEmptyList fun =
error (prel_list_str ++ fun ++ ": empty list")
prel_list_str :: String
prel_list_str = "Prelude."
\end{code}
\begin{code}
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE NoImplicitPrelude, MagicHash, UnboxedTuples #-}
{-# OPTIONS_HADDOCK hide #-}
......@@ -26,15 +25,7 @@ infixl 6 +, -
default () -- Double isn't available yet,
-- and we shouldn't be using defaults anyway
\end{code}
%*********************************************************
%* *
\subsection{Standard numeric class}
%* *
%*********************************************************
\begin{code}
-- | Basic numeric class.
class Num a where
{-# MINIMAL (+), (*), abs, signum, fromInteger, (negate | (-)) #-}
......@@ -71,16 +62,7 @@ class Num a where
{-# INLINE subtract #-}
subtract :: (Num a) => a -> a -> a
subtract x y = y - x
\end{code}
%*********************************************************
%* *
\subsection{Instances for @Int@}
%* *
%*********************************************************
\begin{code}
instance Num Int where
I# x + I# y = I# (x +# y)
I# x - I# y = I# (x -# y)
......@@ -94,15 +76,7 @@ instance Num Int where
{-# INLINE fromInteger #-} -- Just to be sure!
fromInteger i = I# (integerToInt i)
\end{code}
%*********************************************************
%* *
\subsection{Instances for @Word@}
%* *
%*********************************************************
\begin{code}
instance Num Word where
(W# x#) + (W# y#) = W# (x# `plusWord#` y#)
(W# x#) - (W# y#) = W# (x# `minusWord#` y#)
......@@ -112,15 +86,7 @@ instance Num Word where
signum 0 = 0
signum _ = 1
fromInteger i = W# (integerToWord i)
\end{code}
%*********************************************************
%* *
\subsection{The @Integer@ instances for @Num@}
%* *
%*********************************************************
\begin{code}
instance Num Integer where
(+) = plusInteger
(-) = minusInteger
......@@ -130,5 +96,3 @@ instance Num Integer where
abs = absInteger
signum = signumInteger
\end{code}
\begin{code}
{-# LANGUAGE Unsafe #-}
{-# LANGUAGE NoImplicitPrelude, MagicHash, UnboxedTuples #-}
{-# OPTIONS_HADDOCK hide #-}
......@@ -8,7 +7,7 @@
-- Module : GHC.Pack
-- Copyright : (c) The University of Glasgow 1997-2002
-- License : see libraries/base/LICENSE
--
--
-- Maintainer : cvs-ghc@haskell.org
-- Stability : internal
-- Portability : non-portable (GHC Extensions)
......@@ -16,7 +15,7 @@
-- This module provides a small set of low-level functions for packing
-- and unpacking a chunk of bytes. Used by code emitted by the compiler