Move assertError into GHC.IOBase
authorIan Lynagh <igloo@earth.li>
Sun, 3 Aug 2008 14:10:40 +0000 (14:10 +0000)
committerIan Lynagh <igloo@earth.li>
Sun, 3 Aug 2008 14:10:40 +0000 (14:10 +0000)
Control/Exception.hs
GHC/IOBase.lhs

index c1dd408..8d5aa2d 100644 (file)
@@ -558,16 +558,6 @@ instance Show NoMethodError where
 
 -----
 
-data AssertionFailed = AssertionFailed String
-INSTANCE_TYPEABLE0(AssertionFailed,assertionFailedTc,"AssertionFailed")
-
-instance Exception AssertionFailed
-
-instance Show AssertionFailed where
-    showsPrec _ (AssertionFailed err) = showString err
-
------
-
 data NonTermination = NonTermination
 INSTANCE_TYPEABLE0(NonTermination,nonTerminationTc,"NonTermination")
 
@@ -600,35 +590,6 @@ instance Exception Dynamic
 
 -----
 
-assertError :: Addr# -> Bool -> a -> a
-assertError str pred v
-  | pred      = v
-  | otherwise = throw (AssertionFailed (untangle str "Assertion failed"))
-
-{-
-(untangle coded message) expects "coded" to be of the form
-        "location|details"
-It prints
-        location message details
--}
-untangle :: Addr# -> String -> String
-untangle coded message
-  =  location
-  ++ ": " 
-  ++ message
-  ++ details
-  ++ "\n"
-  where
-    coded_str = unpackCStringUtf8# coded
-
-    (location, details)
-      = case (span not_bar coded_str) of { (loc, rest) ->
-        case rest of
-          ('|':det) -> (loc, ' ' : det)
-          _         -> (loc, "")
-        }
-    not_bar c = c /= '|'
-
 -- XXX From GHC.Conc
 throwTo :: Exception e => ThreadId -> e -> IO ()
 throwTo (ThreadId id) ex = IO $ \ s ->
index ea4abf4..aa4af69 100644 (file)
@@ -46,7 +46,7 @@ module GHC.IOBase(
     ExitCode(..),
     throwIO, block, unblock, blocked, catchAny, catchException,
     evaluate,
-    ErrorCall(..),
+    ErrorCall(..), AssertionFailed(..), assertError, untangle,
     BlockedOnDeadMVar(..), BlockedIndefinitely(..), Deadlock(..)
   ) where
 
@@ -670,6 +670,16 @@ instance Show Deadlock where
 
 -----
 
+data AssertionFailed = AssertionFailed String
+    deriving Typeable
+
+instance Exception AssertionFailed
+
+instance Show AssertionFailed where
+    showsPrec _ (AssertionFailed err) = showString err
+
+-----
+
 -- |The type of arithmetic exceptions
 data ArithException
   = Overflow
@@ -1006,3 +1016,34 @@ evaluate a = IO $ \s -> case a `seq` () of () -> (# s, a #)
         -- because we can't have an unboxed tuple as a function argument
 \end{code}
 
+\begin{code}
+assertError :: Addr# -> Bool -> a -> a
+assertError str pred v
+  | pred      = v
+  | otherwise = throw (AssertionFailed (untangle str "Assertion failed"))
+
+{-
+(untangle coded message) expects "coded" to be of the form
+        "location|details"
+It prints
+        location message details
+-}
+untangle :: Addr# -> String -> String
+untangle coded message
+  =  location
+  ++ ": "
+  ++ message
+  ++ details
+  ++ "\n"
+  where
+    coded_str = unpackCStringUtf8# coded
+
+    (location, details)
+      = case (span not_bar coded_str) of { (loc, rest) ->
+        case rest of
+          ('|':det) -> (loc, ' ' : det)
+          _         -> (loc, "")
+        }
+    not_bar c = c /= '|'
+\end{code}
+