{-# LANGUAGE CPP #-}
module Data.Text.Internal.Functions
(
intersperse,
unsafeWithForeignPtr
) where
import Foreign.Ptr (Ptr)
import Foreign.ForeignPtr (ForeignPtr)
#if MIN_VERSION_base(4,15,0)
import qualified GHC.ForeignPtr (unsafeWithForeignPtr)
#else
import qualified Foreign.ForeignPtr (withForeignPtr)
#endif
intersperse :: a -> [a] -> [a]
intersperse :: a -> [a] -> [a]
intersperse a
_ [] = []
intersperse a
sep (a
x:[a]
xs) = a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a] -> [a]
go [a]
xs
where
go :: [a] -> [a]
go [] = []
go (a
y:[a]
ys) = a
sep a -> [a] -> [a]
forall a. a -> [a] -> [a]
: a
ya -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a] -> [a]
go [a]
ys
{-# INLINE intersperse #-}
unsafeWithForeignPtr :: ForeignPtr a -> (Ptr a -> IO b) -> IO b
#if MIN_VERSION_base(4,15,0)
unsafeWithForeignPtr = GHC.ForeignPtr.unsafeWithForeignPtr
#else
unsafeWithForeignPtr :: ForeignPtr a -> (Ptr a -> IO b) -> IO b
unsafeWithForeignPtr = ForeignPtr a -> (Ptr a -> IO b) -> IO b
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
Foreign.ForeignPtr.withForeignPtr
#endif