{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE ImplicitParams #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE ViewPatterns #-}
#if __GLASGOW_HASKELL__ >= 980
#define WARNING_IN_XTODO WARNING in "x-todo"
#else
#define WARNING_IN_XTODO WARNING
#endif
module Control.Placeholder
(
todo
, unimplemented
, pattern TODO
, pattern Unimplemented
, todoIO
, unimplementedIO
, TodoException(TodoException, TodoExceptionWithLocation)
, UnimplementedException(UnimplementedException, UnimplementedExceptionWithLocation)
) where
import Control.Exception
import Data.List (intercalate)
import Data.Typeable
import GHC.Base (raise#, raiseIO#, TYPE, RuntimeRep)
import GHC.Exception
import GHC.Stack
import GHC.Types (IO(IO))
import System.IO.Unsafe
newtype TodoException = TodoExceptionWithLocation String
deriving (Typeable, Show TodoException
Typeable TodoException
(Typeable TodoException, Show TodoException) =>
(TodoException -> SomeException)
-> (SomeException -> Maybe TodoException)
-> (TodoException -> String)
-> Exception TodoException
SomeException -> Maybe TodoException
TodoException -> String
TodoException -> SomeException
forall e.
(Typeable e, Show e) =>
(e -> SomeException)
-> (SomeException -> Maybe e) -> (e -> String) -> Exception e
$ctoException :: TodoException -> SomeException
toException :: TodoException -> SomeException
$cfromException :: SomeException -> Maybe TodoException
fromException :: SomeException -> Maybe TodoException
$cdisplayException :: TodoException -> String
displayException :: TodoException -> String
Exception)
instance Show TodoException where
showsPrec :: Int -> TodoException -> ShowS
showsPrec Int
_ (TodoExceptionWithLocation String
loc)
= String -> ShowS
showString String
todoMessage ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
'\n' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
loc
pattern TodoException :: TodoException
pattern $mTodoException :: forall {r}. TodoException -> ((# #) -> r) -> ((# #) -> r) -> r
$bTodoException :: TodoException
TodoException <- TodoExceptionWithLocation _ where
TodoException = String -> TodoException
TodoExceptionWithLocation String
missingLocation
newtype UnimplementedException = UnimplementedExceptionWithLocation String
deriving (Typeable, Show UnimplementedException
Typeable UnimplementedException
(Typeable UnimplementedException, Show UnimplementedException) =>
(UnimplementedException -> SomeException)
-> (SomeException -> Maybe UnimplementedException)
-> (UnimplementedException -> String)
-> Exception UnimplementedException
SomeException -> Maybe UnimplementedException
UnimplementedException -> String
UnimplementedException -> SomeException
forall e.
(Typeable e, Show e) =>
(e -> SomeException)
-> (SomeException -> Maybe e) -> (e -> String) -> Exception e
$ctoException :: UnimplementedException -> SomeException
toException :: UnimplementedException -> SomeException
$cfromException :: SomeException -> Maybe UnimplementedException
fromException :: SomeException -> Maybe UnimplementedException
$cdisplayException :: UnimplementedException -> String
displayException :: UnimplementedException -> String
Exception)
instance Show UnimplementedException where
showsPrec :: Int -> UnimplementedException -> ShowS
showsPrec Int
_ (UnimplementedExceptionWithLocation String
loc)
= String -> ShowS
showString String
unimplementedMessage ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
'\n' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
loc
pattern UnimplementedException :: UnimplementedException
pattern $mUnimplementedException :: forall {r}.
UnimplementedException -> ((# #) -> r) -> ((# #) -> r) -> r
$bUnimplementedException :: UnimplementedException
UnimplementedException <- UnimplementedExceptionWithLocation _ where
UnimplementedException = String -> UnimplementedException
UnimplementedExceptionWithLocation String
missingLocation
withCallStack :: Exception a => (String -> a) -> CallStack -> SomeException
withCallStack :: forall a.
Exception a =>
(String -> a) -> CallStack -> SomeException
withCallStack String -> a
f CallStack
stk = IO SomeException -> SomeException
forall a. IO a -> a
unsafeDupablePerformIO do
[String]
ccsStack <- IO [String]
currentCallStack
let
implicitParamCallStack :: [String]
implicitParamCallStack = CallStack -> [String]
prettyCallStackLines CallStack
stk
ccsCallStack :: [String]
ccsCallStack = [String] -> [String]
showCCSStack [String]
ccsStack
stack :: String
stack = String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate String
"\n" ([String] -> String) -> [String] -> String
forall a b. (a -> b) -> a -> b
$ [String]
implicitParamCallStack [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String]
ccsCallStack
SomeException -> IO SomeException
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SomeException -> IO SomeException)
-> SomeException -> IO SomeException
forall a b. (a -> b) -> a -> b
$ a -> SomeException
forall e. Exception e => e -> SomeException
toException (a -> SomeException) -> a -> SomeException
forall a b. (a -> b) -> a -> b
$ String -> a
f String
stack
todo :: forall {r :: RuntimeRep} (a :: TYPE r). HasCallStack => a
todo :: forall a. HasCallStack => a
todo = SomeException -> a
forall a b. a -> b
raise# (SomeException -> a) -> SomeException -> a
forall a b. (a -> b) -> a -> b
$ (String -> TodoException) -> CallStack -> SomeException
forall a.
Exception a =>
(String -> a) -> CallStack -> SomeException
withCallStack String -> TodoException
TodoExceptionWithLocation HasCallStack
CallStack
?callStack
{-# WARNING_IN_XTODO todo "'todo' left in code" #-}
todoIO :: HasCallStack => IO a
todoIO :: forall a. HasCallStack => IO a
todoIO = (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
forall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
IO ((State# RealWorld -> (# State# RealWorld, a #)) -> IO a)
-> (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
forall a b. (a -> b) -> a -> b
$ SomeException -> State# RealWorld -> (# State# RealWorld, a #)
forall a b. a -> State# RealWorld -> (# State# RealWorld, b #)
raiseIO# (SomeException -> State# RealWorld -> (# State# RealWorld, a #))
-> SomeException -> State# RealWorld -> (# State# RealWorld, a #)
forall a b. (a -> b) -> a -> b
$ (String -> TodoException) -> CallStack -> SomeException
forall a.
Exception a =>
(String -> a) -> CallStack -> SomeException
withCallStack String -> TodoException
TodoExceptionWithLocation HasCallStack
CallStack
?callStack
{-# WARNING_IN_XTODO todoIO "'todoIO' left in code" #-}
pattern TODO :: HasCallStack => () => a
pattern $mTODO :: forall {r} {a}.
HasCallStack =>
a -> ((# #) -> r) -> ((# #) -> r) -> r
$bTODO :: forall a. HasCallStack => a
TODO <- (raise# (withCallStack TodoExceptionWithLocation ?callStack) -> _unused) where
TODO = SomeException -> a
forall a b. a -> b
raise# (SomeException -> a) -> SomeException -> a
forall a b. (a -> b) -> a -> b
$ (String -> TodoException) -> CallStack -> SomeException
forall a.
Exception a =>
(String -> a) -> CallStack -> SomeException
withCallStack String -> TodoException
TodoExceptionWithLocation HasCallStack
CallStack
?callStack
{-# WARNING_IN_XTODO TODO "'TODO' left in code" #-}
{-# COMPLETE TODO #-}
unimplemented :: forall {r :: RuntimeRep} (a :: TYPE r). HasCallStack => a
unimplemented :: forall a. HasCallStack => a
unimplemented = SomeException -> a
forall a b. a -> b
raise# (SomeException -> a) -> SomeException -> a
forall a b. (a -> b) -> a -> b
$ (String -> UnimplementedException) -> CallStack -> SomeException
forall a.
Exception a =>
(String -> a) -> CallStack -> SomeException
withCallStack String -> UnimplementedException
UnimplementedExceptionWithLocation HasCallStack
CallStack
?callStack
unimplementedIO :: HasCallStack => IO a
unimplementedIO :: forall a. HasCallStack => IO a
unimplementedIO = (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
forall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
IO ((State# RealWorld -> (# State# RealWorld, a #)) -> IO a)
-> (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
forall a b. (a -> b) -> a -> b
$ SomeException -> State# RealWorld -> (# State# RealWorld, a #)
forall a b. a -> State# RealWorld -> (# State# RealWorld, b #)
raiseIO# (SomeException -> State# RealWorld -> (# State# RealWorld, a #))
-> SomeException -> State# RealWorld -> (# State# RealWorld, a #)
forall a b. (a -> b) -> a -> b
$ (String -> UnimplementedException) -> CallStack -> SomeException
forall a.
Exception a =>
(String -> a) -> CallStack -> SomeException
withCallStack String -> UnimplementedException
UnimplementedExceptionWithLocation HasCallStack
CallStack
?callStack
pattern Unimplemented :: HasCallStack => () => a
pattern $mUnimplemented :: forall {r} {a}.
HasCallStack =>
a -> ((# #) -> r) -> ((# #) -> r) -> r
$bUnimplemented :: forall a. HasCallStack => a
Unimplemented <- (raise# (withCallStack UnimplementedExceptionWithLocation ?callStack) -> _unused) where
Unimplemented = SomeException -> a
forall a b. a -> b
raise# (SomeException -> a) -> SomeException -> a
forall a b. (a -> b) -> a -> b
$ (String -> UnimplementedException) -> CallStack -> SomeException
forall a.
Exception a =>
(String -> a) -> CallStack -> SomeException
withCallStack String -> UnimplementedException
UnimplementedExceptionWithLocation HasCallStack
CallStack
?callStack
{-# COMPLETE Unimplemented #-}
missingLocation :: String
missingLocation :: String
missingLocation = String
""
{-# NOINLINE missingLocation #-}
todoMessage :: String
todoMessage :: String
todoMessage = String
"Control.Placeholder.todo: not yet implemented"
{-# NOINLINE todoMessage #-}
unimplementedMessage :: String
unimplementedMessage :: String
unimplementedMessage = String
"Control.Placeholder.unimplemented: unimplemented"
{-# NOINLINE unimplementedMessage #-}