Flesh out the documentation a bit.
import GHC.Base
#endif
+{-|
+
+The 'Either' type represents values with two possibilities: a value of
+type @'Either' a b@ is either @'Left' a@ or @'Right' b@.
+
+The 'Either' type is sometimes used to represent a value which is
+either correct or an error; by convention, the 'Left' constructor is
+used to hold an error value and the 'Right' constructor is used to
+hold a correct value (mnemonic: \"right\" also means \"correct\").
+-}
data Either a b = Left a | Right b deriving (Eq, Ord )
either :: (a -> c) -> (b -> c) -> Either a b -> c
-- ---------------------------------------------------------------------------
-- The Maybe type, and instances
-data Maybe a = Nothing | Just a deriving (Eq, Ord)
+-- | The 'Maybe' type encapsulates an optional value. A value of type
+-- @'Maybe' a@ either contains a value of type @a@ (represented as @'Just' a@),
+-- or it is empty (represented as 'Nothing'). Using 'Maybe' is a good way to
+-- deal with errors or exceptional cases without resorting to drastic
+-- measures such as 'error'.
+--
+-- The 'Maybe' type is also a monad. It is a simple kind of error
+-- monad, where all errors are represented by 'Nothing'. A richer
+-- error monad can be built using the 'Data.Either.Either' type.
+
+data Maybe a = Nothing | Just a
+ deriving (Eq, Ord)
instance Functor Maybe where
fmap _ Nothing = Nothing
%*********************************************************
\begin{code}
+
+-- | The 'Eq' class defines equality ('==') and inequality ('/=').
+-- All the basic datatypes exported by the "Prelude" are instances of 'Eq',
+-- and 'Eq' may be derived for any datatype whose constituents are also
+-- instances of 'Eq'.
+--
+-- Minimal complete definition: either '==' or '/='.
+--
class Eq a where
(==), (/=) :: a -> a -> Bool
it here seems more direct.)
\begin{code}
+-- | The unit datatype @()@ has one non-undefined member, the nullary
+-- constructor @()@.
data () = ()
instance Eq () where
%*********************************************************
\begin{code}
+-- | Represents an ordering relationship between two values: less
+-- than, equal to, or greater than. An 'Ordering' is returned by
+-- 'compare'.
data Ordering = LT | EQ | GT deriving (Eq, Ord)
-- Read in GHC.Read, Show in GHC.Show
\end{code}
%*********************************************************
\begin{code}
+-- | A 'String' is a list of characters. String constants in Haskell are values
+-- of type 'String'.
+--
type String = [Char]
+{-| The character type 'Char' is an enumeration whose values represent
+Unicode characters. A character literal in Haskell has type 'Char'.
+
+To convert a 'Char' to or from an 'Int', use 'Prelude.toEnum' and
+'Prelude.fromEnum' from the 'Enum' class respectively (equivalently
+'ord' and 'chr' also do the trick).
+-}
data Char = C# Char#
-- We don't use deriving for Eq and Ord, because for Ord the derived
%*********************************************************
\begin{code}
+-- | Single-precision floating point numbers.
data Float = F# Float#
+
+-- | Double-precision floating point numbers.
data Double = D# Double#
instance CCallable Float
--SDM
-}
+{-|
+A value of type @'IO' a@ is a computation which, when performed,
+does some I\/O before returning a value of type @a@.
+
+There is really only one way to \"perform\" an I\/O action: bind it to
+@Main.main@ in your program. When your program is run, the I\/O will
+be performed. It isn't possible to perform I\/O from an arbitrary
+function, unless that function is itself in the 'IO' monad and called
+at some point, directly or indirectly, from @Main.main@.
+
+'IO' is a monad, so 'IO' actions can be combined using either the do-notation
+or the '>>' and '>>=' operations from the 'Monad' class.
+-}
newtype IO a = IO (State# RealWorld -> (# State# RealWorld, a #))
unIO :: IO a -> (State# RealWorld -> (# State# RealWorld, a #))
%*********************************************************
\begin{code}
+-- | Arbitrary-precision integers.
data Integer
= S# Int# -- small integers
#ifndef ILX
\begin{code}
data (Integral a) => Ratio a = !a :% !a deriving (Eq)
+
+-- | Arbitrary-precision rational numbers, represented as a ratio of
+-- two 'Integer' values. A rational number may be constructed using
+-- the '%' operator.
type Rational = Ratio Integer
infinity, notANumber :: Rational
module Prelude (
- -- List things
- [] (..),
+ -- * Basic data types
+ Bool(..),
+ Maybe(..),
+ Either(..),
+ Ordering(..),
+ Char, String, Int, Integer, Float, Double, IO,
+ Rational,
+ []((:), []),
+
+ module Data.Tuple,
+ -- Includes tuple types + fst, snd, curry, uncurry
+ ()(..), -- The unit type
+ (->), -- functions
+
+ -- * Basic type classes
+ Eq(..),
+ Ord(..),
+ Enum(..),
+ Bounded(..),
+ Num(..),
+ Real(..),
+ Integral(..),
+ Fractional(..),
+ Floating(..),
+ RealFrac(..),
+ RealFloat(..),
+ -- * List operations
map, (++), filter, concat,
head, last, tail, init, null, length, (!!),
foldl, foldl1, scanl, scanl1, foldr, foldr1, scanr, scanr1,
lines, words, unlines, unwords,
sum, product,
- -- Everything from Text.Read and Text.Show
+ -- * Converting to and from @String@
ReadS, ShowS,
Read(readsPrec, readList),
Show(showsPrec, showList, show),
reads, shows, read, lex,
showChar, showString, readParen, showParen,
- -- Everything corresponding to the Report's PreludeIO
+ -- * Simple I\/O operations
ioError, userError, catch,
FilePath, IOError,
putChar,
getLine, getContents, interact,
readFile, writeFile, appendFile, readIO, readLn,
- Bool(..),
- Maybe(..),
- Either(..),
- Ordering(..),
- Char, String, Int, Integer, Float, Double, IO,
- Rational,
- []((:), []),
-
- module Data.Tuple,
- -- Includes tuple types + fst, snd, curry, uncurry
- ()(..), -- The unit type
- (->), -- functions
-
- Eq(..),
- Ord(..),
- Enum(..),
- Bounded(..),
- Num(..),
- Real(..),
- Integral(..),
- Fractional(..),
- Floating(..),
- RealFrac(..),
- RealFloat(..),
-
- -- Monad stuff, from GHC.Base, and defined here
+ -- * Monads
Monad(..),
Functor(..),
mapM, mapM_, sequence, sequence_, (=<<),
+ -- * Miscellaneous functions
maybe, either,
(&&), (||), not, otherwise,
subtract, even, odd, gcd, lcm, (^), (^^),