Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Pipewire.Prelude
Description
Helper functions and re-export
Synopsis
- peekCString :: CString -> IO Text
- dieOnNull :: String -> IO (Ptr a) -> IO (Ptr a)
- dieOnErr :: String -> IO CInt -> IO ()
- maybeOnNull :: (Ptr a -> b) -> Ptr a -> Maybe b
- module Data.Word
- finally :: IO a -> IO b -> IO a
- when :: Applicative f => Bool -> f () -> f ()
- void :: Functor f => f a -> f ()
- unless :: Applicative f => Bool -> f () -> f ()
- data Ptr a
- data FunPtr a
- freeHaskellFunPtr :: FunPtr a -> IO ()
- nullPtr :: Ptr a
- alloca :: Storable a => (Ptr a -> IO b) -> IO b
- allocaBytes :: Int -> (Ptr a -> IO b) -> IO b
- data CFloat
- data CInt
- type CString = Ptr CChar
- fromBool :: Num a => Bool -> a
- data Text
- withCString :: Text -> (CString -> IO a) -> IO a
- data Vector a
- cfloatVector :: Vector Float -> Vector CFloat
Documentation
peekCString :: CString -> IO Text #
maybeOnNull :: (Ptr a -> b) -> Ptr a -> Maybe b #
Base
module Data.Word
Arguments
:: IO a | computation to run first |
-> IO b | computation to run afterward (even if an exception was raised) |
-> IO a |
A specialised variant of bracket
with just a computation to run
afterward.
when :: Applicative f => Bool -> f () -> f () #
Conditional execution of Applicative
expressions. For example,
when debug (putStrLn "Debugging")
will output the string Debugging
if the Boolean value debug
is True
, and otherwise do nothing.
void :: Functor f => f a -> f () #
discards or ignores the result of evaluation, such
as the return value of an void
valueIO
action.
Examples
Replace the contents of a
with unit:Maybe
Int
>>>
void Nothing
Nothing>>>
void (Just 3)
Just ()
Replace the contents of an
with unit, resulting in an Either
Int
Int
:Either
Int
()
>>>
void (Left 8675309)
Left 8675309>>>
void (Right 8675309)
Right ()
Replace every element of a list with unit:
>>>
void [1,2,3]
[(),(),()]
Replace the second element of a pair with unit:
>>>
void (1,2)
(1,())
Discard the result of an IO
action:
>>>
mapM print [1,2]
1 2 [(),()]>>>
void $ mapM print [1,2]
1 2
unless :: Applicative f => Bool -> f () -> f () #
The reverse of when
.
Foreign
A value of type
represents a pointer to an object, or an
array of objects, which may be marshalled to or from Haskell values
of type Ptr
aa
.
The type a
will often be an instance of class
Storable
which provides the marshalling operations.
However this is not essential, and you can provide your own operations
to access the pointer. For example you might write small foreign
functions to get or set the fields of a C struct
.
Instances
Generic1 (URec (Ptr ()) :: k -> Type) | |
Foldable (UAddr :: Type -> Type) | Since: base-4.9.0.0 |
Defined in Data.Foldable Methods fold :: Monoid m => UAddr m -> m # foldMap :: Monoid m => (a -> m) -> UAddr a -> m # foldMap' :: Monoid m => (a -> m) -> UAddr a -> m # foldr :: (a -> b -> b) -> b -> UAddr a -> b # foldr' :: (a -> b -> b) -> b -> UAddr a -> b # foldl :: (b -> a -> b) -> b -> UAddr a -> b # foldl' :: (b -> a -> b) -> b -> UAddr a -> b # foldr1 :: (a -> a -> a) -> UAddr a -> a # foldl1 :: (a -> a -> a) -> UAddr a -> a # elem :: Eq a => a -> UAddr a -> Bool # maximum :: Ord a => UAddr a -> a # minimum :: Ord a => UAddr a -> a # | |
Traversable (UAddr :: Type -> Type) | Since: base-4.9.0.0 |
Storable (Ptr a) | Since: base-2.1 |
Show (Ptr a) | Since: base-2.1 |
Eq (Ptr a) | Since: base-2.1 |
Ord (Ptr a) | Since: base-2.1 |
Hashable (Ptr a) | |
Defined in Data.Hashable.Class | |
Functor (URec (Ptr ()) :: Type -> Type) | Since: base-4.9.0.0 |
Generic (URec (Ptr ()) p) | |
Eq (URec (Ptr ()) p) | Since: base-4.9.0.0 |
Ord (URec (Ptr ()) p) | Since: base-4.9.0.0 |
Defined in GHC.Generics Methods compare :: URec (Ptr ()) p -> URec (Ptr ()) p -> Ordering # (<) :: URec (Ptr ()) p -> URec (Ptr ()) p -> Bool # (<=) :: URec (Ptr ()) p -> URec (Ptr ()) p -> Bool # (>) :: URec (Ptr ()) p -> URec (Ptr ()) p -> Bool # (>=) :: URec (Ptr ()) p -> URec (Ptr ()) p -> Bool # max :: URec (Ptr ()) p -> URec (Ptr ()) p -> URec (Ptr ()) p # min :: URec (Ptr ()) p -> URec (Ptr ()) p -> URec (Ptr ()) p # | |
data URec (Ptr ()) (p :: k) | Used for marking occurrences of Since: base-4.9.0.0 |
type Rep1 (URec (Ptr ()) :: k -> Type) | Since: base-4.9.0.0 |
Defined in GHC.Generics | |
type Rep (URec (Ptr ()) p) | Since: base-4.9.0.0 |
Defined in GHC.Generics |
A value of type
is a pointer to a function callable
from foreign code. The type FunPtr
aa
will normally be a foreign type,
a function type with zero or more arguments where
- the argument types are marshallable foreign types,
i.e.
Char
,Int
,Double
,Float
,Bool
,Int8
,Int16
,Int32
,Int64
,Word8
,Word16
,Word32
,Word64
,
,Ptr
a
,FunPtr
a
or a renaming of any of these usingStablePtr
anewtype
. - the return type is either a marshallable foreign type or has the form
whereIO
tt
is a marshallable foreign type or()
.
A value of type
may be a pointer to a foreign function,
either returned by another foreign function or imported with a
a static address import likeFunPtr
a
foreign import ccall "stdlib.h &free" p_free :: FunPtr (Ptr a -> IO ())
or a pointer to a Haskell function created using a wrapper stub
declared to produce a FunPtr
of the correct type. For example:
type Compare = Int -> Int -> Bool foreign import ccall "wrapper" mkCompare :: Compare -> IO (FunPtr Compare)
Calls to wrapper stubs like mkCompare
allocate storage, which
should be released with freeHaskellFunPtr
when no
longer required.
To convert FunPtr
values to corresponding Haskell functions, one
can define a dynamic stub for the specific foreign type, e.g.
type IntFunction = CInt -> IO () foreign import ccall "dynamic" mkFun :: FunPtr IntFunction -> IntFunction
Instances
Storable (FunPtr a) | Since: base-2.1 |
Defined in Foreign.Storable | |
Show (FunPtr a) | Since: base-2.1 |
Eq (FunPtr a) | |
Ord (FunPtr a) | |
Defined in GHC.Ptr | |
Hashable (FunPtr a) | |
Defined in Data.Hashable.Class |
freeHaskellFunPtr :: FunPtr a -> IO () #
Release the storage associated with the given FunPtr
, which
must have been obtained from a wrapper stub. This should be called
whenever the return value from a foreign import wrapper function is
no longer required; otherwise, the storage it uses will leak.
alloca :: Storable a => (Ptr a -> IO b) -> IO b #
executes the computation alloca
ff
, passing as argument
a pointer to a temporarily allocated block of memory sufficient to
hold values of type a
.
The memory is freed when f
terminates (either normally or via an
exception), so the pointer passed to f
must not be used after this.
allocaBytes :: Int -> (Ptr a -> IO b) -> IO b #
executes the computation allocaBytes
n ff
, passing as argument
a pointer to a temporarily allocated block of memory of n
bytes.
The block of memory is sufficiently aligned for any of the basic
foreign types that fits into a memory block of the allocated size.
The memory is freed when f
terminates (either normally or via an
exception), so the pointer passed to f
must not be used after this.
Haskell type representing the C float
type.
(The concrete types of Foreign.C.Types are platform-specific.)
Instances
Storable CFloat | |
Enum CFloat | |
Defined in Foreign.C.Types | |
Floating CFloat | |
RealFloat CFloat | |
Defined in Foreign.C.Types Methods floatRadix :: CFloat -> Integer # floatDigits :: CFloat -> Int # floatRange :: CFloat -> (Int, Int) # decodeFloat :: CFloat -> (Integer, Int) # encodeFloat :: Integer -> Int -> CFloat # significand :: CFloat -> CFloat # scaleFloat :: Int -> CFloat -> CFloat # isInfinite :: CFloat -> Bool # isDenormalized :: CFloat -> Bool # isNegativeZero :: CFloat -> Bool # | |
Num CFloat | |
Read CFloat | |
Fractional CFloat | |
Real CFloat | |
Defined in Foreign.C.Types Methods toRational :: CFloat -> Rational # | |
RealFrac CFloat | |
Show CFloat | |
Eq CFloat | |
Ord CFloat | |
Haskell type representing the C int
type.
(The concrete types of Foreign.C.Types are platform-specific.)
Instances
Storable CInt | |
Defined in Foreign.C.Types | |
Bits CInt | |
Defined in Foreign.C.Types Methods (.&.) :: CInt -> CInt -> CInt # (.|.) :: CInt -> CInt -> CInt # complement :: CInt -> CInt # shift :: CInt -> Int -> CInt # rotate :: CInt -> Int -> CInt # setBit :: CInt -> Int -> CInt # clearBit :: CInt -> Int -> CInt # complementBit :: CInt -> Int -> CInt # testBit :: CInt -> Int -> Bool # bitSizeMaybe :: CInt -> Maybe Int # shiftL :: CInt -> Int -> CInt # unsafeShiftL :: CInt -> Int -> CInt # shiftR :: CInt -> Int -> CInt # unsafeShiftR :: CInt -> Int -> CInt # rotateL :: CInt -> Int -> CInt # | |
FiniteBits CInt | |
Defined in Foreign.C.Types Methods finiteBitSize :: CInt -> Int # countLeadingZeros :: CInt -> Int # countTrailingZeros :: CInt -> Int # | |
Bounded CInt | |
Enum CInt | |
Ix CInt | |
Num CInt | |
Read CInt | |
Integral CInt | |
Real CInt | |
Defined in Foreign.C.Types Methods toRational :: CInt -> Rational # | |
Show CInt | |
Eq CInt | |
Ord CInt | |
text
A space efficient, packed, unboxed Unicode text type.
Instances
Chunk Text | |
Defined in Data.Attoparsec.Internal.Types Associated Types type ChunkElem Text Methods pappendChunk :: State Text -> Text -> State Text atBufferEnd :: Text -> State Text -> Pos bufferElemAt :: Text -> Pos -> State Text -> Maybe (ChunkElem Text, Int) chunkElemToChar :: Text -> ChunkElem Text -> Char | |
Hashable Text | |
Defined in Data.Hashable.Class | |
Pretty Text | Automatically converts all newlines to
Note that
Manually use |
Defined in Prettyprinter.Internal | |
type ChunkElem Text | |
Defined in Data.Attoparsec.Internal.Types | |
type State Text | |
Defined in Data.Attoparsec.Internal.Types type State Text = Buffer | |
type Item Text | |
withCString :: Text -> (CString -> IO a) -> IO a #
Marshal a Text
into a C string with a trailing NUL byte,
encoded as UTF-8 in temporary storage.
The temporary storage is freed when the subcomputation terminates (either normally or via an exception), so the pointer to the temporary storage must not be used after this function returns.
Since: text-2.0.1
vector
Storable
-based vectors.
Instances
NFData1 Vector | Since: vector-0.12.1.0 |
Defined in Data.Vector.Storable | |
Storable a => Vector Vector a | |
Defined in Data.Vector.Storable Methods basicUnsafeFreeze :: Mutable Vector s a -> ST s (Vector a) # basicUnsafeThaw :: Vector a -> ST s (Mutable Vector s a) # basicLength :: Vector a -> Int # basicUnsafeSlice :: Int -> Int -> Vector a -> Vector a # basicUnsafeIndexM :: Vector a -> Int -> Box a # basicUnsafeCopy :: Mutable Vector s a -> Vector a -> ST s () # | |
(Data a, Storable a) => Data (Vector a) | |
Defined in Data.Vector.Storable Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Vector a -> c (Vector a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Vector a) # toConstr :: Vector a -> Constr # dataTypeOf :: Vector a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Vector a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Vector a)) # gmapT :: (forall b. Data b => b -> b) -> Vector a -> Vector a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Vector a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Vector a -> r # gmapQ :: (forall d. Data d => d -> u) -> Vector a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Vector a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Vector a -> m (Vector a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Vector a -> m (Vector a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Vector a -> m (Vector a) # | |
Storable a => Monoid (Vector a) | |
Storable a => Semigroup (Vector a) | |
Storable a => IsList (Vector a) | |
(Read a, Storable a) => Read (Vector a) | |
(Show a, Storable a) => Show (Vector a) | |
NFData (Vector a) | |
Defined in Data.Vector.Storable | |
(Storable a, Eq a) => Eq (Vector a) | |
(Storable a, Ord a) => Ord (Vector a) | |
Defined in Data.Vector.Storable | |
Storable a => VecCtx (Vector a) | |
Defined in Language.C.Inline.Context Associated Types type VecCtxScalar (Vector a) # Methods vecCtxLength :: Vector a -> Int # vecCtxUnsafeWith :: Vector a -> (Ptr (VecCtxScalar (Vector a)) -> IO b) -> IO b # | |
type Mutable Vector | |
Defined in Data.Vector.Storable | |
type Item (Vector a) | |
Defined in Data.Vector.Storable | |
type VecCtxScalar (Vector a) | |
Defined in Language.C.Inline.Context |