untabify
[ghc-base.git] / GHC / Err.lhs
index fb34ab5..c1c9774 100644 (file)
@@ -1,21 +1,27 @@
-% -----------------------------------------------------------------------------
-% $Id: Err.lhs,v 1.4 2002/04/11 12:03:43 simonpj Exp $
-%
-% (c) The University of Glasgow, 1994-2000
-%
-
-\section[GHC.Err]{Module @GHC.Err@}
-
-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.
-
 \begin{code}
-{-# OPTIONS -fno-implicit-prelude #-}
-module GHC.Err 
+{-# OPTIONS_GHC -fno-implicit-prelude #-}
+{-# OPTIONS_HADDOCK hide #-}
+-----------------------------------------------------------------------------
+-- |
+-- 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.
+-- 
+-----------------------------------------------------------------------------
+
+-- #hide
+module GHC.Err
        (
          irrefutPatError
        , noMethodBindingError
@@ -23,35 +29,39 @@ module GHC.Err
        , patError
        , recSelError
        , recConError
-       , runtimeError              -- :: Addr#  -> a   -- Addr# points to UTF8 encoded C string
+       , runtimeError              -- :: Addr#  -> a    -- Addr# points to UTF8 encoded C string
+
+       , absentErr                 -- :: a
+       , divZeroError              -- :: a
+       , overflowError             -- :: a
 
-       , absentErr, parError       -- :: a
-       , seqError                  -- :: a
+       , error                     -- :: String -> a
+       , assertError               -- :: String -> Bool -> a -> a
 
-       , error                    -- :: String -> a
-       , assertError              -- :: String -> Bool -> a -> a
-       
-       , undefined                -- :: a
+       , undefined                 -- :: a
        ) where
 
+#ifndef __HADDOCK__
 import GHC.Base
 import GHC.List     ( span )
 import GHC.Exception
+#endif
 \end{code}
 
 %*********************************************************
-%*                                                     *
+%*                                                      *
 \subsection{Error-ish functions}
-%*                                                     *
+%*                                                      *
 %*********************************************************
 
 \begin{code}
--- error stops execution and displays an error message
+-- | 'error' stops execution and displays an error message.
 error :: String -> a
 error s = throw (ErrorCall 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 
+-- messages which are more appropriate to the context in which 'undefined'
 -- appears. 
 
 undefined :: a
@@ -59,35 +69,33 @@ undefined =  error "Prelude.undefined"
 \end{code}
 
 %*********************************************************
-%*                                                      *
+%*                                                       *
 \subsection{Compiler generated errors + local utils}
-%*                                                      *
+%*                                                       *
 %*********************************************************
 
 Used for compiler-generated error message;
 encoding saves bytes of string junk.
 
 \begin{code}
-absentErr, parError, seqError :: a
+absentErr :: a
 
 absentErr = error "Oops! The program has entered an `absent' argument!\n"
-parError  = error "Oops! Entered GHCerr.parError (a GHC bug -- please report it!)\n"
-seqError  = error "Oops! Entered seqError (a GHC bug -- please report it!)\n"
 \end{code}
 
 \begin{code}
 recSelError, recConError, irrefutPatError, runtimeError,
-            nonExhaustiveGuardsError, patError, noMethodBindingError
-       :: Addr# -> a   -- All take a UTF8-encoded C string
+             nonExhaustiveGuardsError, patError, noMethodBindingError
+        :: Addr# -> a   -- All take a UTF8-encoded C string
 
-recSelError             s = throw (RecSelError (unpackCStringUtf8# s)) -- No location info unfortunately
-runtimeError            s = error (unpackCStringUtf8# s)               -- No location info unfortunately
+recSelError              s = throw (RecSelError (unpackCStringUtf8# s)) -- No location info unfortunately
+runtimeError             s = error (unpackCStringUtf8# s)               -- No location info unfortunately
 
 nonExhaustiveGuardsError s = throw (PatternMatchFail (untangle s "Non-exhaustive guards in"))
-irrefutPatError                 s = throw (PatternMatchFail (untangle s "Irrefutable pattern failed for pattern"))
-recConError                     s = throw (RecConError      (untangle s "Missing field in record construction"))
+irrefutPatError          s = throw (PatternMatchFail (untangle s "Irrefutable pattern failed for pattern"))
+recConError              s = throw (RecConError      (untangle s "Missing field in record construction"))
 noMethodBindingError     s = throw (NoMethodError    (untangle s "No instance nor default method for class operation"))
-patError                s = throw (PatternMatchFail (untangle s "Non-exhaustive patterns in"))
+patError                 s = throw (PatternMatchFail (untangle s "Non-exhaustive patterns in"))
 
 assertError :: Addr# -> Bool -> a -> a
 assertError str pred v 
@@ -98,11 +106,11 @@ assertError str pred v
 
 (untangle coded message) expects "coded" to be of the form 
 
-       "location|details"
+        "location|details"
 
 It prints
 
-       location message details
+        location message details
 
 \begin{code}
 untangle :: Addr# -> String -> String
@@ -117,9 +125,24 @@ untangle coded message
 
     (location, details)
       = case (span not_bar coded_str) of { (loc, rest) ->
-       case rest of
-         ('|':det) -> (loc, ' ' : det)
-         _         -> (loc, "")
-       }
+        case rest of
+          ('|':det) -> (loc, ' ' : det)
+          _         -> (loc, "")
+        }
     not_bar c = c /= '|'
 \end{code}
+
+Divide by zero and arithmetic overflow.
+We put them here because they are needed relatively early
+in the libraries before the Exception type has been defined yet.
+
+\begin{code}
+{-# NOINLINE divZeroError #-}
+divZeroError :: a
+divZeroError = throw (ArithException DivideByZero)
+
+{-# NOINLINE overflowError #-}
+overflowError :: a
+overflowError = throw (ArithException Overflow)
+\end{code}
+