linear-base-0.4.0: Standard library for linear types.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Unrestricted.Linear

Description

This module provides essential tools for doing non-linear things in linear code.

Critical Definition: Restricted

In a linear function f :: a %1-> b, the argument a must be used in a linear way. Its use is restricted while an argument in a non-linear function is unrestricted.

Hence, a linear function with an argument of Ur a (Ur is short for unrestricted) can use the a in an unrestricted way. That is, we have the following equivalence:

(Ur a %1-> b) ≌ (a -> b)

Consumable, Dupable, Moveable classes

Use these classes to perform some non-linear action on linearly bound values.

If a type is Consumable, you can consume it in a linear function that doesn't need that value to produce it's result:

fst :: Consumable b => (a,b) %1-> a
fst (a,b) = withConsume (consume b) a
  where
    withConsume :: () %1-> a %1-> a
    withConsume () x = x

If a type is Dupable, you can duplicate it as much as you like.

-- checkIndex ix size_of_array
checkIndex :: Int %1-> Int %1-> Bool
checkIndex ix size = withDuplicate (dup2 ix) size
  where
    withDuplicate :: (Int, Int) %1-> Int %1-> Bool
    withDuplicate (ix,ix') size = (0 <= ix) && (ix < size)
    (<) :: Int %1-> Int %1-> Bool
    (<) = ...

    (<=) :: Int %1-> Int %1-> Bool
    (<=) = ...

    (&&) :: Bool %1-> Bool %1-> Bool
    (&&) = ...

If a type is Moveable, you can move it inside Ur and use it in any non-linear way you would like.

diverge :: Int %1-> Bool
diverge ix = fromMove (move ix)
  where
    fromMove :: Ur Int %1-> Bool
    fromMove (Ur 0) = True
    fromMove (Ur 1) = True
    fromMove (Ur x) = False
Synopsis

Unrestricted

data Ur a where Source #

Ur a represents unrestricted values of type a in a linear context. The key idea is that because the contructor holds a with a regular arrow, a function that uses Ur a linearly can use a however it likes.

someLinear :: Ur a %1-> (a,a)
someLinear (Ur a) = (a,a)

Constructors

Ur :: a -> Ur a 

Instances

Instances details
Foldable Ur Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Ur

Methods

fold :: Monoid m => Ur m -> m #

foldMap :: Monoid m => (a -> m) -> Ur a -> m #

foldMap' :: Monoid m => (a -> m) -> Ur a -> m #

foldr :: (a -> b -> b) -> b -> Ur a -> b #

foldr' :: (a -> b -> b) -> b -> Ur a -> b #

foldl :: (b -> a -> b) -> b -> Ur a -> b #

foldl' :: (b -> a -> b) -> b -> Ur a -> b #

foldr1 :: (a -> a -> a) -> Ur a -> a #

foldl1 :: (a -> a -> a) -> Ur a -> a #

toList :: Ur a -> [a] #

null :: Ur a -> Bool #

length :: Ur a -> Int #

elem :: Eq a => a -> Ur a -> Bool #

maximum :: Ord a => Ur a -> a #

minimum :: Ord a => Ur a -> a #

sum :: Num a => Ur a -> a #

product :: Num a => Ur a -> a #

Traversable Ur Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Ur

Methods

traverse :: Applicative f => (a -> f b) -> Ur a -> f (Ur b) #

sequenceA :: Applicative f => Ur (f a) -> f (Ur a) #

mapM :: Monad m => (a -> m b) -> Ur a -> m (Ur b) #

sequence :: Monad m => Ur (m a) -> m (Ur a) #

Applicative Ur Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Ur

Methods

pure :: a -> Ur a #

(<*>) :: Ur (a -> b) -> Ur a -> Ur b #

liftA2 :: (a -> b -> c) -> Ur a -> Ur b -> Ur c #

(*>) :: Ur a -> Ur b -> Ur b #

(<*) :: Ur a -> Ur b -> Ur a #

Functor Ur Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Ur

Methods

fmap :: (a -> b) -> Ur a -> Ur b #

(<$) :: a -> Ur b -> Ur a #

Monad Ur Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Ur

Methods

(>>=) :: Ur a -> (a -> Ur b) -> Ur b #

(>>) :: Ur a -> Ur b -> Ur b #

return :: a -> Ur a #

Applicative Ur Source # 
Instance details

Defined in Data.Functor.Linear.Internal.Applicative

Methods

pure :: a -> Ur a Source #

(<*>) :: Ur (a %1 -> b) %1 -> Ur a %1 -> Ur b Source #

liftA2 :: (a %1 -> b %1 -> c) -> Ur a %1 -> Ur b %1 -> Ur c Source #

Functor Ur Source # 
Instance details

Defined in Data.Functor.Linear.Internal.Functor

Methods

fmap :: (a %1 -> b) -> Ur a %1 -> Ur b Source #

Generic1 Ur Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Ur

Associated Types

type Rep1 Ur :: k -> Type #

Methods

from1 :: forall (a :: k). Ur a -> Rep1 Ur a #

to1 :: forall (a :: k). Rep1 Ur a -> Ur a #

Generic1 Ur Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Ur

Associated Types

type Rep1 Ur :: k -> Type #

Methods

to1 :: forall (p :: k) (m :: Multiplicity). Rep1 Ur p %m -> Ur p #

from1 :: forall (p :: k) (m :: Multiplicity). Ur p %m -> Rep1 Ur p #

Storable a => Storable (Ur a) Source # 
Instance details

Defined in Foreign.Marshal.Pure.Internal

Methods

sizeOf :: Ur a -> Int #

alignment :: Ur a -> Int #

peekElemOff :: Ptr (Ur a) -> Int -> IO (Ur a) #

pokeElemOff :: Ptr (Ur a) -> Int -> Ur a -> IO () #

peekByteOff :: Ptr b -> Int -> IO (Ur a) #

pokeByteOff :: Ptr b -> Int -> Ur a -> IO () #

peek :: Ptr (Ur a) -> IO (Ur a) #

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

Generic (Ur a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Ur

Associated Types

type Rep (Ur a) :: Type -> Type #

Methods

from :: Ur a -> Rep (Ur a) x #

to :: Rep (Ur a) x -> Ur a #

Monoid a => Monoid (Ur a) Source #

Useful to treat unrestricted monoids as linear ones.

Instance details

Defined in Data.Monoid.Linear.Internal.Monoid

Methods

mempty :: Ur a Source #

Semigroup a => Semigroup (Ur a) Source #

Useful to treat unrestricted semigroups as linear ones.

Instance details

Defined in Data.Monoid.Linear.Internal.Semigroup

Methods

(<>) :: Ur a %1 -> Ur a %1 -> Ur a Source #

Eq a => Eq (Ur a) Source # 
Instance details

Defined in Data.Ord.Linear.Internal.Eq

Methods

(==) :: Ur a %1 -> Ur a %1 -> Bool Source #

(/=) :: Ur a %1 -> Ur a %1 -> Bool Source #

Ord a => Ord (Ur a) Source # 
Instance details

Defined in Data.Ord.Linear.Internal.Ord

Methods

compare :: Ur a %1 -> Ur a %1 -> Ordering Source #

(<=) :: Ur a %1 -> Ur a %1 -> Bool Source #

(<) :: Ur a %1 -> Ur a %1 -> Bool Source #

(>) :: Ur a %1 -> Ur a %1 -> Bool Source #

(>=) :: Ur a %1 -> Ur a %1 -> Bool Source #

Consumable (Ur a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: Ur a %1 -> () Source #

Dupable (Ur a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Dupable

Methods

dupR :: Ur a %1 -> Replicator (Ur a) Source #

dup2 :: Ur a %1 -> (Ur a, Ur a) Source #

Movable (Ur a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Movable

Methods

move :: Ur a %1 -> Ur (Ur a) Source #

KnownRepresentable a => KnownRepresentable (Ur a) Source # 
Instance details

Defined in Foreign.Marshal.Pure.Internal

Methods

storable :: Dict (Storable (Ur a))

Generic (Ur a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Ur

Associated Types

type Rep (Ur a) :: Type -> Type #

Methods

to :: forall p (m :: Multiplicity). Rep (Ur a) p %m -> Ur a #

from :: forall p (m :: Multiplicity). Ur a %m -> Rep (Ur a) p #

type Rep1 Ur Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Ur

type Rep1 Ur = D1 ('MetaData "Ur" "Data.Unrestricted.Linear.Internal.Ur" "linear-base-0.4.0-INifdktDXX9C2vI0Gst1y5" 'False) (C1 ('MetaCons "Ur" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) Par1))
type Rep1 Ur Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Ur

type Rep1 Ur
type Rep (Ur a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Ur

type Rep (Ur a) = D1 ('MetaData "Ur" "Data.Unrestricted.Linear.Internal.Ur" "linear-base-0.4.0-INifdktDXX9C2vI0Gst1y5" 'False) (C1 ('MetaCons "Ur" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)))
type Rep (Ur a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Ur

type Rep (Ur a)

unur :: Ur a %1 -> a Source #

Get an a out of an Ur a. If you call this function on a linearly bound Ur a, then the a you get out has to be used linearly, for example:

restricted :: Ur a %1-> b
restricted x = f (unur x)
  where
    -- f __must__ be linear
    f :: a %1-> b
    f x = ...

lift :: (a -> b) -> Ur a %1 -> Ur b Source #

Lifts a function on a linear Ur a.

lift2 :: (a -> b -> c) -> Ur a %1 -> Ur b %1 -> Ur c Source #

Lifts a function to work on two linear Ur a.

newtype UrT m a Source #

UrT transforms linear control monads to non-linear monads.

  • UrT (State s) a is a non-linear monad with linear state.

Constructors

UrT (m (Ur a)) 

Instances

Instances details
Applicative m => Applicative (UrT m) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.UrT

Methods

pure :: a -> UrT m a #

(<*>) :: UrT m (a -> b) -> UrT m a -> UrT m b #

liftA2 :: (a -> b -> c) -> UrT m a -> UrT m b -> UrT m c #

(*>) :: UrT m a -> UrT m b -> UrT m b #

(<*) :: UrT m a -> UrT m b -> UrT m a #

Functor m => Functor (UrT m) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.UrT

Methods

fmap :: (a -> b) -> UrT m a -> UrT m b #

(<$) :: a -> UrT m b -> UrT m a #

Monad m => Monad (UrT m) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.UrT

Methods

(>>=) :: UrT m a -> (a -> UrT m b) -> UrT m b #

(>>) :: UrT m a -> UrT m b -> UrT m b #

return :: a -> UrT m a #

runUrT :: UrT m a %1 -> m (Ur a) Source #

Linearly unwrap the UrT newtype wrapper.

liftUrT :: (Movable a, Functor m) => m a %1 -> UrT m a Source #

Lift a computation to the UrT monad, provided that the type a can be used unrestricted.

evalUrT :: Functor m => UrT m a %1 -> m a Source #

Extract the inner computation linearly, the inverse of liftUrT.

evalUrT (liftUrT m) = m

Performing non-linear actions on linearly bound values

class Consumable a where Source #

Methods

consume :: a %1 -> () Source #

Instances

Instances details
Consumable All Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: All %1 -> () Source #

Consumable Any Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: Any %1 -> () Source #

Consumable Void Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: Void %1 -> () Source #

Consumable Int16 Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Instances

Methods

consume :: Int16 %1 -> () Source #

Consumable Int32 Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Instances

Methods

consume :: Int32 %1 -> () Source #

Consumable Int64 Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Instances

Methods

consume :: Int64 %1 -> () Source #

Consumable Int8 Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Instances

Methods

consume :: Int8 %1 -> () Source #

Consumable Word16 Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Instances

Methods

consume :: Word16 %1 -> () Source #

Consumable Word32 Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Instances

Methods

consume :: Word32 %1 -> () Source #

Consumable Word64 Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Instances

Methods

consume :: Word64 %1 -> () Source #

Consumable Word8 Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Instances

Methods

consume :: Word8 %1 -> () Source #

Consumable Ordering Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: Ordering %1 -> () Source #

Consumable Pool Source # 
Instance details

Defined in Foreign.Marshal.Pure.Internal

Methods

consume :: Pool %1 -> () Source #

Consumable () Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: () %1 -> () Source #

Consumable Bool Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: Bool %1 -> () Source #

Consumable Char Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: Char %1 -> () Source #

Consumable Double Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: Double %1 -> () Source #

Consumable Float Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: Float %1 -> () Source #

Consumable Int Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: Int %1 -> () Source #

Consumable Word Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: Word %1 -> () Source #

Consumable a => Consumable (First a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: First a %1 -> () Source #

Consumable a => Consumable (Last a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: Last a %1 -> () Source #

Consumable a => Consumable (First a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: First a %1 -> () Source #

Consumable a => Consumable (Last a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: Last a %1 -> () Source #

Consumable a => Consumable (Max a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: Max a %1 -> () Source #

Consumable a => Consumable (Min a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: Min a %1 -> () Source #

Consumable a => Consumable (WrappedMonoid a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: WrappedMonoid a %1 -> () Source #

Consumable a => Consumable (Dual a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: Dual a %1 -> () Source #

Consumable a => Consumable (Product a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: Product a %1 -> () Source #

Consumable a => Consumable (Sum a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: Sum a %1 -> () Source #

Consumable (Array a) Source # 
Instance details

Defined in Data.Array.Mutable.Linear.Internal

Methods

consume :: Array a %1 -> () Source #

Consumable (Replicator a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: Replicator a %1 -> () Source #

Consumable (Set a) Source # 
Instance details

Defined in Data.Set.Mutable.Linear.Internal

Methods

consume :: Set a %1 -> () Source #

Movable a => Consumable (AsMovable a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Instances

Methods

consume :: AsMovable a %1 -> () Source #

Consumable (Ur a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: Ur a %1 -> () Source #

Consumable (Vector a) Source # 
Instance details

Defined in Data.Vector.Mutable.Linear.Internal

Methods

consume :: Vector a %1 -> () Source #

(Generic a, GConsumable (Rep a)) => Consumable (Generically a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: Generically a %1 -> () Source #

Consumable a => Consumable (Vector a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: Vector a %1 -> () Source #

Consumable a => Consumable (NonEmpty a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: NonEmpty a %1 -> () Source #

Consumable a => Consumable (Maybe a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: Maybe a %1 -> () Source #

Consumable a => Consumable (a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: (a) %1 -> () Source #

Consumable a => Consumable [a] Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: [a] %1 -> () Source #

(Consumable e, Consumable a) => Consumable (Either e a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: Either e a %1 -> () Source #

(Consumable a, Consumable b) => Consumable (Arg a b) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: Arg a b %1 -> () Source #

Consumable (HashMap k v) Source # 
Instance details

Defined in Data.HashMap.Mutable.Linear.Internal

Methods

consume :: HashMap k v %1 -> () Source #

(KnownNat n, Consumable a) => Consumable (V n a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Instances

Methods

consume :: V n a %1 -> () Source #

Consumable (V 0 a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Instances

Methods

consume :: V 0 a %1 -> () Source #

(Consumable a, Consumable b) => Consumable (a, b) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: (a, b) %1 -> () Source #

Consumable (f a) => Consumable (Ap f a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: Ap f a %1 -> () Source #

Consumable (f a) => Consumable (Alt f a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: Alt f a %1 -> () Source #

(Consumable a, Consumable b, Consumable c) => Consumable (a, b, c) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: (a, b, c) %1 -> () Source #

(Consumable a, Consumable b, Consumable c, Consumable d) => Consumable (a, b, c, d) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: (a, b, c, d) %1 -> () Source #

(Consumable a, Consumable b, Consumable c, Consumable d, Consumable e) => Consumable (a, b, c, d, e) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Consumable

Methods

consume :: (a, b, c, d, e) %1 -> () Source #

class Consumable a => Dupable a where Source #

The laws of Dupable are dual to those of Monoid:

  • 1. first consume (dup2 a) ≃ a ≃ second consume (dup2 a) (dup2 neutrality)
  • 2. first dup2 (dup2 a) ≃ (second dup2 (dup2 a)) (dup2 associativity)

where the (≃) sign represents equality up to type isomorphism.

  • 3. dup2 = Replicator.elim (,) . dupR (coherence between dup2 and dupR)
  • 4. consume = Replicator.elim () . dupR (coherence between consume and dupR)
  • 5. Replicator.extract . dupR = id (dupR identity)
  • 6. dupR . dupR = (Replicator.map dupR) . dupR (dupR interchange)

(Laws 1-2 and 5-6 are equivalent)

Implementation of Dupable for Movable types should be done with deriving via AsMovable.

Implementation of Dupable for other types can be done with deriving via Generically. Note that at present this mechanism can have performance problems for recursive parameterized types. Specifically, the methods will not specialize to underlying Dupable instances. See this GHC issue.

Minimal complete definition

dupR | dup2

Methods

dupR :: a %1 -> Replicator a Source #

Creates a Replicator for the given a.

You usually want to define this method using Replicator's Applicative instance. For instance, here is an implementation of Dupable [a]:

instance Dupable a => Dupable [a] where
  dupR [] = pure []
  dupR (a : as) = (:) <$> dupR a <*> dupR as

dup2 :: a %1 -> (a, a) Source #

Creates two as from a Dupable a, in a linear fashion.

Instances

Instances details
Dupable All Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Dupable

Methods

dupR :: All %1 -> Replicator All Source #

dup2 :: All %1 -> (All, All) Source #

Dupable Any Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Dupable

Methods

dupR :: Any %1 -> Replicator Any Source #

dup2 :: Any %1 -> (Any, Any) Source #

Dupable Int16 Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Instances

Methods

dupR :: Int16 %1 -> Replicator Int16 Source #

dup2 :: Int16 %1 -> (Int16, Int16) Source #

Dupable Int32 Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Instances

Methods

dupR :: Int32 %1 -> Replicator Int32 Source #

dup2 :: Int32 %1 -> (Int32, Int32) Source #

Dupable Int64 Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Instances

Methods

dupR :: Int64 %1 -> Replicator Int64 Source #

dup2 :: Int64 %1 -> (Int64, Int64) Source #

Dupable Int8 Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Instances

Methods

dupR :: Int8 %1 -> Replicator Int8 Source #

dup2 :: Int8 %1 -> (Int8, Int8) Source #

Dupable Word16 Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Instances

Dupable Word32 Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Instances

Dupable Word64 Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Instances

Dupable Word8 Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Instances

Methods

dupR :: Word8 %1 -> Replicator Word8 Source #

dup2 :: Word8 %1 -> (Word8, Word8) Source #

Dupable Ordering Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Dupable

Dupable Pool Source # 
Instance details

Defined in Foreign.Marshal.Pure.Internal

Methods

dupR :: Pool %1 -> Replicator Pool Source #

dup2 :: Pool %1 -> (Pool, Pool) Source #

Dupable () Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Dupable

Methods

dupR :: () %1 -> Replicator () Source #

dup2 :: () %1 -> ((), ()) Source #

Dupable Bool Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Dupable

Methods

dupR :: Bool %1 -> Replicator Bool Source #

dup2 :: Bool %1 -> (Bool, Bool) Source #

Dupable Char Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Dupable

Methods

dupR :: Char %1 -> Replicator Char Source #

dup2 :: Char %1 -> (Char, Char) Source #

Dupable Double Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Dupable

Dupable Float Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Dupable

Methods

dupR :: Float %1 -> Replicator Float Source #

dup2 :: Float %1 -> (Float, Float) Source #

Dupable Int Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Dupable

Methods

dupR :: Int %1 -> Replicator Int Source #

dup2 :: Int %1 -> (Int, Int) Source #

Dupable Word Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Dupable

Methods

dupR :: Word %1 -> Replicator Word Source #

dup2 :: Word %1 -> (Word, Word) Source #

Dupable a => Dupable (Product a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Dupable

Methods

dupR :: Product a %1 -> Replicator (Product a) Source #

dup2 :: Product a %1 -> (Product a, Product a) Source #

Dupable a => Dupable (Sum a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Dupable

Methods

dupR :: Sum a %1 -> Replicator (Sum a) Source #

dup2 :: Sum a %1 -> (Sum a, Sum a) Source #

Dupable (Array a) Source # 
Instance details

Defined in Data.Array.Mutable.Linear.Internal

Methods

dupR :: Array a %1 -> Replicator (Array a) Source #

dup2 :: Array a %1 -> (Array a, Array a) Source #

Dupable (Replicator a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Dupable

Dupable (Set a) Source # 
Instance details

Defined in Data.Set.Mutable.Linear.Internal

Methods

dupR :: Set a %1 -> Replicator (Set a) Source #

dup2 :: Set a %1 -> (Set a, Set a) Source #

Movable a => Dupable (AsMovable a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Instances

Dupable (Ur a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Dupable

Methods

dupR :: Ur a %1 -> Replicator (Ur a) Source #

dup2 :: Ur a %1 -> (Ur a, Ur a) Source #

Dupable (Vector a) Source # 
Instance details

Defined in Data.Vector.Mutable.Linear.Internal

Methods

dupR :: Vector a %1 -> Replicator (Vector a) Source #

dup2 :: Vector a %1 -> (Vector a, Vector a) Source #

(Generic a, GDupable (Rep a)) => Dupable (Generically a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Dupable

Dupable a => Dupable (NonEmpty a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Dupable

Methods

dupR :: NonEmpty a %1 -> Replicator (NonEmpty a) Source #

dup2 :: NonEmpty a %1 -> (NonEmpty a, NonEmpty a) Source #

Dupable a => Dupable (Maybe a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Dupable

Methods

dupR :: Maybe a %1 -> Replicator (Maybe a) Source #

dup2 :: Maybe a %1 -> (Maybe a, Maybe a) Source #

Dupable a => Dupable (a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Dupable

Methods

dupR :: (a) %1 -> Replicator (a) Source #

dup2 :: (a) %1 -> ((a), (a)) Source #

Dupable a => Dupable [a] Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Dupable

Methods

dupR :: [a] %1 -> Replicator [a] Source #

dup2 :: [a] %1 -> ([a], [a]) Source #

(Dupable a, Dupable b) => Dupable (Either a b) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Dupable

Methods

dupR :: Either a b %1 -> Replicator (Either a b) Source #

dup2 :: Either a b %1 -> (Either a b, Either a b) Source #

Dupable (HashMap k v) Source # 
Instance details

Defined in Data.HashMap.Mutable.Linear.Internal

Methods

dupR :: HashMap k v %1 -> Replicator (HashMap k v) Source #

dup2 :: HashMap k v %1 -> (HashMap k v, HashMap k v) Source #

(KnownNat n, Dupable a) => Dupable (V n a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Instances

Methods

dupR :: V n a %1 -> Replicator (V n a) Source #

dup2 :: V n a %1 -> (V n a, V n a) Source #

(Dupable a, Dupable b) => Dupable (a, b) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Dupable

Methods

dupR :: (a, b) %1 -> Replicator (a, b) Source #

dup2 :: (a, b) %1 -> ((a, b), (a, b)) Source #

(Dupable a, Dupable b, Dupable c) => Dupable (a, b, c) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Dupable

Methods

dupR :: (a, b, c) %1 -> Replicator (a, b, c) Source #

dup2 :: (a, b, c) %1 -> ((a, b, c), (a, b, c)) Source #

(Dupable a, Dupable b, Dupable c, Dupable d) => Dupable (a, b, c, d) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Dupable

Methods

dupR :: (a, b, c, d) %1 -> Replicator (a, b, c, d) Source #

dup2 :: (a, b, c, d) %1 -> ((a, b, c, d), (a, b, c, d)) Source #

(Dupable a, Dupable b, Dupable c, Dupable d, Dupable e) => Dupable (a, b, c, d, e) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Dupable

Methods

dupR :: (a, b, c, d, e) %1 -> Replicator (a, b, c, d, e) Source #

dup2 :: (a, b, c, d, e) %1 -> ((a, b, c, d, e), (a, b, c, d, e)) Source #

class Dupable a => Movable a where Source #

Use Movable a to represent a type which can be used many times even when given linearly. Simple data types such as Bool or [] are Movable. Though, bear in mind that this typically induces a deep copy of the value.

Formally, Movable a is the class of coalgebras of the Ur comonad. That is

  • unur (move x) = x
  • move @(Ur a) (move @a x) = fmap (move @a) $ move @a x

Additionally, a Movable instance must be compatible with its Dupable parent instance. That is:

  • case move x of {Ur _ -> ()} = consume x
  • case move x of {Ur x -> (x, x)} = dup2 x

Methods

move :: a %1 -> Ur a Source #

Instances

Instances details
Movable All Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Movable

Methods

move :: All %1 -> Ur All Source #

Movable Any Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Movable

Methods

move :: Any %1 -> Ur Any Source #

Movable Int16 Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Instances

Methods

move :: Int16 %1 -> Ur Int16 Source #

Movable Int32 Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Instances

Methods

move :: Int32 %1 -> Ur Int32 Source #

Movable Int64 Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Instances

Methods

move :: Int64 %1 -> Ur Int64 Source #

Movable Int8 Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Instances

Methods

move :: Int8 %1 -> Ur Int8 Source #

Movable Word16 Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Instances

Methods

move :: Word16 %1 -> Ur Word16 Source #

Movable Word32 Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Instances

Methods

move :: Word32 %1 -> Ur Word32 Source #

Movable Word64 Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Instances

Methods

move :: Word64 %1 -> Ur Word64 Source #

Movable Word8 Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Instances

Methods

move :: Word8 %1 -> Ur Word8 Source #

Movable Ordering Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Movable

Methods

move :: Ordering %1 -> Ur Ordering Source #

Movable () Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Movable

Methods

move :: () %1 -> Ur () Source #

Movable Bool Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Movable

Methods

move :: Bool %1 -> Ur Bool Source #

Movable Char Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Movable

Methods

move :: Char %1 -> Ur Char Source #

Movable Double Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Movable

Methods

move :: Double %1 -> Ur Double Source #

Movable Float Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Movable

Methods

move :: Float %1 -> Ur Float Source #

Movable Int Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Movable

Methods

move :: Int %1 -> Ur Int Source #

Movable Word Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Movable

Methods

move :: Word %1 -> Ur Word Source #

Movable a => Movable (Product a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Movable

Methods

move :: Product a %1 -> Ur (Product a) Source #

Movable a => Movable (Sum a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Movable

Methods

move :: Sum a %1 -> Ur (Sum a) Source #

Movable a => Movable (AsMovable a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Instances

Methods

move :: AsMovable a %1 -> Ur (AsMovable a) Source #

Movable (Ur a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Movable

Methods

move :: Ur a %1 -> Ur (Ur a) Source #

(Generic a, GMovable (Rep a)) => Movable (Generically a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Movable

Methods

move :: Generically a %1 -> Ur (Generically a) Source #

Movable a => Movable (NonEmpty a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Movable

Methods

move :: NonEmpty a %1 -> Ur (NonEmpty a) Source #

Movable a => Movable (Maybe a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Movable

Methods

move :: Maybe a %1 -> Ur (Maybe a) Source #

Movable a => Movable (a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Movable

Methods

move :: (a) %1 -> Ur (a) Source #

Movable a => Movable [a] Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Movable

Methods

move :: [a] %1 -> Ur [a] Source #

(Movable a, Movable b) => Movable (Either a b) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Movable

Methods

move :: Either a b %1 -> Ur (Either a b) Source #

(Movable a, Movable b) => Movable (a, b) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Movable

Methods

move :: (a, b) %1 -> Ur (a, b) Source #

(Movable a, Movable b, Movable c) => Movable (a, b, c) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Movable

Methods

move :: (a, b, c) %1 -> Ur (a, b, c) Source #

(Movable a, Movable b, Movable c, Movable d) => Movable (a, b, c, d) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Movable

Methods

move :: (a, b, c, d) %1 -> Ur (a, b, c, d) Source #

(Movable a, Movable b, Movable c, Movable d, Movable e) => Movable (a, b, c, d, e) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Movable

Methods

move :: (a, b, c, d, e) %1 -> Ur (a, b, c, d, e) Source #

lseq :: Consumable a => a %1 -> b %1 -> b infixr 0 Source #

Consume the first argument and return the second argument. This is like seq but the first argument is restricted to be Consumable.

dup :: Dupable a => a %1 -> (a, a) Source #

Creates two as from a Dupable a. Same function as dup2.

dup3 :: Dupable a => a %1 -> (a, a, a) Source #

Creates 3 as from a Dupable a, in a linear fashion.

dup4 :: Dupable a => a %1 -> (a, a, a, a) Source #

Creates 4 as from a Dupable a, in a linear fashion.

dup5 :: Dupable a => a %1 -> (a, a, a, a, a) Source #

Creates 5 as from a Dupable a, in a linear fashion.

dup6 :: Dupable a => a %1 -> (a, a, a, a, a, a) Source #

Creates 6 as from a Dupable a, in a linear fashion.

dup7 :: Dupable a => a %1 -> (a, a, a, a, a, a, a) Source #

Creates 7 as from a Dupable a, in a linear fashion.

newtype AsMovable a Source #

Newtype that must be used with DerivingVia to get efficient Dupable and Consumable implementations for Movable types.

Constructors

AsMovable a 

Instances

Instances details
Movable a => Consumable (AsMovable a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Instances

Methods

consume :: AsMovable a %1 -> () Source #

Movable a => Dupable (AsMovable a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Instances

Movable a => Movable (AsMovable a) Source # 
Instance details

Defined in Data.Unrestricted.Linear.Internal.Instances

Methods

move :: AsMovable a %1 -> Ur (AsMovable a) Source #