Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
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
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
->Type
PIsData
, which means 'parametric over things which areData
-encodable'PUnsafeLiftDecl
, which means 'parametric over things that have a Haskell-level equivalent'
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
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
=
pidentity
pbimap
#
(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
=
pidentity
pfirst
#
f=
pbimap
#
f#
pidentity
psecond
#
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
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.
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 #