phasechange-0.1: Freezing, thawing, and copy elision

Safe HaskellUnsafe

Data.PhaseChange.Unsafe

Contents

Description

This module provides functions on PhaseChangeable data which can break referential transparency if used incorrectly. For safe functions, see Data.PhaseChange. To write an instance, see Data.PhaseChange.Impl.

Synopsis

Unsafe functions

unsafeThaw :: (Immutable imm, MonadST mST, s ~ World mST) => imm -> mST (Thawed imm s)Source

Returns the input argument viewed as a mutable type. The input argument must not be used afterwards.

unsafeFreeze :: (Mutable mut, MonadST mST, s ~ World mST) => mut s -> mST (Frozen mut)Source

Returns the input argument viewed as an immutable type. The input argument must not be used afterwards.

readWith :: Immutable imm => (forall s. Thawed imm s -> ST s a) -> imm -> aSource

Read a value from immutable data with a reading-computation on mutable data. This function is referentially transparent as long as the computation does not mutate its input argument, but there is no way to enforce this.

Convenience functions for working with M1

unsafeThaw1 :: (PhaseChange (imm a) (M1 mut a), MonadST mST, s ~ World mST) => imm a -> mST (mut s a)Source

unsafeFreeze1 :: (PhaseChange (imm a) (M1 mut a), MonadST mST, s ~ World mST) => mut s a -> mST (imm a)Source

readWith1 :: PhaseChange (imm a) (M1 mut a) => (forall s. mut s a -> ST s b) -> imm a -> bSource

Convenience functions for working with M2

unsafeThaw2 :: (PhaseChange (imm a b) (M2 mut a b), MonadST mST, s ~ World mST) => imm a b -> mST (mut s a b)Source

unsafeFreeze2 :: (PhaseChange (imm a b) (M2 mut a b), MonadST mST, s ~ World mST) => mut s a b -> mST (imm a b)Source

readWith2 :: PhaseChange (imm a b) (M2 mut a b) => (forall s. mut s a b -> ST s c) -> imm a b -> cSource