-- This is written in Haskell. {-- HBase -- general-purpose libraries for Haskell Copyright (C) 2002 Ashley Yakeley This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --} -- | This module is not included in HBase, -- you have to import it separately. module HBase.Debug ( module HBase.Debug, unsafePerformIO ) where { import HBase; import System.IO.Unsafe(unsafePerformIO); import qualified System.IO; -- | This will typically crash if you're coercing to a different type. unsafeCoerce :: a -> b; unsafeCoerce a = unsafePerformIO (do { set r (Just a); Just b <- get r; return b; }) where { r :: IORef (Maybe c); r = unsafePerformIO (newStd Nothing); }; unsafeTypedCoerce :: (Type b) -> a -> b; unsafeTypedCoerce _ = unsafeCoerce; unsafeCoerceIO :: (Monad m) => IO a -> m a; unsafeCoerceIO = unsafeCoerce; debugPrint :: String -> IO (); debugPrint s = System.IO.hPutStrLn System.IO.stderr s; debugPrintValue :: (Show a) => String -> a -> IO (); debugPrintValue s a = debugPrint (s ++ ": " ++ (show a)); unsafePrintValue :: (Show a) => String -> a -> a; unsafePrintValue s a = unsafePerformIO (do { debugPrintValue s a; return a; }); unsafePrintCoercedValue :: (Show b) => (Type b) -> String -> a -> a; unsafePrintCoercedValue t s a = unsafePerformIO (do { debugPrintValue s (unsafeTypedCoerce t a); return a; }); seqReturn :: (Monad m) => a -> m (); seqReturn a = seq a (return ()); debugSource :: (Show a,LiftedMonad IO m) => m a -> m a; debugSource ma = do { a <- ma; lift (debugPrint (show a)); return a; }; }