module Data.Generics.Uniplate.Internal.Utils(
unsafeCoerce, builder, unsafePerformIO, inlinePerformIO, concatCont
) where
import Foreign(unsafePerformIO)
import Unsafe.Coerce(unsafeCoerce)
#ifdef __GLASGOW_HASKELL__
import GHC.Exts(build, realWorld#)
import GHC.IOBase(IO(IO))
#endif
#ifdef __GLASGOW_HASKELL__
builder :: forall a . (forall b . (a -> b -> b) -> b -> b) -> [a]
builder = build
#else
builder :: ((x -> [x] -> [x]) -> [x] -> [x]) -> [x]
builder f = f (:) []
#endif
inlinePerformIO :: IO a -> a
#ifdef __GLASGOW_HASKELL__
inlinePerformIO (IO m) = case m realWorld# of (# _, r #) -> r
#else
inlinePerformIO = unsafePerformIO
#endif
concatCont :: [a -> a] -> a -> a
concatCont xs rest = foldr ($) rest xs