on d2cde55 help sign in
streamly/src/Streamly/Internal/BaseCompat.hs
66 lines 1.5 kB history raw
1-- |
2-- Module : Streamly.Internal.BaseCompat
3-- License : BSD3
4-- Maintainer : streamly@composewell.com
5-- Stability : experimental
6-- Portability : GHC
7--
8-- Compatibility functions for "base" package.
9--
10module Streamly.Internal.BaseCompat
11 (
12 (#.)
13 , errorWithoutStackTrace
14 , fromLeft
15 , fromRight
16 , unsafeWithForeignPtr
17 , oneShot
18 )
19where
21import Data.Coerce (Coercible, coerce)
22#if MIN_VERSION_base(4,10,0)
23import Data.Either (fromRight, fromLeft)
24import qualified GHC.Exts as GHCExt
25#endif
26import GHC.ForeignPtr (ForeignPtr(..))
27import GHC.Ptr (Ptr(..))
28#if MIN_VERSION_base(4,15,0)
29import qualified GHC.ForeignPtr as GHCForeignPtr
30#else
31import Foreign.ForeignPtr (withForeignPtr)
32#endif
34{-# INLINE (#.) #-}
35(#.) :: Coercible b c => (b -> c) -> (a -> b) -> (a -> c)
36(#.) _f = coerce
38#if !(MIN_VERSION_base(4,9,0))
39{-# NOINLINE errorWithoutStackTrace #-}
40errorWithoutStackTrace :: String -> a
41errorWithoutStackTrace = error
42#endif
44#if !(MIN_VERSION_base(4,10,0))
45fromLeft :: a -> Either a b -> a
46fromLeft _ (Left a) = a
47fromLeft a _ = a
49fromRight :: b -> Either a b -> b
50fromRight _ (Right b) = b
51fromRight b _ = b
52#endif
54unsafeWithForeignPtr :: ForeignPtr a -> (Ptr a -> IO b) -> IO b
55#if MIN_VERSION_base(4,15,0)
56unsafeWithForeignPtr = GHCForeignPtr.unsafeWithForeignPtr
57#else
58unsafeWithForeignPtr = withForeignPtr
59#endif
61oneShot :: (a -> b) -> a -> b
62#if MIN_VERSION_base(4,10,0)
63oneShot = GHCExt.oneShot
64#else
65oneShot = id
66#endif