scoped-codensity-0.1.0.0: CPS resource allocation but as a Monad and completely safe
Safe HaskellNone
LanguageHaskell2010

Control.Monad.Scoped.Ptr

Description

Working with Ptrs in a way that prevents use after free

>>> :set -XPostfixOperators
>>> import Control.Monad.Scoped.Internal
>>> scoped do x <- mut (69 :: Word); x .= 42; (x ?)
42
Synopsis

Documentation

type Ptr s a = ScopedResource s (Ptr a) Source #

A Ptr that is associated to a scope but it is mutable (can be read from and written to)

mut :: forall a (m :: Type -> Type) s (ss :: [Type]). (Storable a, MonadUnliftIO m) => a -> Scoped (s ': ss) m (Ptr s a) Source #

Acquire mutable memory for the duration of a scope. The value is automatically dropped at the end of the scope.

(.=) :: forall a (m :: Type -> Type) s (ss :: [Type]). (Storable a, MonadIO m, s :< ss) => Ptr s a -> a -> Scoped ss m () Source #

write a value to a pointer

(?) :: forall a (m :: Type -> Type) s (ss :: [Type]). (Storable a, MonadIO m, s :< ss) => Ptr s a -> Scoped ss m a Source #

read a value from a pointer