| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Proarrow.Category.Instance.Linear
Description
The category of Haskell types and linear functions: the kind LINEAR wraps Type
in L, and a morphism is a a %1 -> b function. Symmetric monoidal closed with
. The categorical product is L a ** L b = L (a, b)With, and only comonoid objects
(such as ) can be copied or discarded, so it is deliberately not
L (Ur a)CopyDiscard.
Synopsis
- data LINEAR = L Type
- data Linear (a :: LINEAR) (b :: LINEAR) where
- unLinear :: ('L a ~> 'L b) %1 -> a %1 -> b
- data family Forget :: LINEAR +-> Type
- data Ur a where
- counitUr :: Ur a %1 -> a
- dupUr :: Ur a %1 -> Ur (Ur a)
- data Top where
- data With a b where
- urWith :: Ur (With a b) %1 -> (Ur a, Ur b)
- mkWith :: a -> b -> With a b
- type Not a = a %1 -> ()
- not :: (Not b %1 -> Not a) %1 -> a %1 -> b
- not' :: (a %1 -> b) %1 -> Not b %1 -> Not a
- newtype Par a b = Par (Not (Not a, Not b))
- mkPar :: a %1 -> b %1 -> Par a b
- pairFst :: (a, Par b c) %1 -> Par (a, b) c
- pairSnd :: (Par a b, c) %1 -> Par a (b, c)
- parAppL :: Par a b %1 -> Not a %1 -> b
- parAppR :: Par a b %1 -> Not b %1 -> a
- newtype Quest a = Quest (Not (Ur (Not a)))
- notQuest :: Not (Quest a) %1 -> Ur (Not a)
- unitQuest :: a %1 -> Quest a
- multQuest :: Quest (Quest a) %1 -> Quest a
- questPar :: Par (Quest a) (Quest b) %1 -> Quest (Either a b)
- dn :: Not (Not a) %1 -> a
- unsafeLinear :: (a -> b) -> a %1 -> b
- unit :: 'L () ~> 'L (Par a (Not a))
- counit :: 'L (Not a, a) ~> 'L ()
- type (!~>) (p :: k -> k1 -> Type) (q :: k -> k1 -> Type) = forall (a :: k) (b :: k1). p a b %1 -> q a b
- data NegComp (p :: j +-> k) (q :: i +-> j) (a :: k) (c :: i) where
- newtype Neg (p :: k -> k1 -> Type) (a :: k1) (b :: k) = Neg (Not (p b a))
- getNeg :: forall {k1} {k2} p (a :: k2) (b :: k1). Neg p a b %1 -> Not (p b a)
- conv1 :: forall {k1} {k2} {k3} (p :: k1 +-> k2) (q :: k3 +-> k1) (a :: k2) (b :: k3). NegComp p q a b %1 -> Neg (Neg q :.: Neg p) a b
- conv2 :: forall {j} {i} {k} (q :: j -> i -> Type) (p :: k -> j -> Type) (a :: k) (b :: i). Neg (Neg q :.: Neg p) a b %1 -> NegComp p q a b
- asCocat :: forall {i} (p :: i -> i -> Type). ((Neg p :.: Neg p) !~> Neg p) -> p !~> NegComp p p
Documentation
Instances
| Monoidal LINEAR Source Github # | Tuples as monoidal tensor. Tuples are not the binary product in LINEAR. | ||||||||
Defined in Proarrow.Category.Instance.Linear Associated Types
Methods withOb2 :: forall (a :: LINEAR) (b :: LINEAR) r. (Ob a, Ob b) => (Ob (a ** b) => r) -> r Source Github # leftUnitor :: forall (a :: LINEAR). Ob a => ((Unit :: LINEAR) ** a) ~> a Source Github # leftUnitorInv :: forall (a :: LINEAR). Ob a => a ~> ((Unit :: LINEAR) ** a) Source Github # rightUnitor :: forall (a :: LINEAR). Ob a => (a ** (Unit :: LINEAR)) ~> a Source Github # rightUnitorInv :: forall (a :: LINEAR). Ob a => a ~> (a ** (Unit :: LINEAR)) Source Github # associator :: forall (a :: LINEAR) (b :: LINEAR) (c :: LINEAR). (Ob a, Ob b, Ob c) => ((a ** b) ** c) ~> (a ** (b ** c)) Source Github # associatorInv :: forall (a :: LINEAR) (b :: LINEAR) (c :: LINEAR). (Ob a, Ob b, Ob c) => (a ** (b ** c)) ~> ((a ** b) ** c) Source Github # | |||||||||
| SymMonoidal LINEAR Source Github # | |||||||||
| Closed LINEAR Source Github # | |||||||||
Defined in Proarrow.Category.Instance.Linear Methods withObExp :: forall (a :: LINEAR) (b :: LINEAR) r. (Ob a, Ob b) => (Ob (a ~~> b) => r) -> r Source Github # curry :: forall (a :: LINEAR) (b :: LINEAR) (c :: LINEAR). (Ob a, Ob b) => ((a ** b) ~> c) -> a ~> (b ~~> c) Source Github # apply :: forall (a :: LINEAR) (b :: LINEAR). (Ob a, Ob b) => ((a ~~> b) ** a) ~> b Source Github # (^^^) :: forall (a :: LINEAR) (b :: LINEAR) (x :: LINEAR) (y :: LINEAR). (b ~> y) -> (x ~> a) -> (a ~~> b) ~> (x ~~> y) Source Github # | |||||||||
| Distributive LINEAR Source Github # | |||||||||
Defined in Proarrow.Category.Instance.Linear Methods distL :: forall (a :: LINEAR) (b :: LINEAR) (c :: LINEAR). (Ob a, Ob b, Ob c) => (a ** (b || c)) ~> ((a ** b) || (a ** c)) Source Github # distR :: forall (a :: LINEAR) (b :: LINEAR) (c :: LINEAR). (Ob a, Ob b, Ob c) => ((a || b) ** c) ~> ((a ** c) || (b ** c)) Source Github # absorbL :: forall (a :: LINEAR). Ob a => (a ** (InitialObject :: LINEAR)) ~> (InitialObject :: LINEAR) Source Github # absorbR :: forall (a :: LINEAR). Ob a => ((InitialObject :: LINEAR) ** a) ~> (InitialObject :: LINEAR) Source Github # | |||||||||
| StarAutonomous LINEAR Source Github # | |||||||||
Defined in Proarrow.Category.Instance.Linear Methods withObDual :: forall (a :: LINEAR) r. Ob a => (Ob (Dual a) => r) -> r Source Github # dual :: forall (a :: LINEAR) (b :: LINEAR). (a ~> b) -> Dual b ~> Dual a Source Github # dualInv :: forall (a :: LINEAR) (b :: LINEAR). (Ob a, Ob b) => (Dual a ~> Dual b) -> b ~> a Source Github # linDist :: forall (a :: LINEAR) (b :: LINEAR) (c :: LINEAR). (Ob a, Ob b, Ob c) => ((a ** b) ~> Dual c) -> a ~> Dual (b ** c) Source Github # linDistInv :: forall (a :: LINEAR) (b :: LINEAR) (c :: LINEAR). (Ob a, Ob b, Ob c) => (a ~> Dual (b ** c)) -> (a ** b) ~> Dual c Source Github # doubleNeg :: forall (a :: LINEAR). Ob a => Dual (Dual a) ~> a Source Github # doubleNegInv :: forall (a :: LINEAR). Ob a => a ~> Dual (Dual a) Source Github # | |||||||||
| HasBinaryCoproducts LINEAR Source Github # | |||||||||
Defined in Proarrow.Category.Instance.Linear Methods withObCoprod :: forall (a :: LINEAR) (b :: LINEAR) r. (Ob a, Ob b) => (Ob (a || b) => r) -> r Source Github # lft :: forall (a :: LINEAR) (b :: LINEAR). (Ob a, Ob b) => a ~> (a || b) Source Github # rgt :: forall (a :: LINEAR) (b :: LINEAR). (Ob a, Ob b) => b ~> (a || b) Source Github # (|||) :: forall (x :: LINEAR) (a :: LINEAR) (y :: LINEAR). (x ~> a) -> (y ~> a) -> (x || y) ~> a Source Github # (+++) :: forall (a :: LINEAR) (b :: LINEAR) (x :: LINEAR) (y :: LINEAR). (a ~> x) -> (b ~> y) -> (a || b) ~> (x || y) Source Github # | |||||||||
| HasInitialObject LINEAR Source Github # | |||||||||
Defined in Proarrow.Category.Instance.Linear Associated Types
| |||||||||
| CategoryOf LINEAR Source Github # | Category of linear functions. | ||||||||
Defined in Proarrow.Category.Instance.Linear | |||||||||
| HasBinaryProducts LINEAR Source Github # | |||||||||
Defined in Proarrow.Category.Instance.Linear Methods withObProd :: forall (a :: LINEAR) (b :: LINEAR) r. (Ob a, Ob b) => (Ob (a && b) => r) -> r Source Github # fst :: forall (a :: LINEAR) (b :: LINEAR). (Ob a, Ob b) => (a && b) ~> a Source Github # snd :: forall (a :: LINEAR) (b :: LINEAR). (Ob a, Ob b) => (a && b) ~> b Source Github # (&&&) :: forall (a :: LINEAR) (x :: LINEAR) (y :: LINEAR). (a ~> x) -> (a ~> y) -> a ~> (x && y) Source Github # (***) :: forall (a :: LINEAR) (b :: LINEAR) (x :: LINEAR) (y :: LINEAR). (a ~> x) -> (b ~> y) -> (a && b) ~> (x && y) Source Github # | |||||||||
| HasTerminalObject LINEAR Source Github # | |||||||||
Defined in Proarrow.Category.Instance.Linear Associated Types
| |||||||||
| Copowered Type LINEAR Source Github # | |||||||||
Defined in Proarrow.Category.Instance.Linear Methods withObCopower :: forall (a :: LINEAR) n r. (Ob a, Ob n) => (Ob (n *. a) => r) -> r Source Github # copower :: forall (a :: LINEAR) (b :: LINEAR) n. (Ob a, Ob b) => (n ~> HomObj Type a b) -> (n *. a) ~> b Source Github # uncopower :: forall (a :: LINEAR) n (b :: LINEAR). (Ob a, Ob n) => ((n *. a) ~> b) -> n ~> HomObj Type a b Source Github # | |||||||||
| Promonad Linear Source Github # | |||||||||
| Powered Type LINEAR Source Github # | |||||||||
Defined in Proarrow.Category.Instance.Linear Methods withObPower :: forall (a :: LINEAR) n r. (Ob a, Ob n) => (Ob (a ^ n) => r) -> r Source Github # power :: forall (a :: LINEAR) (b :: LINEAR) n. (Ob a, Ob b) => (n ~> HomObj Type a b) -> a ~> (b ^ n) Source Github # unpower :: forall (b :: LINEAR) n (a :: LINEAR). (Ob b, Ob n) => (a ~> (b ^ n)) -> n ~> HomObj Type a b Source Github # | |||||||||
| MonoidalProfunctor Linear Source Github # | |||||||||
| Profunctor Linear Source Github # | |||||||||
Defined in Proarrow.Category.Instance.Linear Methods dimap :: forall (c :: LINEAR) (a :: LINEAR) (b :: LINEAR) (d :: LINEAR). (c ~> a) -> (b ~> d) -> Linear a b -> Linear c d Source Github # lmap :: forall (c :: LINEAR) (a :: LINEAR) (b :: LINEAR). (c ~> a) -> Linear a b -> Linear c b Source Github # rmap :: forall (b :: LINEAR) (d :: LINEAR) (a :: LINEAR). (b ~> d) -> Linear a b -> Linear a d Source Github # (\\) :: forall (a :: LINEAR) (b :: LINEAR) r. ((Ob a, Ob b) => r) -> Linear a b -> r Source Github # | |||||||||
| FunctorForRep Forget Source Github # | |||||||||
| MonoidalProfunctor (Rep Forget) Source Github # | Forget is a lax monoidal functor | ||||||||
| MonoidalProfunctor (Corep Forget) Source Github # | Forget is also a colax monoidal functor | ||||||||
| Corepresentable (Rep Forget) Source Github # | By creating the left adjoint to the forgetful functor, we obtain the free-forgetful adjunction between Hask and LINEAR | ||||||||
Defined in Proarrow.Category.Instance.Linear Methods coindex :: forall a (b :: LINEAR). Rep Forget a b -> (Rep Forget %% a) ~> b Source Github # cotabulate :: forall a (b :: LINEAR). Ob a => ((Rep Forget %% a) ~> b) -> Rep Forget a b Source Github # corepMap :: (a ~> b) -> (Rep Forget %% a) ~> (Rep Forget %% b) Source Github # corepUniv :: Ob a => Rep Forget a (Rep Forget %% a) Source Github # | |||||||||
| Comonoid ('L (Ur a) :: LINEAR) Source Github # | |||||||||
| Comonoid ('L Bool) Source Github # |
| ||||||||
| Costrong (CoprodAction :: LINEAR -> (COPROD LINEAR, LINEAR) -> Type) Linear Source Github # | |||||||||
Defined in Proarrow.Category.Instance.Linear | |||||||||
| MonoidalProfunctor (Coprod Linear) Source Github # | |||||||||
Defined in Proarrow.Category.Instance.Linear | |||||||||
| type Unit Source Github # | |||||||||
Defined in Proarrow.Category.Instance.Linear | |||||||||
| type InitialObject Source Github # | |||||||||
Defined in Proarrow.Category.Instance.Linear | |||||||||
| type (~>) Source Github # | |||||||||
Defined in Proarrow.Category.Instance.Linear | |||||||||
| type TerminalObject Source Github # | |||||||||
Defined in Proarrow.Category.Instance.Linear | |||||||||
| type Ob (a :: LINEAR) Source Github # | |||||||||
Defined in Proarrow.Category.Instance.Linear | |||||||||
| type (a :: LINEAR) ~~> (b :: LINEAR) Source Github # | |||||||||
| type Forget @ (a :: LINEAR) Source Github # | |||||||||
| type (n :: Type) *. ('L a :: LINEAR) Source Github # | |||||||||
| type ('L a :: LINEAR) ^ (n :: Type) Source Github # | |||||||||
| type (Rep Forget) %% (a :: Type) Source Github # | |||||||||
| type Dual ('L a :: LINEAR) Source Github # | |||||||||
| type ('L a :: LINEAR) ** ('L b :: LINEAR) Source Github # | |||||||||
| type ('L a :: LINEAR) || ('L b :: LINEAR) Source Github # | |||||||||
| type ('L a :: LINEAR) && ('L b :: LINEAR) Source Github # | |||||||||
data Linear (a :: LINEAR) (b :: LINEAR) where Source Github #
Instances
| Promonad Linear Source Github # | |
| MonoidalProfunctor Linear Source Github # | |
| Profunctor Linear Source Github # | |
Defined in Proarrow.Category.Instance.Linear Methods dimap :: forall (c :: LINEAR) (a :: LINEAR) (b :: LINEAR) (d :: LINEAR). (c ~> a) -> (b ~> d) -> Linear a b -> Linear c d Source Github # lmap :: forall (c :: LINEAR) (a :: LINEAR) (b :: LINEAR). (c ~> a) -> Linear a b -> Linear c b Source Github # rmap :: forall (b :: LINEAR) (d :: LINEAR) (a :: LINEAR). (b ~> d) -> Linear a b -> Linear a d Source Github # (\\) :: forall (a :: LINEAR) (b :: LINEAR) r. ((Ob a, Ob b) => r) -> Linear a b -> r Source Github # | |
| Costrong (CoprodAction :: LINEAR -> (COPROD LINEAR, LINEAR) -> Type) Linear Source Github # | |
Defined in Proarrow.Category.Instance.Linear | |
| MonoidalProfunctor (Coprod Linear) Source Github # | |
Defined in Proarrow.Category.Instance.Linear | |
data family Forget :: LINEAR +-> Type Source Github #
Instances
| FunctorForRep Forget Source Github # | |
| MonoidalProfunctor (Rep Forget) Source Github # | Forget is a lax monoidal functor |
| MonoidalProfunctor (Corep Forget) Source Github # | Forget is also a colax monoidal functor |
| Corepresentable (Rep Forget) Source Github # | By creating the left adjoint to the forgetful functor, we obtain the free-forgetful adjunction between Hask and LINEAR |
Defined in Proarrow.Category.Instance.Linear Methods coindex :: forall a (b :: LINEAR). Rep Forget a b -> (Rep Forget %% a) ~> b Source Github # cotabulate :: forall a (b :: LINEAR). Ob a => ((Rep Forget %% a) ~> b) -> Rep Forget a b Source Github # corepMap :: (a ~> b) -> (Rep Forget %% a) ~> (Rep Forget %% b) Source Github # corepUniv :: Ob a => Rep Forget a (Rep Forget %% a) Source Github # | |
| type Forget @ (a :: LINEAR) Source Github # | |
| type (Rep Forget) %% (a :: Type) Source Github # | |
dn :: Not (Not a) %1 -> a Source Github #
Double negation is possible with linear functions, though using unsafeDupablePerformIO.
Derived from https://gist.github.com/ant-arctica/7563282c57d9d1ce0c4520c543187932
TODO: only tested in GHCi, might get ruined by optimizations
unsafeLinear :: (a -> b) -> a %1 -> b Source Github #
type (!~>) (p :: k -> k1 -> Type) (q :: k -> k1 -> Type) = forall (a :: k) (b :: k1). p a b %1 -> q a b Source Github #
conv1 :: forall {k1} {k2} {k3} (p :: k1 +-> k2) (q :: k3 +-> k1) (a :: k2) (b :: k3). NegComp p q a b %1 -> Neg (Neg q :.: Neg p) a b Source Github #