foundation-0.0.30: Alternative prelude with batteries and no dependencies

License | BSD-style
Maintainer | Haskell Foundation
Stability | experimental
Portability | portable
Safe Haskell | None
Language | Haskell2010

Foundation.Class.Storable

Contents

- Ptr
- offset based helper
- Collection

Description

https://github.com/haskell-foundation/issues/111

Synopsis

- class Storable a where
  - peek :: Ptr a -> IO a
  - poke :: Ptr a -> a -> IO ()
- class Storable a => StorableFixed a where
  - size :: proxy a -> CountOf Word8
  - alignment :: proxy a -> CountOf Word8
- data Ptr a
- plusPtr :: StorableFixed a => Ptr a -> CountOf a -> Ptr a
- castPtr :: Ptr a -> Ptr b
- peekOff :: StorableFixed a => Ptr a -> Offset a -> IO a
- pokeOff :: StorableFixed a => Ptr a -> Offset a -> a -> IO ()
- peekArray :: (Buildable col, StorableFixed (Element col)) => CountOf (Element col) -> Ptr (Element col) -> IO col
- peekArrayEndedBy :: (Buildable col, StorableFixed (Element col), Eq (Element col), Show (Element col)) => Element col -> Ptr (Element col) -> IO col
- pokeArray :: (Sequential col, StorableFixed (Element col)) => Ptr (Element col) -> col -> IO ()
- pokeArrayEndedBy :: (Sequential col, StorableFixed (Element col)) => Element col -> Ptr (Element col) -> col -> IO ()

# Documentation

class Storable a where #

Storable type of self determined size.

Methods

peek :: Ptr a -> IO a #

poke :: Ptr a -> a -> IO () #

#### Instances

Instances details

Storable Word128 # |
Instance details Defined in Foundation.Class.Storable Methods peek :: Ptr Word128 -> IO Word128 # poke :: Ptr Word128 -> Word128 -> IO () #
Storable Word256 # |
Instance details Defined in Foundation.Class.Storable Methods peek :: Ptr Word256 -> IO Word256 # poke :: Ptr Word256 -> Word256 -> IO () #
Storable IPv4 # |
Instance details Defined in Foundation.Network.IPv4 Methods peek :: Ptr IPv4 -> IO IPv4 # poke :: Ptr IPv4 -> IPv4 -> IO () #
Storable IPv6 # |
Instance details Defined in Foundation.Network.IPv6 Methods peek :: Ptr IPv6 -> IO IPv6 # poke :: Ptr IPv6 -> IPv6 -> IO () #
Storable UUID # |
Instance details Defined in Foundation.UUID Methods peek :: Ptr UUID -> IO UUID # poke :: Ptr UUID -> UUID -> IO () #
Storable CChar # |
Instance details Defined in Foundation.Class.Storable Methods peek :: Ptr CChar -> IO CChar # poke :: Ptr CChar -> CChar -> IO () #
Storable CUChar # |
Instance details Defined in Foundation.Class.Storable Methods peek :: Ptr CUChar -> IO CUChar # poke :: Ptr CUChar -> CUChar -> IO () #
Storable Int16 # |
Instance details Defined in Foundation.Class.Storable Methods peek :: Ptr Int16 -> IO Int16 # poke :: Ptr Int16 -> Int16 -> IO () #
Storable Int32 # |
Instance details Defined in Foundation.Class.Storable Methods peek :: Ptr Int32 -> IO Int32 # poke :: Ptr Int32 -> Int32 -> IO () #
Storable Int64 # |
Instance details Defined in Foundation.Class.Storable Methods peek :: Ptr Int64 -> IO Int64 # poke :: Ptr Int64 -> Int64 -> IO () #
Storable Int8 # |
Instance details Defined in Foundation.Class.Storable Methods peek :: Ptr Int8 -> IO Int8 # poke :: Ptr Int8 -> Int8 -> IO () #
Storable Word16 # |
Instance details Defined in Foundation.Class.Storable Methods peek :: Ptr Word16 -> IO Word16 # poke :: Ptr Word16 -> Word16 -> IO () #
Storable Word32 # |
Instance details Defined in Foundation.Class.Storable Methods peek :: Ptr Word32 -> IO Word32 # poke :: Ptr Word32 -> Word32 -> IO () #
Storable Word64 # |
Instance details Defined in Foundation.Class.Storable Methods peek :: Ptr Word64 -> IO Word64 # poke :: Ptr Word64 -> Word64 -> IO () #
Storable Word8 # |
Instance details Defined in Foundation.Class.Storable Methods peek :: Ptr Word8 -> IO Word8 # poke :: Ptr Word8 -> Word8 -> IO () #
Storable Char # |
Instance details Defined in Foundation.Class.Storable Methods peek :: Ptr Char -> IO Char # poke :: Ptr Char -> Char -> IO () #
Storable Double # |
Instance details Defined in Foundation.Class.Storable Methods peek :: Ptr Double -> IO Double # poke :: Ptr Double -> Double -> IO () #
Storable Float # |
Instance details Defined in Foundation.Class.Storable Methods peek :: Ptr Float -> IO Float # poke :: Ptr Float -> Float -> IO () #
Storable (BE Word128) # |
Instance details Defined in Foundation.Class.Storable Methods peek :: Ptr (BE Word128) -> IO (BE Word128) # poke :: Ptr (BE Word128) -> BE Word128 -> IO () #
Storable (BE Word256) # |
Instance details Defined in Foundation.Class.Storable Methods peek :: Ptr (BE Word256) -> IO (BE Word256) # poke :: Ptr (BE Word256) -> BE Word256 -> IO () #
Storable (BE Word16) # |
Instance details Defined in Foundation.Class.Storable Methods peek :: Ptr (BE Word16) -> IO (BE Word16) # poke :: Ptr (BE Word16) -> BE Word16 -> IO () #
Storable (BE Word32) # |
Instance details Defined in Foundation.Class.Storable Methods peek :: Ptr (BE Word32) -> IO (BE Word32) # poke :: Ptr (BE Word32) -> BE Word32 -> IO () #
Storable (BE Word64) # |
Instance details Defined in Foundation.Class.Storable Methods peek :: Ptr (BE Word64) -> IO (BE Word64) # poke :: Ptr (BE Word64) -> BE Word64 -> IO () #
Storable (LE Word128) # |
Instance details Defined in Foundation.Class.Storable Methods peek :: Ptr (LE Word128) -> IO (LE Word128) # poke :: Ptr (LE Word128) -> LE Word128 -> IO () #
Storable (LE Word256) # |
Instance details Defined in Foundation.Class.Storable Methods peek :: Ptr (LE Word256) -> IO (LE Word256) # poke :: Ptr (LE Word256) -> LE Word256 -> IO () #
Storable (LE Word16) # |
Instance details Defined in Foundation.Class.Storable Methods peek :: Ptr (LE Word16) -> IO (LE Word16) # poke :: Ptr (LE Word16) -> LE Word16 -> IO () #
Storable (LE Word32) # |
Instance details Defined in Foundation.Class.Storable Methods peek :: Ptr (LE Word32) -> IO (LE Word32) # poke :: Ptr (LE Word32) -> LE Word32 -> IO () #
Storable (LE Word64) # |
Instance details Defined in Foundation.Class.Storable Methods peek :: Ptr (LE Word64) -> IO (LE Word64) # poke :: Ptr (LE Word64) -> LE Word64 -> IO () #
Storable (Ptr a) # |
Instance details Defined in Foundation.Class.Storable Methods peek :: Ptr (Ptr a) -> IO (Ptr a) # poke :: Ptr (Ptr a) -> Ptr a -> IO () #

class Storable a => StorableFixed a where #

Extending the Storable type class to the types that can be sequenced in a structure.

Methods

size :: proxy a -> CountOf Word8 #

alignment :: proxy a -> CountOf Word8 #

#### Instances

Instances details

StorableFixed Word128 # |
Instance details Defined in Foundation.Class.Storable Methods size :: proxy Word128 -> CountOf Word8 # alignment :: proxy Word128 -> CountOf Word8 #
StorableFixed Word256 # |
Instance details Defined in Foundation.Class.Storable Methods size :: proxy Word256 -> CountOf Word8 # alignment :: proxy Word256 -> CountOf Word8 #
StorableFixed IPv4 # |
Instance details Defined in Foundation.Network.IPv4 Methods size :: proxy IPv4 -> CountOf Word8 # alignment :: proxy IPv4 -> CountOf Word8 #
StorableFixed IPv6 # |
Instance details Defined in Foundation.Network.IPv6 Methods size :: proxy IPv6 -> CountOf Word8 # alignment :: proxy IPv6 -> CountOf Word8 #
StorableFixed UUID # |
Instance details Defined in Foundation.UUID Methods size :: proxy UUID -> CountOf Word8 # alignment :: proxy UUID -> CountOf Word8 #
StorableFixed CChar # |
Instance details Defined in Foundation.Class.Storable Methods size :: proxy CChar -> CountOf Word8 # alignment :: proxy CChar -> CountOf Word8 #
StorableFixed CUChar # |
Instance details Defined in Foundation.Class.Storable Methods size :: proxy CUChar -> CountOf Word8 # alignment :: proxy CUChar -> CountOf Word8 #
StorableFixed Int16 # |
Instance details Defined in Foundation.Class.Storable Methods size :: proxy Int16 -> CountOf Word8 # alignment :: proxy Int16 -> CountOf Word8 #
StorableFixed Int32 # |
Instance details Defined in Foundation.Class.Storable Methods size :: proxy Int32 -> CountOf Word8 # alignment :: proxy Int32 -> CountOf Word8 #
StorableFixed Int64 # |
Instance details Defined in Foundation.Class.Storable Methods size :: proxy Int64 -> CountOf Word8 # alignment :: proxy Int64 -> CountOf Word8 #
StorableFixed Int8 # |
Instance details Defined in Foundation.Class.Storable Methods size :: proxy Int8 -> CountOf Word8 # alignment :: proxy Int8 -> CountOf Word8 #
StorableFixed Word16 # |
Instance details Defined in Foundation.Class.Storable Methods size :: proxy Word16 -> CountOf Word8 # alignment :: proxy Word16 -> CountOf Word8 #
StorableFixed Word32 # |
Instance details Defined in Foundation.Class.Storable Methods size :: proxy Word32 -> CountOf Word8 # alignment :: proxy Word32 -> CountOf Word8 #
StorableFixed Word64 # |
Instance details Defined in Foundation.Class.Storable Methods size :: proxy Word64 -> CountOf Word8 # alignment :: proxy Word64 -> CountOf Word8 #
StorableFixed Word8 # |
Instance details Defined in Foundation.Class.Storable Methods size :: proxy Word8 -> CountOf Word8 # alignment :: proxy Word8 -> CountOf Word8 #
StorableFixed Char # |
Instance details Defined in Foundation.Class.Storable Methods size :: proxy Char -> CountOf Word8 # alignment :: proxy Char -> CountOf Word8 #
StorableFixed Double # |
Instance details Defined in Foundation.Class.Storable Methods size :: proxy Double -> CountOf Word8 # alignment :: proxy Double -> CountOf Word8 #
StorableFixed Float # |
Instance details Defined in Foundation.Class.Storable Methods size :: proxy Float -> CountOf Word8 # alignment :: proxy Float -> CountOf Word8 #
StorableFixed (BE Word128) # |
Instance details Defined in Foundation.Class.Storable Methods size :: proxy (BE Word128) -> CountOf Word8 # alignment :: proxy (BE Word128) -> CountOf Word8 #
StorableFixed (BE Word256) # |
Instance details Defined in Foundation.Class.Storable Methods size :: proxy (BE Word256) -> CountOf Word8 # alignment :: proxy (BE Word256) -> CountOf Word8 #
StorableFixed (BE Word16) # |
Instance details Defined in Foundation.Class.Storable Methods size :: proxy (BE Word16) -> CountOf Word8 # alignment :: proxy (BE Word16) -> CountOf Word8 #
StorableFixed (BE Word32) # |
Instance details Defined in Foundation.Class.Storable Methods size :: proxy (BE Word32) -> CountOf Word8 # alignment :: proxy (BE Word32) -> CountOf Word8 #
StorableFixed (BE Word64) # |
Instance details Defined in Foundation.Class.Storable Methods size :: proxy (BE Word64) -> CountOf Word8 # alignment :: proxy (BE Word64) -> CountOf Word8 #
StorableFixed (LE Word128) # |
Instance details Defined in Foundation.Class.Storable Methods size :: proxy (LE Word128) -> CountOf Word8 # alignment :: proxy (LE Word128) -> CountOf Word8 #
StorableFixed (LE Word256) # |
Instance details Defined in Foundation.Class.Storable Methods size :: proxy (LE Word256) -> CountOf Word8 # alignment :: proxy (LE Word256) -> CountOf Word8 #
StorableFixed (LE Word16) # |
Instance details Defined in Foundation.Class.Storable Methods size :: proxy (LE Word16) -> CountOf Word8 # alignment :: proxy (LE Word16) -> CountOf Word8 #
StorableFixed (LE Word32) # |
Instance details Defined in Foundation.Class.Storable Methods size :: proxy (LE Word32) -> CountOf Word8 # alignment :: proxy (LE Word32) -> CountOf Word8 #
StorableFixed (LE Word64) # |
Instance details Defined in Foundation.Class.Storable Methods size :: proxy (LE Word64) -> CountOf Word8 # alignment :: proxy (LE Word64) -> CountOf Word8 #
StorableFixed (Ptr a) # |
Instance details Defined in Foundation.Class.Storable Methods size :: proxy (Ptr a) -> CountOf Word8 # alignment :: proxy (Ptr a) -> CountOf Word8 #

# Ptr

data Ptr a #

A value of type ``Ptr` a` represents a pointer to an object, or an array of objects, which may be marshalled to or from Haskell values of type `a`.

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

Instances details

Generic1 (URec (Ptr ()) :: k -> Type) |
Instance details Defined in GHC.Internal.Generics Associated Types
type Rep1 (URec (Ptr ()) :: k -> Type) | @since base-4.9.0.0
Instance details Defined in GHC.Internal.Generics type Rep1 (URec (Ptr ()) :: k -> Type) = D1 ('MetaData "URec" "GHC.Internal.Generics" "ghc-internal" 'False) (C1 ('MetaCons "UAddr" 'PrefixI 'True) (S1 ('MetaSel ('Just "uAddr#") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (UAddr :: k -> Type)))
Methods from1 :: forall (a :: k). URec (Ptr ()) a -> Rep1 (URec (Ptr ()) :: k -> Type) a # to1 :: forall (a :: k). Rep1 (URec (Ptr ()) :: k -> Type) a -> URec (Ptr ()) a #
NormalForm (Ptr a) |
Instance details Defined in Basement.NormalForm Methods toNormalForm :: Ptr a -> () #
Storable (Ptr a) # |
Instance details Defined in Foundation.Class.Storable Methods peek :: Ptr (Ptr a) -> IO (Ptr a) # poke :: Ptr (Ptr a) -> Ptr a -> IO () #
StorableFixed (Ptr a) # |
Instance details Defined in Foundation.Class.Storable Methods size :: proxy (Ptr a) -> CountOf Word8 # alignment :: proxy (Ptr a) -> CountOf Word8 #
Data a => Data (Ptr a) | @since base-4.8.0.0
Instance details Defined in GHC.Internal.Data.Data Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Ptr a -> c (Ptr a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Ptr a) # toConstr :: Ptr a -> Constr # dataTypeOf :: Ptr a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Ptr a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Ptr a)) # gmapT :: (forall b. Data b => b -> b) -> Ptr a -> Ptr a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ptr a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Ptr a -> r # gmapQ :: (forall d. Data d => d -> u) -> Ptr a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Ptr a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Ptr a -> m (Ptr a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Ptr a -> m (Ptr a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Ptr a -> m (Ptr a) #
Foldable (UAddr :: Type -> Type) | @since base-4.9.0.0
Instance details Defined in GHC.Internal.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 # toList :: UAddr a -> [a] # null :: UAddr a -> Bool # length :: UAddr a -> Int # elem :: Eq a => a -> UAddr a -> Bool # maximum :: Ord a => UAddr a -> a # minimum :: Ord a => UAddr a -> a # sum :: Num a => UAddr a -> a # product :: Num a => UAddr a -> a #
Traversable (UAddr :: Type -> Type) | @since base-4.9.0.0
Instance details Defined in GHC.Internal.Data.Traversable Methods traverse :: Applicative f => (a -> f b) -> UAddr a -> f (UAddr b) # sequenceA :: Applicative f => UAddr (f a) -> f (UAddr a) # mapM :: Monad m => (a -> m b) -> UAddr a -> m (UAddr b) # sequence :: Monad m => UAddr (m a) -> m (UAddr a) #
Storable (Ptr a) | @since base-2.01
Instance details Defined in GHC.Internal.Foreign.Storable Methods sizeOf :: Ptr a -> Int # alignment :: Ptr a -> Int # peekElemOff :: Ptr (Ptr a) -> Int -> IO (Ptr a) # pokeElemOff :: Ptr (Ptr a) -> Int -> Ptr a -> IO () # peekByteOff :: Ptr b -> Int -> IO (Ptr a) # pokeByteOff :: Ptr b -> Int -> Ptr a -> IO () # peek :: Ptr (Ptr a) -> IO (Ptr a) # poke :: Ptr (Ptr a) -> Ptr a -> IO () #
Show (Ptr a) | @since base-2.01
Instance details Defined in GHC.Internal.Ptr Methods showsPrec :: Int -> Ptr a -> ShowS # show :: Ptr a -> String # showList :: [Ptr a] -> ShowS #
Eq (Ptr a) | @since base-2.01
Instance details Defined in GHC.Internal.Ptr Methods (==) :: Ptr a -> Ptr a -> Bool # (/=) :: Ptr a -> Ptr a -> Bool #
Ord (Ptr a) | @since base-2.01
Instance details Defined in GHC.Internal.Ptr Methods compare :: Ptr a -> Ptr a -> Ordering # (<) :: Ptr a -> Ptr a -> Bool # (<=) :: Ptr a -> Ptr a -> Bool # (>) :: Ptr a -> Ptr a -> Bool # (>=) :: Ptr a -> Ptr a -> Bool # max :: Ptr a -> Ptr a -> Ptr a # min :: Ptr a -> Ptr a -> Ptr a #
Functor (URec (Ptr ()) :: Type -> Type) | @since base-4.9.0.0
Instance details Defined in GHC.Internal.Generics Methods fmap :: (a -> b) -> URec (Ptr ()) a -> URec (Ptr ()) b # (<$) :: a -> URec (Ptr ()) b -> URec (Ptr ()) a #
Generic (URec (Ptr ()) p) |
Instance details Defined in GHC.Internal.Generics Associated Types
type Rep (URec (Ptr ()) p) | @since base-4.9.0.0
Instance details Defined in GHC.Internal.Generics type Rep (URec (Ptr ()) p) = D1 ('MetaData "URec" "GHC.Internal.Generics" "ghc-internal" 'False) (C1 ('MetaCons "UAddr" 'PrefixI 'True) (S1 ('MetaSel ('Just "uAddr#") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (UAddr :: Type -> Type)))
Methods from :: URec (Ptr ()) p -> Rep (URec (Ptr ()) p) x # to :: Rep (URec (Ptr ()) p) x -> URec (Ptr ()) p #
Eq (URec (Ptr ()) p) | @since base-4.9.0.0
Instance details Defined in GHC.Internal.Generics Methods (==) :: URec (Ptr ()) p -> URec (Ptr ()) p -> Bool # (/=) :: URec (Ptr ()) p -> URec (Ptr ()) p -> Bool #
Ord (URec (Ptr ()) p) | @since base-4.9.0.0
Instance details Defined in GHC.Internal.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 `Addr#` @since base-4.9.0.0
Instance details Defined in GHC.Internal.Generics data URec (Ptr ()) (p :: k) = UAddr { uAddr# :: Addr# }
type Rep1 (URec (Ptr ()) :: k -> Type) | @since base-4.9.0.0
Instance details Defined in GHC.Internal.Generics type Rep1 (URec (Ptr ()) :: k -> Type) = D1 ('MetaData "URec" "GHC.Internal.Generics" "ghc-internal" 'False) (C1 ('MetaCons "UAddr" 'PrefixI 'True) (S1 ('MetaSel ('Just "uAddr#") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (UAddr :: k -> Type)))
type Rep (URec (Ptr ()) p) | @since base-4.9.0.0
Instance details Defined in GHC.Internal.Generics type Rep (URec (Ptr ()) p) = D1 ('MetaData "URec" "GHC.Internal.Generics" "ghc-internal" 'False) (C1 ('MetaCons "UAddr" 'PrefixI 'True) (S1 ('MetaSel ('Just "uAddr#") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (UAddr :: Type -> Type)))

plusPtr :: StorableFixed a => Ptr a -> CountOf a -> Ptr a #

castPtr :: Ptr a -> Ptr b #

The `castPtr` function casts a pointer from one type to another.

# offset based helper

peekOff :: StorableFixed a => Ptr a -> Offset a -> IO a #

like `peek` but at a given offset.

pokeOff :: StorableFixed a => Ptr a -> Offset a -> a -> IO () #

like `poke` but at a given offset.

# Collection

peekArray :: (Buildable col, StorableFixed (Element col)) => CountOf (Element col) -> Ptr (Element col) -> IO col #

peekArrayEndedBy :: (Buildable col, StorableFixed (Element col), Eq (Element col), Show (Element col)) => Element col -> Ptr (Element col) -> IO col #

pokeArray :: (Sequential col, StorableFixed (Element col)) => Ptr (Element col) -> col -> IO () #

pokeArrayEndedBy :: (Sequential col, StorableFixed (Element col)) => Element col -> Ptr (Element col) -> col -> IO () #