| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Control.Monad.Borrow.Pure.BO
Description
This module provides all the safe API of BO monad, including the advanced, low-level combinators that are not meant to be used by most users.
For the conceptual overview, please refer to Control.Monad.Borrow.Pure, which is the prelude of this package.
Synopsis
- data BO (α :: Lifetime) a
- execBO :: forall (α :: Lifetime) a. BO α a %1 -> Now α %1 -> (Now α, a)
- runBO :: Linearly %1 -> (forall (α :: Lifetime). BO α (After α a)) %1 -> a
- runBOLend :: Linearly %1 -> (forall (α :: Lifetime). BO α (Lend α a)) %1 -> a
- runBO_ :: Linearly %1 -> (forall (α :: Lifetime). BO α a) %1 -> a
- sexecBO :: forall (α :: Lifetime) (β :: Lifetime) a. BO (α /\ β) a %1 -> Now α %1 -> BO β (Now α, a)
- scope_ :: forall (α :: Lifetime) (β :: Lifetime) a. Now α %1 -> BO (α /\ β) a %1 -> BO β (Now α, a)
- srunBO :: forall (β :: Lifetime) a. (forall (α :: Lifetime). BO (α /\ β) (After α a)) %1 -> BO β a
- srunBO_ :: forall (β :: Lifetime) a. (forall (α :: Lifetime). BO (α /\ β) a) %1 -> BO β a
- askLinearly :: forall (α :: Lifetime). BO α Linearly
- asksLinearly :: forall r (α :: Lifetime). (Linearly %1 -> r) %1 -> BO α r
- asksLinearlyM :: forall (α :: Lifetime) r. (Linearly %1 -> BO α r) %1 -> BO α r
- evaluateBO :: forall a (α :: Lifetime). a %1 -> BO α a
- modifyBO :: a %1 -> Linearly %1 -> (forall (α :: Lifetime). Mut α a %1 -> BO α r) %1 -> (r, a)
- modifyBO_ :: a %1 -> Linearly %1 -> (forall (α :: Lifetime). Mut α a %1 -> BO α ()) %1 -> a
- modifyLinearOnlyBO :: LinearOnly a => a %1 -> (forall (α :: Lifetime). Mut α a %1 -> BO α r) %1 -> (r, a)
- modifyLinearOnlyBO_ :: LinearOnly a => a %1 -> (forall (α :: Lifetime). Mut α a %1 -> BO α ()) %1 -> a
- parBO :: forall (α :: Lifetime) a b. BO α a %1 -> BO α b %1 -> BO α (a, b)
- data Alias (ak :: AliasKind) (α :: Lifetime) a
- data AliasKind
- data BorrowKind
- type Borrow (bk :: BorrowKind) = Alias ('Borrow bk)
- type Mut = Borrow 'Mut
- type Share = Borrow 'Share
- type Lend = Alias 'Lend
- coerceShare :: forall b (α :: Lifetime) a. Coercible a b => Share α a %1 -> Share α b
- shareCoercion :: forall a b (α :: Lifetime). Coercible a b => Coercion (Share α a) (Share α b)
- borrowM :: forall a (α :: Lifetime). a %1 -> BO α (Mut α a, Lend α a)
- borrowLinearlyM :: forall a (α :: Lifetime). (Linearly %1 -> a) %1 -> BO α (Mut α a, Lend α a)
- sharing' :: forall (α :: Lifetime) a (α' :: Lifetime) r. Mut α a %1 -> (forall (β :: Lifetime). Share (β /\ α) a -> BO (β /\ α') (After β r)) %1 -> BO α' (r, Mut α a)
- sharing :: forall (α :: Lifetime) (α' :: Lifetime) a r. Mut α a %1 -> (forall (β :: Lifetime). Share (β /\ α) a -> BO (β /\ α') r) %1 -> BO α' (r, Mut α a)
- (<$~) :: forall (α :: Lifetime) a (α' :: Lifetime) r. (forall (β :: Lifetime). Share (β /\ α) a -> BO (β /\ α') r) %1 -> Mut α a %1 -> BO α' (r, Mut α a)
- sharing_ :: forall (α :: Lifetime) (α' :: Lifetime) a r. Consumable r => Mut α a %1 -> (forall (β :: Lifetime). Share (β /\ α) a -> BO (β /\ α') r) %1 -> BO α' (Mut α a)
- (<$=) :: forall (α :: Lifetime) a (α' :: Lifetime). (forall (β :: Lifetime). Share (β /\ α) a -> BO (β /\ α') ()) %1 -> Mut α a %1 -> BO α' (Mut α a)
- reborrowing' :: forall (α :: Lifetime) a (α' :: Lifetime) r. Mut α a %1 -> (forall (β :: Lifetime). Mut (β /\ α) a %1 -> BO (β /\ α') (After β r)) %1 -> BO α' (r, Mut α a)
- reborrowing :: forall (α :: Lifetime) a (α' :: Lifetime) r. Mut α a %1 -> (forall (β :: Lifetime). Mut (β /\ α) a %1 -> BO (β /\ α') r) %1 -> BO α' (r, Mut α a)
- (<%~) :: forall (α :: Lifetime) a (α' :: Lifetime) r. (forall (β :: Lifetime). Mut (β /\ α) a %1 -> BO (β /\ α') r) %1 -> Mut α a %1 -> BO α' (r, Mut α a)
- reborrowing_ :: forall r (α :: Lifetime) a (α' :: Lifetime). Consumable r => Mut α a %1 -> (forall (β :: Lifetime). Mut (β /\ α) a %1 -> BO (β /\ α') r) %1 -> BO α' (Mut α a)
- (<%=) :: forall (α :: Lifetime) a (α' :: Lifetime). (forall (β :: Lifetime). Mut (β /\ α) a %1 -> BO (β /\ α') ()) %1 -> Mut α a %1 -> BO α' (Mut α a)
- share :: forall (k :: BorrowKind) (α :: Lifetime) a. Borrow k α a %1 -> Ur (Share α a)
- reclaim' :: forall (α :: Lifetime) a. Lend α a %1 -> After α a
- reclaim :: forall (α :: Lifetime) a. End α => Lend α a %1 -> a
- pureAfter :: forall (α :: Lifetime) a. (End α => a) %1 -> BO α (After α a)
- reborrow :: forall (β :: Lifetime) (α :: Lifetime) a. α >= β => Mut α a %1 -> (Mut β a, Lend β (Mut α a))
- joinMut :: forall (bk :: BorrowKind) (α :: Lifetime) (β :: Lifetime) a. Borrow bk α (Mut β a) %1 -> Borrow bk (α /\ β) a
- joinLend :: forall (α :: Lifetime) a. Lend α (Lend α a) %1 -> Lend α a
- borrow :: forall (α :: Lifetime) a. a %1 -> Linearly %1 -> (Mut α a, Lend α a)
- borrowLinearOnly :: forall (α :: Lifetime) a. LinearOnly a => a %1 -> (Mut α a, Lend α a)
- class DistributesAlias (f :: Type -> Type)
- split :: forall f x (ak :: AliasKind) (α :: Lifetime). DistributesAlias f => Alias ak α (f x) %1 -> f (Alias ak α x)
- type GenericDistributesAlias (f :: Type -> Type) = (Generic1 f, GDistributeAlias (Rep1 f))
- genericSplit :: forall f x (ak :: AliasKind) (α :: Lifetime). GenericDistributesAlias f => Alias ak α (f x) %1 -> f (Alias ak α x)
- splitPair :: forall (ak :: AliasKind) (α :: Lifetime) a b. Alias ak α (a, b) %1 -> (Alias ak α a, Alias ak α b)
- splitEither :: forall (ak :: AliasKind) (α :: Lifetime) a b. Alias ak α (Either a b) %1 -> Either (Alias ak α a) (Alias ak α b)
- assocRBO :: forall (α :: Lifetime) (β :: Lifetime) (γ :: Lifetime) a. BO ((α /\ β) /\ γ) a %1 -> BO (α /\ (β /\ γ)) a
- assocLBO :: forall (α :: Lifetime) (β :: Lifetime) (γ :: Lifetime) a. BO (α /\ (β /\ γ)) a %1 -> BO ((α /\ β) /\ γ) a
- assocBOEq :: forall (α :: Lifetime) (β :: Lifetime) (γ :: Lifetime) a. BO ((α /\ β) /\ γ) a :~: BO (α /\ (β /\ γ)) a
- assocBorrowL :: forall (bk :: BorrowKind) (α :: Lifetime) (β :: Lifetime) (γ :: Lifetime) a. Borrow bk (α /\ (β /\ γ)) a %1 -> Borrow bk ((α /\ β) /\ γ) a
- assocBorrowR :: forall (bk :: BorrowKind) (α :: Lifetime) (β :: Lifetime) (γ :: Lifetime) a. Borrow bk ((α /\ β) /\ γ) a %1 -> Borrow bk (α /\ (β /\ γ)) a
- assocBorrowEq :: forall (bk :: BorrowKind) (α :: Lifetime) (β :: Lifetime) (γ :: Lifetime) a. Borrow bk ((α /\ β) /\ γ) a :~: Borrow bk (α /\ (β /\ γ)) a
- assocLendL :: forall (α :: Lifetime) (β :: Lifetime) (γ :: Lifetime) a. Lend (α /\ (β /\ γ)) a %1 -> Lend ((α /\ β) /\ γ) a
- assocLendR :: forall (α :: Lifetime) (β :: Lifetime) (γ :: Lifetime) a. Lend ((α /\ β) /\ γ) a %1 -> Lend (α /\ (β /\ γ)) a
- assocLendEq :: forall (α :: Lifetime) (β :: Lifetime) (γ :: Lifetime) a. Lend ((α /\ β) /\ γ) a :~: Lend (α /\ (β /\ γ)) a
- module Control.Monad.Borrow.Pure.Lifetime
- module Control.Monad.Borrow.Pure.Lifetime.Token
- module Data.Coerce.Directed
Core BO monad
data BO (α :: Lifetime) a Source #
Computation returning a that can be performed only during the lifetime α.
Internally it is a linear ST monad.
Instances
| (α >= β, a <: b) => (BO α a :: Type) <: (BO β b :: Type) Source # | |
Defined in Control.Monad.Borrow.Pure.BO.Internal | |
| Applicative (BO α) Source # | |
| Functor (BO α) Source # | |
Defined in Control.Monad.Borrow.Pure.BO.Internal | |
| Monad (BO α) Source # | |
| Applicative (BO α) Source # | |
| Functor (BO α) Source # | |
Defined in Control.Monad.Borrow.Pure.BO.Internal | |
| Monoid w => Monoid (BO α w) Source # | |
Defined in Control.Monad.Borrow.Pure.BO.Internal | |
| Semigroup w => Semigroup (BO α w) Source # | |
sexecBO :: forall (α :: Lifetime) (β :: Lifetime) a. BO (α /\ β) a %1 -> Now α %1 -> BO β (Now α, a) Source #
See also scope.
scope_ :: forall (α :: Lifetime) (β :: Lifetime) a. Now α %1 -> BO (α /\ β) a %1 -> BO β (Now α, a) Source #
Flipped version of sexecBO.
srunBO :: forall (β :: Lifetime) a. (forall (α :: Lifetime). BO (α /\ β) (After α a)) %1 -> BO β a Source #
Runs a BO computation within the ephemeral sublifetime and returns the result.
evaluateBO :: forall a (α :: Lifetime). a %1 -> BO α a Source #
In-place modification with mutable borrows
modifyBO :: a %1 -> Linearly %1 -> (forall (α :: Lifetime). Mut α a %1 -> BO α r) %1 -> (r, a) Source #
Modifies linear resources in-place, together with results.
modifyBO_ :: a %1 -> Linearly %1 -> (forall (α :: Lifetime). Mut α a %1 -> BO α ()) %1 -> a Source #
Modifies linear resources in-place, without results.
modifyLinearOnlyBO :: LinearOnly a => a %1 -> (forall (α :: Lifetime). Mut α a %1 -> BO α r) %1 -> (r, a) Source #
Modifies linear resources in-place, together with results.
modifyLinearOnlyBO_ :: LinearOnly a => a %1 -> (forall (α :: Lifetime). Mut α a %1 -> BO α ()) %1 -> a Source #
Modifies linear resources in-place, together with results.
Parallel computation
parBO :: forall (α :: Lifetime) a b. BO α a %1 -> BO α b %1 -> BO α (a, b) Source #
Run two computations in parallel, returning their results as a tuple.
Borrowing
data Alias (ak :: AliasKind) (α :: Lifetime) a Source #
Alias of kind ak to a resource of type a.
Instances
| Reborrowable Mut Source # | |
| Reborrowable Share Source # | |
| (α <= β, a <: b) => (Lend α a :: Type) <: (Lend β b :: Type) Source # | |
Defined in Control.Monad.Borrow.Pure.BO.Internal | |
| (α >= β, a <: b, b <: a) => (Mut α a :: Type) <: (Mut β b :: Type) Source # | |
Defined in Control.Monad.Borrow.Pure.BO.Internal | |
| (α >= β, a <: b) => (Share α a :: Type) <: (Share β b :: Type) Source # | |
Defined in Control.Monad.Borrow.Pure.BO.Internal | |
| bk ~ 'Mut => LinearOnly (Borrow bk α a :: Type) Source # | |
Defined in Control.Monad.Borrow.Pure.BO.Internal Methods linearOnly :: LinearOnlyWitness (Borrow bk α a) Source # | |
| Consumable (Borrow bk α a) Source # | |
Defined in Control.Monad.Borrow.Pure.BO.Internal | |
| k ~ 'Borrow 'Share => Dupable (Alias k α a) Source # | |
| k ~ 'Borrow 'Share => Movable (Alias k α a) Source # | |
| Affine (Borrow bk α a) Source # | |
data BorrowKind Source #
Borrower kind.
type Borrow (bk :: BorrowKind) = Alias ('Borrow bk) Source #
Borrower of kind bk that is active during the lifetime α.
type Share = Borrow 'Share Source #
Shared borrower, which is unrestricted but usually can only read from the data.
shareCoercion :: forall a b (α :: Lifetime). Coercible a b => Coercion (Share α a) (Share α b) Source #
borrowM :: forall a (α :: Lifetime). a %1 -> BO α (Mut α a, Lend α a) Source #
Borrow a resource linearly for the same lifetime as the ambient BO computation.
Returns the pair of the mutable borrow to the resource, and Lender to be invoked later to reclaim the resource at the End of the lifetime.
See also borrowLinearlyM.
If you want to borrow a resource indepdendent of the ambient lifetime, you can use borrow instead.
borrowLinearlyM :: forall a (α :: Lifetime). (Linearly %1 -> a) %1 -> BO α (Mut α a, Lend α a) Source #
A variant of borrowM that does linear allocation first.
sharing' :: forall (α :: Lifetime) a (α' :: Lifetime) r. Mut α a %1 -> (forall (β :: Lifetime). Share (β /\ α) a -> BO (β /\ α') (After β r)) %1 -> BO α' (r, Mut α a) Source #
Executes an operation on Shared borrow in sub lifetime.
You may need -XImpredicativeTypes extension to use this function.
See also: sharing and sharing_. For Mutable borrows, see reborrowing'.
sharing :: forall (α :: Lifetime) (α' :: Lifetime) a r. Mut α a %1 -> (forall (β :: Lifetime). Share (β /\ α) a -> BO (β /\ α') r) %1 -> BO α' (r, Mut α a) Source #
A variant of sharing' that returns the direct value of the computation on the shared borrow.
There is also a flipped infix version (<$~).
See also: sharing_. For Mutable borrows, see reborrowing.
(<$~) :: forall (α :: Lifetime) a (α' :: Lifetime) r. (forall (β :: Lifetime). Share (β /\ α) a -> BO (β /\ α') r) %1 -> Mut α a %1 -> BO α' (r, Mut α a) infix 4 Source #
sharing_ :: forall (α :: Lifetime) (α' :: Lifetime) a r. Consumable r => Mut α a %1 -> (forall (β :: Lifetime). Share (β /\ α) a -> BO (β /\ α') r) %1 -> BO α' (Mut α a) Source #
A variant of sharing' that discards the final result of the computation.
There is also a flipped infix version (<$=).
See also: sharing. For Mutable borrows, see reborrowing_.
(<$=) :: forall (α :: Lifetime) a (α' :: Lifetime). (forall (β :: Lifetime). Share (β /\ α) a -> BO (β /\ α') ()) %1 -> Mut α a %1 -> BO α' (Mut α a) Source #
reborrowing' :: forall (α :: Lifetime) a (α' :: Lifetime) r. Mut α a %1 -> (forall (β :: Lifetime). Mut (β /\ α) a %1 -> BO (β /\ α') (After β r)) %1 -> BO α' (r, Mut α a) Source #
Executes an operation on Mutable borrow in sub lifetime.
You may need -XImpredicativeTypes extension to use this function.
See also: reborrowing, and reborrowing_. For Shared borrows, see sharing, sharing', and sharing_.
reborrowing :: forall (α :: Lifetime) a (α' :: Lifetime) r. Mut α a %1 -> (forall (β :: Lifetime). Mut (β /\ α) a %1 -> BO (β /\ α') r) %1 -> BO α' (r, Mut α a) Source #
A variant of reborrowing' that returns the direct value of the operation on the reborrowed mutable borrow.
There is also a flipped infix version (<%~).
See also: reborrowing_ and sharing.
(<%~) :: forall (α :: Lifetime) a (α' :: Lifetime) r. (forall (β :: Lifetime). Mut (β /\ α) a %1 -> BO (β /\ α') r) %1 -> Mut α a %1 -> BO α' (r, Mut α a) infix 4 Source #
Flipped infix version of reborrowing, smoewhat analgous to (<$>) and (<%~) in lens package.
reborrowing_ :: forall r (α :: Lifetime) a (α' :: Lifetime). Consumable r => Mut α a %1 -> (forall (β :: Lifetime). Mut (β /\ α) a %1 -> BO (β /\ α') r) %1 -> BO α' (Mut α a) Source #
A variant of reborrowing' that discards the final result of the computation.
There is also a flipped infix version (<%=).
See also: reborrowing and sharing_.
(<%=) :: forall (α :: Lifetime) a (α' :: Lifetime). (forall (β :: Lifetime). Mut (β /\ α) a %1 -> BO (β /\ α') ()) %1 -> Mut α a %1 -> BO α' (Mut α a) infix 4 Source #
Flipped infix version of reborrowing_, smoewhat analgous to (<$>) and (<%=) in lens package.
share :: forall (k :: BorrowKind) (α :: Lifetime) a. Borrow k α a %1 -> Ur (Share α a) Source #
Shares a mutable borrow, invalidating the original one.
reborrow :: forall (β :: Lifetime) (α :: Lifetime) a. α >= β => Mut α a %1 -> (Mut β a, Lend β (Mut α a)) Source #
Reborrow a mutable borrow into a sublifetime.
joinMut :: forall (bk :: BorrowKind) (α :: Lifetime) (β :: Lifetime) a. Borrow bk α (Mut β a) %1 -> Borrow bk (α /\ β) a Source #
Collapse a borrower to a mutable borrower.
Lower-level operators
borrowLinearOnly :: forall (α :: Lifetime) a. LinearOnly a => a %1 -> (Mut α a, Lend α a) Source #
A variant of borrow that obtains Linearly viar LinearOnly.
Splitting aliases
class DistributesAlias (f :: Type -> Type) Source #
Distribute an alias over a functor.
Instances
| DistributesAlias First Source # | |
| DistributesAlias Last Source # | |
| DistributesAlias Max Source # | |
| DistributesAlias Min Source # | |
| DistributesAlias Identity Source # | |
| DistributesAlias First Source # | |
| DistributesAlias Last Source # | |
| DistributesAlias Down Source # | |
| DistributesAlias Dual Source # | |
| DistributesAlias Par1 Source # | |
| DistributesAlias Maybe Source # | |
| DistributesAlias Solo Source # | |
| DistributesAlias [] Source # | |
| Unsatisfiable ('Text "Use splitEither directly!") => DistributesAlias (Either e) Source # | |
| Unsatisfiable ('Text "Use splitPair instead!") => DistributesAlias ((,) a) Source # | |
| GenericDistributesAlias f => DistributesAlias (Generically1 f) Source # | |
Defined in Control.Monad.Borrow.Pure.BO.Internal Methods split_ :: forall (ak :: AliasKind) (α :: Lifetime) x. Alias ak α (Generically1 f x) %1 -> Generically1 f (Alias ak α x) | |
split :: forall f x (ak :: AliasKind) (α :: Lifetime). DistributesAlias f => Alias ak α (f x) %1 -> f (Alias ak α x) Source #
genericSplit :: forall f x (ak :: AliasKind) (α :: Lifetime). GenericDistributesAlias f => Alias ak α (f x) %1 -> f (Alias ak α x) Source #
splitPair :: forall (ak :: AliasKind) (α :: Lifetime) a b. Alias ak α (a, b) %1 -> (Alias ak α a, Alias ak α b) Source #
splitEither :: forall (ak :: AliasKind) (α :: Lifetime) a b. Alias ak α (Either a b) %1 -> Either (Alias ak α a) (Alias ak α b) Source #
Misc Utilities
Manual lifetime reassociation
assocRBO :: forall (α :: Lifetime) (β :: Lifetime) (γ :: Lifetime) a. BO ((α /\ β) /\ γ) a %1 -> BO (α /\ (β /\ γ)) a Source #
assocLBO :: forall (α :: Lifetime) (β :: Lifetime) (γ :: Lifetime) a. BO (α /\ (β /\ γ)) a %1 -> BO ((α /\ β) /\ γ) a Source #
assocBOEq :: forall (α :: Lifetime) (β :: Lifetime) (γ :: Lifetime) a. BO ((α /\ β) /\ γ) a :~: BO (α /\ (β /\ γ)) a Source #
assocBorrowL :: forall (bk :: BorrowKind) (α :: Lifetime) (β :: Lifetime) (γ :: Lifetime) a. Borrow bk (α /\ (β /\ γ)) a %1 -> Borrow bk ((α /\ β) /\ γ) a Source #
assocBorrowR :: forall (bk :: BorrowKind) (α :: Lifetime) (β :: Lifetime) (γ :: Lifetime) a. Borrow bk ((α /\ β) /\ γ) a %1 -> Borrow bk (α /\ (β /\ γ)) a Source #
assocBorrowEq :: forall (bk :: BorrowKind) (α :: Lifetime) (β :: Lifetime) (γ :: Lifetime) a. Borrow bk ((α /\ β) /\ γ) a :~: Borrow bk (α /\ (β /\ γ)) a Source #
assocLendL :: forall (α :: Lifetime) (β :: Lifetime) (γ :: Lifetime) a. Lend (α /\ (β /\ γ)) a %1 -> Lend ((α /\ β) /\ γ) a Source #
assocLendR :: forall (α :: Lifetime) (β :: Lifetime) (γ :: Lifetime) a. Lend ((α /\ β) /\ γ) a %1 -> Lend (α /\ (β /\ γ)) a Source #
assocLendEq :: forall (α :: Lifetime) (β :: Lifetime) (γ :: Lifetime) a. Lend ((α /\ β) /\ γ) a :~: Lend (α /\ (β /\ γ)) a Source #
Re-exports
module Data.Coerce.Directed