Copyright | (c) Alexey Kuleshevich 2020 |
---|---|
License | BSD3 |
Maintainer | Alexey Kuleshevich <alexey@kuleshevi.ch> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Synopsis
- class Prim a
- newtype Atom a = Atom {
- unAtom :: a
- class (Prim a, Eq a) => Atomic a
- class Atomic a => AtomicCount a
- class (Bits a, Atomic a) => AtomicBits a
- class MonadThrow m => MonadPrim s m | m -> s
- type RW = RealWorld
- data RealWorld :: Type
- byteCount :: forall a. Prim a => a -> Count Word8
- byteCountType :: forall a. Prim a => Count Word8
- byteCountProxy :: forall proxy a. Prim a => proxy a -> Count Word8
- alignment :: forall a. Prim a => a -> Int
- alignmentType :: forall a. Prim a => Int
- alignmentProxy :: forall proxy a. Prim a => proxy a -> Int
- newtype Size = Size {}
- newtype Count a = Count {}
- fromCount :: Prim a => Count a -> Int
- toByteCount :: Prim a => Count a -> Count Word8
- fromCount# :: Prim a => Count a -> Int#
- fromByteCount :: forall a. Prim a => Count Word8 -> Count a
- fromByteCountRem :: forall a. Prim a => Count Word8 -> (Count a, Count Word8)
- countAsProxy :: proxy a -> Count a -> Count a
- newtype Off a = Off {}
- toByteOff :: Prim e => Off e -> Off Word8
- fromOff# :: Prim a => Off a -> Int#
- fromByteOff :: forall a. Prim a => Off Word8 -> Off a
- fromByteOffRem :: forall a. Prim a => Off Word8 -> (Off a, Off Word8)
- offAsProxy :: proxy a -> Off a -> Off a
- prefetchValue0 :: MonadPrim s m => a -> m ()
- prefetchValue1 :: MonadPrim s m => a -> m ()
- prefetchValue2 :: MonadPrim s m => a -> m ()
- prefetchValue3 :: MonadPrim s m => a -> m ()
- module Data.Word
- module Data.Int
- data Ptr a
- data ForeignPtr a
- class Typeable (a :: k)
- data Proxy (t :: k) :: forall k. k -> Type = Proxy
- module Data.Monoid
- module Data.Coerce
Documentation
Invariants:
- Reading should never fail on memory that contains only zeros
- Writing should always overwrite all of the bytes allocated for the element. In other words, writing to a dirty (uninitilized) region of memory should never leave any garbage around. For example, if a type requires 31 bytes of memory then on any write all 31 bytes must be overwritten.
- A single thread write/read sequence must always roundtrip
- This is not a class for serialization, therefore memory layout of unpacked datatype
is selfcontained in
Prim
class and representation is not expected to stay the same between different versions of software. Primitive types likeInt
,Word
,Char
are an exception to this rule for obvious reasons.
Instances
Instances
class (Prim a, Eq a) => Atomic a Source #
Instances
class Atomic a => AtomicCount a Source #
Instances
class (Bits a, Atomic a) => AtomicBits a Source #
Instances
class MonadThrow m => MonadPrim s m | m -> s Source #
Instances
MonadPrim RealWorld IO Source # | |
MonadPrim s m => MonadPrim s (MaybeT m) Source # | |
MonadPrim s (ST s) Source # | |
MonadPrim s m => MonadPrim s (SelectT r m) Source # | |
(Monoid w, MonadPrim s m) => MonadPrim s (AccumT w m) Source # | |
(Monoid w, MonadPrim s m) => MonadPrim s (WriterT w m) Source # | |
(Monoid w, MonadPrim s m) => MonadPrim s (WriterT w m) Source # | |
MonadPrim s m => MonadPrim s (StateT st m) Source # | |
MonadPrim s m => MonadPrim s (StateT st m) Source # | |
MonadPrim s m => MonadPrim s (IdentityT m) Source # | |
MonadPrim s m => MonadPrim s (ExceptT e m) Source # | |
MonadPrim s m => MonadPrim s (ReaderT r m) Source # | |
MonadPrim s m => MonadPrim s (ContT r m) Source # | |
(Monoid w, MonadPrim s m) => MonadPrim s (RWST r w st m) Source # | |
(Monoid w, MonadPrim s m) => MonadPrim s (RWST r w st m) Source # | |
RealWorld
is deeply magical. It is primitive, but it is not
unlifted (hence ptrArg
). We never manipulate values of type
RealWorld
; it's only used in the type system, to parameterise State#
.
Instances
MonadPrim RealWorld IO Source # | |
MonadUnliftPrim RealWorld IO Source # | |
Defined in Control.Prim.Monad.Internal withRunInPrimBase :: MonadPrimBase RealWorld n => ((forall a. IO a -> n a) -> n b) -> IO b Source # | |
MonadPrimBase RealWorld IO Source # | |
Prim type size
byteCount :: forall a. Prim a => a -> Count Word8 Source #
Get the size of the data type in bytes. Argument is not evaluated.
byteCountType :: forall a. Prim a => Count Word8 Source #
Same as sizeOf
, except that the type can be supplied as a type level argument
>>>
:set -XTypeApplications
>>>
import Data.Prim
>>>
byteCountType @Int64
Count {unCount = 8}
byteCountProxy :: forall proxy a. Prim a => proxy a -> Count Word8 Source #
Same as sizeOf
, but argument is a Proxy
of a
, instead of the type itself.
>>>
import Data.Prim
>>>
import Data.Proxy
>>>
byteCountProxy (Proxy :: Proxy Int64)
Count {unCount = 8}
Prim type alignment
alignment :: forall a. Prim a => a -> Int Source #
Get the alignemnt of the type in bytes. Argument is not evaluated.
alignmentType :: forall a. Prim a => Int Source #
Same as alignment
, except that the type can be supplied with TypeApplications
>>>
:set -XTypeApplications
>>>
import Data.Prim
>>>
alignmentType @Int32
4
alignmentProxy :: forall proxy a. Prim a => proxy a -> Int Source #
Number of elements
Instances
countAsProxy :: proxy a -> Count a -> Count a Source #
Helper noop function that restricts Count
to the type of proxy
Since: 0.1.0
Offset in number of elements
Instances
toByteOff :: Prim e => Off e -> Off Word8 Source #
Compute byte offset from an offset of Prim
type
>>>
toByteOff (10 :: Off Word64)
Off {unOff = 80}
Since: 0.1.0
offAsProxy :: proxy a -> Off a -> Off a Source #
Helper noop function that restricts Off
set to the type of proxy
Since: 0.1.0
Prefetch
prefetchValue0 :: MonadPrim s m => a -> m () Source #
prefetchValue1 :: MonadPrim s m => a -> m () Source #
prefetchValue2 :: MonadPrim s m => a -> m () Source #
prefetchValue3 :: MonadPrim s m => a -> m () Source #
Re-export
module Data.Word
module Data.Int
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
data ForeignPtr a #
The type ForeignPtr
represents references to objects that are
maintained in a foreign language, i.e., that are not part of the
data structures usually managed by the Haskell storage manager.
The essential difference between ForeignPtr
s and vanilla memory
references of type Ptr a
is that the former may be associated
with finalizers. A finalizer is a routine that is invoked when
the Haskell storage manager detects that - within the Haskell heap
and stack - there are no more references left that are pointing to
the ForeignPtr
. Typically, the finalizer will, then, invoke
routines in the foreign language that free the resources bound by
the foreign object.
The ForeignPtr
is parameterised in the same way as Ptr
. The
type argument of ForeignPtr
should normally be an instance of
class Storable
.
Instances
Eq (ForeignPtr a) | Since: base-2.1 |
Defined in GHC.ForeignPtr (==) :: ForeignPtr a -> ForeignPtr a -> Bool # (/=) :: ForeignPtr a -> ForeignPtr a -> Bool # | |
Ord (ForeignPtr a) | Since: base-2.1 |
Defined in GHC.ForeignPtr compare :: ForeignPtr a -> ForeignPtr a -> Ordering # (<) :: ForeignPtr a -> ForeignPtr a -> Bool # (<=) :: ForeignPtr a -> ForeignPtr a -> Bool # (>) :: ForeignPtr a -> ForeignPtr a -> Bool # (>=) :: ForeignPtr a -> ForeignPtr a -> Bool # max :: ForeignPtr a -> ForeignPtr a -> ForeignPtr a # min :: ForeignPtr a -> ForeignPtr a -> ForeignPtr a # | |
Show (ForeignPtr a) | Since: base-2.1 |
Defined in GHC.ForeignPtr showsPrec :: Int -> ForeignPtr a -> ShowS # show :: ForeignPtr a -> String # showList :: [ForeignPtr a] -> ShowS # |
The class Typeable
allows a concrete representation of a type to
be calculated.
typeRep#
data Proxy (t :: k) :: forall k. k -> Type #
Proxy
is a type that holds no data, but has a phantom parameter of
arbitrary type (or even kind). Its use is to provide type information, even
though there is no value available of that type (or it may be too costly to
create one).
Historically,
is a safer alternative to the
Proxy
:: Proxy
a'undefined :: a'
idiom.
>>>
Proxy :: Proxy (Void, Int -> Int)
Proxy
Proxy can even hold types of higher kinds,
>>>
Proxy :: Proxy Either
Proxy
>>>
Proxy :: Proxy Functor
Proxy
>>>
Proxy :: Proxy complicatedStructure
Proxy
Instances
Generic1 (Proxy :: k -> Type) | |
Monad (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Functor (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Applicative (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Foldable (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Defined in Data.Foldable fold :: Monoid m => Proxy m -> m # foldMap :: Monoid m => (a -> m) -> Proxy a -> m # foldr :: (a -> b -> b) -> b -> Proxy a -> b # foldr' :: (a -> b -> b) -> b -> Proxy a -> b # foldl :: (b -> a -> b) -> b -> Proxy a -> b # foldl' :: (b -> a -> b) -> b -> Proxy a -> b # foldr1 :: (a -> a -> a) -> Proxy a -> a # foldl1 :: (a -> a -> a) -> Proxy a -> a # elem :: Eq a => a -> Proxy a -> Bool # maximum :: Ord a => Proxy a -> a # minimum :: Ord a => Proxy a -> a # | |
Traversable (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Eq1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Ord1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
Read1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
Show1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Alternative (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
MonadPlus (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
NFData1 (Proxy :: Type -> Type) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
Bounded (Proxy t) | Since: base-4.7.0.0 |
Enum (Proxy s) | Since: base-4.7.0.0 |
Eq (Proxy s) | Since: base-4.7.0.0 |
Ord (Proxy s) | Since: base-4.7.0.0 |
Read (Proxy t) | Since: base-4.7.0.0 |
Show (Proxy s) | Since: base-4.7.0.0 |
Ix (Proxy s) | Since: base-4.7.0.0 |
Generic (Proxy t) | |
Semigroup (Proxy s) | Since: base-4.9.0.0 |
Monoid (Proxy s) | Since: base-4.7.0.0 |
NFData (Proxy a) | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
type Rep1 (Proxy :: k -> Type) | Since: base-4.6.0.0 |
type Rep (Proxy t) | Since: base-4.6.0.0 |
module Data.Monoid
module Data.Coerce