| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Plutarch.Extra.Functor
Contents
Synopsis
- class Plut (a :: S -> Type)
- class PFunctor (f :: (S -> Type) -> S -> Type) where
- type PSubcategory f :: (S -> Type) -> Constraint
- pfmap :: forall (a :: S -> Type) (b :: S -> Type) (s :: S). (PSubcategory f a, PSubcategory f b) => Term s ((a :--> b) :--> (f a :--> f b))
- pfconst :: forall (a :: S -> Type) (b :: S -> Type) (s :: S). (PSubcategory f a, PSubcategory f b) => Term s (a :--> (f b :--> f a))
- class PBifunctor (f :: (S -> Type) -> (S -> Type) -> S -> Type) where
- type PSubcategoryLeft f :: (S -> Type) -> Constraint
- type PSubcategoryRight f :: (S -> Type) -> Constraint
- pbimap :: forall (a :: S -> Type) (b :: S -> Type) (c :: S -> Type) (d :: S -> Type) (s :: S). (PSubcategoryLeft f a, PSubcategoryLeft f c, PSubcategoryRight f b, PSubcategoryRight f d) => Term s ((a :--> c) :--> ((b :--> d) :--> (f a b :--> f c d)))
- pfirst :: forall (a :: S -> Type) (b :: S -> Type) (c :: S -> Type) (s :: S). (PSubcategoryLeft f a, PSubcategoryLeft f c, PSubcategoryRight f b) => Term s ((a :--> c) :--> (f a b :--> f c b))
- psecond :: forall (a :: S -> Type) (b :: S -> Type) (d :: S -> Type) (s :: S). (PSubcategoryLeft f a, PSubcategoryRight f b, PSubcategoryRight f d) => Term s ((b :--> d) :--> (f a b :--> f a d))
- (#<$) :: forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (b :: S -> Type) (s :: S). (PFunctor f, PSubcategory f a, PSubcategory f b) => Term s a -> Term s (f b) -> Term s (f a)
- (#$>) :: forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (b :: S -> Type) (s :: S). (PFunctor f, PSubcategory f a, PSubcategory f b) => Term s (f a) -> Term s b -> Term s (f b)
- (#<$>) :: forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (b :: S -> Type) (s :: S). (PFunctor f, PSubcategory f a, PSubcategory f b) => Term s (a :--> b) -> Term s (f a) -> Term s (f b)
- (#<&>) :: forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (b :: S -> Type) (s :: S). (PFunctor f, PSubcategory f a, PSubcategory f b) => Term s (f a) -> Term s (a :--> b) -> Term s (f b)
- pvoid :: forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (b :: S -> Type) (s :: S). (PFunctor f, PSubcategory f a, PSubcategory f b, PBoring b) => Term s (f a) -> Term s (f b)
Type classes
class Plut (a :: S -> Type) Source #
Describes the entire category of Plutarch types, with arrows being Plutarch
functions. Since the typical name for the category of Haskell types is
Hask, we follow this trend with naming, choosing Plut.
Use this for PSubcategory if you want any Plutarch type to be available.
Since: 3.1.0
Instances
| Plut a Source # | Since: 3.1.0 |
Defined in Plutarch.Extra.Functor | |
class PFunctor (f :: (S -> Type) -> S -> Type) where Source #
Describes a Plutarch-level covariant endofunctor. However, unlike in
Haskell, the endofunctor is defined over a subcategory of Plut, rather than
all of it.
Put another way, this is the Plutarch equivalent to Functor, but unlike in
Haskell, instead of requiring full parametricity, we are allowed to constrain
what we are parametric over.
Laws
Formally, f must be an endofunctor on a subcategory of Plut, as described
by the PSubcategory constraint. This means that the following must hold:
If is PSubcategory fPlut (that is, f is defined as an endofunctor on
all of Plut), the second law is a free theorem; however, in any other
case, it may not be.
Since: 1.0.0
Minimal complete definition
Associated Types
type PSubcategory f :: (S -> Type) -> Constraint Source #
Describes the subcategory of Plut that f is an endofunctor on. Put
another way, this describes what kind of types f is 'parametric
over'.
Common choices for this are:
Plut, which means 'parametric over anything of kind'S->TypePIsData, which means 'parametric over things which areData-encodable'PUnsafeLiftDecl, which means 'parametric over things that have a Haskell-level equivalent'
Methods
pfmap :: forall (a :: S -> Type) (b :: S -> Type) (s :: S). (PSubcategory f a, PSubcategory f b) => Term s ((a :--> b) :--> (f a :--> f b)) Source #
pfconst :: forall (a :: S -> Type) (b :: S -> Type) (s :: S). (PSubcategory f a, PSubcategory f b) => Term s (a :--> (f b :--> f a)) Source #
Instances
| PFunctor PIdentity Source # | Since: 3.1.0 |
Defined in Plutarch.Extra.Identity Associated Types type PSubcategory PIdentity :: (S -> Type) -> Constraint Source # Methods pfmap :: forall (a :: S -> Type) (b :: S -> Type) (s :: S). (PSubcategory PIdentity a, PSubcategory PIdentity b) => Term s ((a :--> b) :--> (PIdentity a :--> PIdentity b)) Source # pfconst :: forall (a :: S -> Type) (b :: S -> Type) (s :: S). (PSubcategory PIdentity a, PSubcategory PIdentity b) => Term s (a :--> (PIdentity b :--> PIdentity a)) Source # | |
| PFunctor PSum Source # | Since: 3.1.0 |
Defined in Plutarch.Extra.Sum Associated Types type PSubcategory PSum :: (S -> Type) -> Constraint Source # Methods pfmap :: forall (a :: S -> Type) (b :: S -> Type) (s :: S). (PSubcategory PSum a, PSubcategory PSum b) => Term s ((a :--> b) :--> (PSum a :--> PSum b)) Source # pfconst :: forall (a :: S -> Type) (b :: S -> Type) (s :: S). (PSubcategory PSum a, PSubcategory PSum b) => Term s (a :--> (PSum b :--> PSum a)) Source # | |
| PFunctor PMaybeData Source # | Since: 1.0.0 |
Defined in Plutarch.Extra.Functor Associated Types type PSubcategory PMaybeData :: (S -> Type) -> Constraint Source # Methods pfmap :: forall (a :: S -> Type) (b :: S -> Type) (s :: S). (PSubcategory PMaybeData a, PSubcategory PMaybeData b) => Term s ((a :--> b) :--> (PMaybeData a :--> PMaybeData b)) Source # pfconst :: forall (a :: S -> Type) (b :: S -> Type) (s :: S). (PSubcategory PMaybeData a, PSubcategory PMaybeData b) => Term s (a :--> (PMaybeData b :--> PMaybeData a)) Source # | |
| PFunctor PBuiltinList Source # | Since: 1.0.0 |
Defined in Plutarch.Extra.Functor Associated Types type PSubcategory PBuiltinList :: (S -> Type) -> Constraint Source # Methods pfmap :: forall (a :: S -> Type) (b :: S -> Type) (s :: S). (PSubcategory PBuiltinList a, PSubcategory PBuiltinList b) => Term s ((a :--> b) :--> (PBuiltinList a :--> PBuiltinList b)) Source # pfconst :: forall (a :: S -> Type) (b :: S -> Type) (s :: S). (PSubcategory PBuiltinList a, PSubcategory PBuiltinList b) => Term s (a :--> (PBuiltinList b :--> PBuiltinList a)) Source # | |
| PFunctor PList Source # | Since: 3.1.0 |
Defined in Plutarch.Extra.Functor Associated Types type PSubcategory PList :: (S -> Type) -> Constraint Source # Methods pfmap :: forall (a :: S -> Type) (b :: S -> Type) (s :: S). (PSubcategory PList a, PSubcategory PList b) => Term s ((a :--> b) :--> (PList a :--> PList b)) Source # pfconst :: forall (a :: S -> Type) (b :: S -> Type) (s :: S). (PSubcategory PList a, PSubcategory PList b) => Term s (a :--> (PList b :--> PList a)) Source # | |
| PFunctor PMaybe Source # | Since: 3.1.0 |
Defined in Plutarch.Extra.Functor Associated Types type PSubcategory PMaybe :: (S -> Type) -> Constraint Source # Methods pfmap :: forall (a :: S -> Type) (b :: S -> Type) (s :: S). (PSubcategory PMaybe a, PSubcategory PMaybe b) => Term s ((a :--> b) :--> (PMaybe a :--> PMaybe b)) Source # pfconst :: forall (a :: S -> Type) (b :: S -> Type) (s :: S). (PSubcategory PMaybe a, PSubcategory PMaybe b) => Term s (a :--> (PMaybe b :--> PMaybe a)) Source # | |
| PFunctor (PConst a) Source # | Since: 3.1.0 |
Defined in Plutarch.Extra.Const Associated Types type PSubcategory (PConst a) :: (S -> Type) -> Constraint Source # Methods pfmap :: forall (a0 :: S -> Type) (b :: S -> Type) (s :: S). (PSubcategory (PConst a) a0, PSubcategory (PConst a) b) => Term s ((a0 :--> b) :--> (PConst a a0 :--> PConst a b)) Source # pfconst :: forall (a0 :: S -> Type) (b :: S -> Type) (s :: S). (PSubcategory (PConst a) a0, PSubcategory (PConst a) b) => Term s (a0 :--> (PConst a b :--> PConst a a0)) Source # | |
| PFunctor (PState s) Source # | Since: 3.1.0 |
Defined in Plutarch.Extra.State Associated Types type PSubcategory (PState s) :: (S -> Type) -> Constraint Source # Methods pfmap :: forall (a :: S -> Type) (b :: S -> Type) (s0 :: S). (PSubcategory (PState s) a, PSubcategory (PState s) b) => Term s0 ((a :--> b) :--> (PState s a :--> PState s b)) Source # pfconst :: forall (a :: S -> Type) (b :: S -> Type) (s0 :: S). (PSubcategory (PState s) a, PSubcategory (PState s) b) => Term s0 (a :--> (PState s b :--> PState s a)) Source # | |
| PIsData a => PFunctor (PDThese a) Source # | Since: 1.0.0 |
Defined in Plutarch.Extra.These Associated Types type PSubcategory (PDThese a) :: (S -> Type) -> Constraint Source # Methods pfmap :: forall (a0 :: S -> Type) (b :: S -> Type) (s :: S). (PSubcategory (PDThese a) a0, PSubcategory (PDThese a) b) => Term s ((a0 :--> b) :--> (PDThese a a0 :--> PDThese a b)) Source # pfconst :: forall (a0 :: S -> Type) (b :: S -> Type) (s :: S). (PSubcategory (PDThese a) a0, PSubcategory (PDThese a) b) => Term s (a0 :--> (PDThese a b :--> PDThese a a0)) Source # | |
| PFunctor (PThese a) Source # | Since: 3.1.0 |
Defined in Plutarch.Extra.These Associated Types type PSubcategory (PThese a) :: (S -> Type) -> Constraint Source # Methods pfmap :: forall (a0 :: S -> Type) (b :: S -> Type) (s :: S). (PSubcategory (PThese a) a0, PSubcategory (PThese a) b) => Term s ((a0 :--> b) :--> (PThese a a0 :--> PThese a b)) Source # pfconst :: forall (a0 :: S -> Type) (b :: S -> Type) (s :: S). (PSubcategory (PThese a) a0, PSubcategory (PThese a) b) => Term s (a0 :--> (PThese a b :--> PThese a a0)) Source # | |
| PFunctor (PEither e) Source # | Since: 3.1.0 |
Defined in Plutarch.Extra.Functor Associated Types type PSubcategory (PEither e) :: (S -> Type) -> Constraint Source # Methods pfmap :: forall (a :: S -> Type) (b :: S -> Type) (s :: S). (PSubcategory (PEither e) a, PSubcategory (PEither e) b) => Term s ((a :--> b) :--> (PEither e a :--> PEither e b)) Source # pfconst :: forall (a :: S -> Type) (b :: S -> Type) (s :: S). (PSubcategory (PEither e) a, PSubcategory (PEither e) b) => Term s (a :--> (PEither e b :--> PEither e a)) Source # | |
| PFunctor (PPair a) Source # | Since: 3.1.0 |
Defined in Plutarch.Extra.Functor Associated Types type PSubcategory (PPair a) :: (S -> Type) -> Constraint Source # Methods pfmap :: forall (a0 :: S -> Type) (b :: S -> Type) (s :: S). (PSubcategory (PPair a) a0, PSubcategory (PPair a) b) => Term s ((a0 :--> b) :--> (PPair a a0 :--> PPair a b)) Source # pfconst :: forall (a0 :: S -> Type) (b :: S -> Type) (s :: S). (PSubcategory (PPair a) a0, PSubcategory (PPair a) b) => Term s (a0 :--> (PPair a b :--> PPair a a0)) Source # | |
| PFunctor f => PFunctor (PStar f a) Source # | This essentially makes Since: 3.0.1 |
Defined in Plutarch.Extra.Star Associated Types type PSubcategory (PStar f a) :: (S -> Type) -> Constraint Source # Methods pfmap :: forall (a0 :: S -> Type) (b :: S -> Type) (s :: S). (PSubcategory (PStar f a) a0, PSubcategory (PStar f a) b) => Term s ((a0 :--> b) :--> (PStar f a a0 :--> PStar f a b)) Source # pfconst :: forall (a0 :: S -> Type) (b :: S -> Type) (s :: S). (PSubcategory (PStar f a) a0, PSubcategory (PStar f a) b) => Term s (a0 :--> (PStar f a b :--> PStar f a a0)) Source # | |
| PFunctor (PTagged tag) Source # | Since: 3.1.0 |
Defined in Plutarch.Extra.Tagged Associated Types type PSubcategory (PTagged tag) :: (S -> Type) -> Constraint Source # Methods pfmap :: forall (a :: S -> Type) (b :: S -> Type) (s :: S). (PSubcategory (PTagged tag) a, PSubcategory (PTagged tag) b) => Term s ((a :--> b) :--> (PTagged tag a :--> PTagged tag b)) Source # pfconst :: forall (a :: S -> Type) (b :: S -> Type) (s :: S). (PSubcategory (PTagged tag) a, PSubcategory (PTagged tag) b) => Term s (a :--> (PTagged tag b :--> PTagged tag a)) Source # | |
| PIsData k => PFunctor (PMap s k) Source # | Since: 1.0.0 |
Defined in Plutarch.Extra.Functor Associated Types type PSubcategory (PMap s k) :: (S -> Type) -> Constraint Source # Methods pfmap :: forall (a :: S -> Type) (b :: S -> Type) (s0 :: S). (PSubcategory (PMap s k) a, PSubcategory (PMap s k) b) => Term s0 ((a :--> b) :--> (PMap s k a :--> PMap s k b)) Source # pfconst :: forall (a :: S -> Type) (b :: S -> Type) (s0 :: S). (PSubcategory (PMap s k) a, PSubcategory (PMap s k) b) => Term s0 (a :--> (PMap s k b :--> PMap s k a)) Source # | |
class PBifunctor (f :: (S -> Type) -> (S -> Type) -> S -> Type) where Source #
Similar to PFunctor, but is covariant in two parameters instead of one.
This means that types like PEither don't need to be partially applied, as
is the case with PFunctor. Formally, this represents a Plutarch-level
covariant bifunctor; just as with PFunctor however, it is defined over a
subcategory of Plut.
Similarly to PFunctor, this is the Plutarch equivalent of Bifunctor.
Laws
Formally, f must be a bifunctor on a subcategory of Plut, as described by
PSubcategoryLeft (for the first parameter) and PSubcategoryRight (for the
second). For pbimap, this means the following must hold:
pbimap#pidentity#pidentity=pidentitypbimap#(f1#>>>f2)#(g1#>>>g2)=(pbimap#f1#g1)#>>>(pbimap#f2#g2)
Furthermore, 'PSubcategoryLeft f' ~ should hold; this
may be required in the future. If both PSubcategoryRight f and
PSubcategoryLeft f are PSubcategoryRight fPlut, the second law is a free theorem; however,
this does not hold in general.
If you define pfirst and psecond, the following must also hold:
pfirst#pidentity=psecond#pidentity=pidentitypfirst#f=pbimap#f#pidentitypsecond#f=pbimap#pidentity#fpfirst#(f#>>>g)=(pfirst#f)#>>>(pfirst#g)psecond#(f#>>>g)=(psecond#f)#>>>(psecond#g)
If you define pfirst and psecond instead of pbimap, the following
must also hold:
Note
If f a is also an instance of PFunctor, should hold, and we should have PSubcategoryRight f ~
PSubcategory (f a);
once again, this is not currently enforced, but may be in the future.pfmap = psecond
Since: 1.0.0
Associated Types
type PSubcategoryLeft f :: (S -> Type) -> Constraint Source #
Similar to PSubcategory, but for only the first parameter of f. See
the documentation on PSubcategory for common choices here.
type PSubcategoryRight f :: (S -> Type) -> Constraint Source #
Similar to PSubcategory, but for only the second parameter of f.
See the documentation on PSubcategory for common choices here.
Methods
pbimap :: forall (a :: S -> Type) (b :: S -> Type) (c :: S -> Type) (d :: S -> Type) (s :: S). (PSubcategoryLeft f a, PSubcategoryLeft f c, PSubcategoryRight f b, PSubcategoryRight f d) => Term s ((a :--> c) :--> ((b :--> d) :--> (f a b :--> f c d))) Source #
pfirst :: forall (a :: S -> Type) (b :: S -> Type) (c :: S -> Type) (s :: S). (PSubcategoryLeft f a, PSubcategoryLeft f c, PSubcategoryRight f b) => Term s ((a :--> c) :--> (f a b :--> f c b)) Source #
psecond :: forall (a :: S -> Type) (b :: S -> Type) (d :: S -> Type) (s :: S). (PSubcategoryLeft f a, PSubcategoryRight f b, PSubcategoryRight f d) => Term s ((b :--> d) :--> (f a b :--> f a d)) Source #
Instances
Functions
(#<$) :: forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (b :: S -> Type) (s :: S). (PFunctor f, PSubcategory f a, PSubcategory f b) => Term s a -> Term s (f b) -> Term s (f a) infixl 4 Source #
(#$>) :: forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (b :: S -> Type) (s :: S). (PFunctor f, PSubcategory f a, PSubcategory f b) => Term s (f a) -> Term s b -> Term s (f b) infixl 4 Source #
Flipped version of #<$.
Since: 1.0.0
(#<$>) :: forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (b :: S -> Type) (s :: S). (PFunctor f, PSubcategory f a, PSubcategory f b) => Term s (a :--> b) -> Term s (f a) -> Term s (f b) infixl 4 Source #