module Data.Array.Parallel.Base.Debug (
check
, checkCritical
, checkLen
, checkEq
, checkNotEmpty
, uninitialised
) where
import Data.Array.Parallel.Base.Config (debug, debugCritical)
outOfBounds :: String -> Int -> Int -> a
outOfBounds loc n i = error $ loc ++ ": Out of bounds (size = "
++ show n ++ "; index = " ++ show i ++ ")"
check :: String -> Int -> Int -> a -> a
check loc n i v
| debug = if (i >= 0 && i < n) then v else outOfBounds loc n i
| otherwise = v
checkCritical :: String -> Int -> Int -> a -> a
checkCritical loc n i v
| debugCritical = if (i >= 0 && i < n) then v else outOfBounds loc n i
| otherwise = v
checkLen :: String -> Int -> Int -> a -> a
checkLen loc n i v
| debug = if (i >= 0 && i <= n) then v else outOfBounds loc n i
| otherwise = v
checkEq :: (Eq a, Show a) => String -> String -> a -> a -> b -> b
checkEq loc msg x y v
| debug = if x == y then v else err
| otherwise = v
where
err = error $ loc ++ ": " ++ msg
++ " (first = " ++ show x
++ "; second = " ++ show y ++ ")"
checkNotEmpty :: String -> Int -> a -> a
checkNotEmpty loc n v
| debug = if n /= 0 then v else err
| otherwise = v
where
err = error $ loc ++ ": Empty array"
uninitialised :: String -> a
uninitialised loc = error $ loc ++ ": Touched an uninitialised value"