liqwid-plutarch-extra-3.21.1: A collection of Plutarch extras from Liqwid Labs
Safe HaskellSafe-Inferred
LanguageHaskell2010

Plutarch.Extra.Functor

Synopsis

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

Instances details
Plut a Source #

Since: 3.1.0

Instance details

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 PSubcategory f is Plut (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

pfmap

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 -> Type'
  • PIsData, which means 'parametric over things which are Data-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 #

Replace all values to be computed with a fixed value. Defaults to pfmap pconst, but could be more efficient for some PFunctors.

Since: 1.2.0

Instances

Instances details
PFunctor PIdentity Source #

Since: 3.1.0

Instance details

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

Instance details

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

Instance details

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

Instance details

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

Instance details

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

Instance details

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

Instance details

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

Instance details

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

Instance details

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

Instance details

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

Instance details

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

Instance details

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 PStar f a b equivalent to the Haskell ReaderT a f b: that is, a read-only environment of type a producing a result of type b in an effect f. If f is only a PFunctor, we can only lift, but not compose.

Since: 3.0.1

Instance details

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

Instance details

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

Instance details

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:

Furthermore, 'PSubcategoryLeft f' ~ PSubcategoryRight f should hold; this may be required in the future. If both PSubcategoryLeft f and PSubcategoryRight f are Plut, 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:

If you define pfirst and psecond instead of pbimap, the following must also hold:

Note

If f a is also an instance of PFunctor, PSubcategoryRight f ~ PSubcategory (f a) should hold, and we should have pfmap = psecond; once again, this is not currently enforced, but may be in the future.

Since: 1.0.0

Minimal complete definition

pbimap | pfirst, psecond

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

Instances details
PBifunctor PConst Source #

Since: 3.1.0

Instance details

Defined in Plutarch.Extra.Const

Associated Types

type PSubcategoryLeft PConst :: (S -> Type) -> Constraint Source #

type PSubcategoryRight PConst :: (S -> Type) -> Constraint Source #

Methods

pbimap :: forall (a :: S -> Type) (b :: S -> Type) (c :: S -> Type) (d :: S -> Type) (s :: S). (PSubcategoryLeft PConst a, PSubcategoryLeft PConst c, PSubcategoryRight PConst b, PSubcategoryRight PConst d) => Term s ((a :--> c) :--> ((b :--> d) :--> (PConst a b :--> PConst c d))) Source #

pfirst :: forall (a :: S -> Type) (b :: S -> Type) (c :: S -> Type) (s :: S). (PSubcategoryLeft PConst a, PSubcategoryLeft PConst c, PSubcategoryRight PConst b) => Term s ((a :--> c) :--> (PConst a b :--> PConst c b)) Source #

psecond :: forall (a :: S -> Type) (b :: S -> Type) (d :: S -> Type) (s :: S). (PSubcategoryLeft PConst a, PSubcategoryRight PConst b, PSubcategoryRight PConst d) => Term s ((b :--> d) :--> (PConst a b :--> PConst a d)) Source #

PBifunctor PDThese Source #

Since: 1.0.0

Instance details

Defined in Plutarch.Extra.These

Methods

pbimap :: forall (a :: S -> Type) (b :: S -> Type) (c :: S -> Type) (d :: S -> Type) (s :: S). (PSubcategoryLeft PDThese a, PSubcategoryLeft PDThese c, PSubcategoryRight PDThese b, PSubcategoryRight PDThese d) => Term s ((a :--> c) :--> ((b :--> d) :--> (PDThese a b :--> PDThese c d))) Source #

pfirst :: forall (a :: S -> Type) (b :: S -> Type) (c :: S -> Type) (s :: S). (PSubcategoryLeft PDThese a, PSubcategoryLeft PDThese c, PSubcategoryRight PDThese b) => Term s ((a :--> c) :--> (PDThese a b :--> PDThese c b)) Source #

psecond :: forall (a :: S -> Type) (b :: S -> Type) (d :: S -> Type) (s :: S). (PSubcategoryLeft PDThese a, PSubcategoryRight PDThese b, PSubcategoryRight PDThese d) => Term s ((b :--> d) :--> (PDThese a b :--> PDThese a d)) Source #

PBifunctor PThese Source #

Since: 3.1.0

Instance details

Defined in Plutarch.Extra.These

Associated Types

type PSubcategoryLeft PThese :: (S -> Type) -> Constraint Source #

type PSubcategoryRight PThese :: (S -> Type) -> Constraint Source #

Methods

pbimap :: forall (a :: S -> Type) (b :: S -> Type) (c :: S -> Type) (d :: S -> Type) (s :: S). (PSubcategoryLeft PThese a, PSubcategoryLeft PThese c, PSubcategoryRight PThese b, PSubcategoryRight PThese d) => Term s ((a :--> c) :--> ((b :--> d) :--> (PThese a b :--> PThese c d))) Source #

pfirst :: forall (a :: S -> Type) (b :: S -> Type) (c :: S -> Type) (s :: S). (PSubcategoryLeft PThese a, PSubcategoryLeft PThese c, PSubcategoryRight PThese b) => Term s ((a :--> c) :--> (PThese a b :--> PThese c b)) Source #

psecond :: forall (a :: S -> Type) (b :: S -> Type) (d :: S -> Type) (s :: S). (PSubcategoryLeft PThese a, PSubcategoryRight PThese b, PSubcategoryRight PThese d) => Term s ((b :--> d) :--> (PThese a b :--> PThese a d)) Source #

PBifunctor PEither Source #

Since: 3.1.0

Instance details

Defined in Plutarch.Extra.Functor

Methods

pbimap :: forall (a :: S -> Type) (b :: S -> Type) (c :: S -> Type) (d :: S -> Type) (s :: S). (PSubcategoryLeft PEither a, PSubcategoryLeft PEither c, PSubcategoryRight PEither b, PSubcategoryRight PEither d) => Term s ((a :--> c) :--> ((b :--> d) :--> (PEither a b :--> PEither c d))) Source #

pfirst :: forall (a :: S -> Type) (b :: S -> Type) (c :: S -> Type) (s :: S). (PSubcategoryLeft PEither a, PSubcategoryLeft PEither c, PSubcategoryRight PEither b) => Term s ((a :--> c) :--> (PEither a b :--> PEither c b)) Source #

psecond :: forall (a :: S -> Type) (b :: S -> Type) (d :: S -> Type) (s :: S). (PSubcategoryLeft PEither a, PSubcategoryRight PEither b, PSubcategoryRight PEither d) => Term s ((b :--> d) :--> (PEither a b :--> PEither a d)) Source #

PBifunctor PPair Source #

Since: 3.1.0

Instance details

Defined in Plutarch.Extra.Functor

Associated Types

type PSubcategoryLeft PPair :: (S -> Type) -> Constraint Source #

type PSubcategoryRight PPair :: (S -> Type) -> Constraint Source #

Methods

pbimap :: forall (a :: S -> Type) (b :: S -> Type) (c :: S -> Type) (d :: S -> Type) (s :: S). (PSubcategoryLeft PPair a, PSubcategoryLeft PPair c, PSubcategoryRight PPair b, PSubcategoryRight PPair d) => Term s ((a :--> c) :--> ((b :--> d) :--> (PPair a b :--> PPair c d))) Source #

pfirst :: forall (a :: S -> Type) (b :: S -> Type) (c :: S -> Type) (s :: S). (PSubcategoryLeft PPair a, PSubcategoryLeft PPair c, PSubcategoryRight PPair b) => Term s ((a :--> c) :--> (PPair a b :--> PPair c b)) Source #

psecond :: forall (a :: S -> Type) (b :: S -> Type) (d :: S -> Type) (s :: S). (PSubcategoryLeft PPair a, PSubcategoryRight PPair b, PSubcategoryRight PPair d) => Term s ((b :--> d) :--> (PPair a b :--> PPair a d)) Source #

PBifunctor (PMap keys) Source #

Since: 1.0.0

Instance details

Defined in Plutarch.Extra.Functor

Associated Types

type PSubcategoryLeft (PMap keys) :: (S -> Type) -> Constraint Source #

type PSubcategoryRight (PMap keys) :: (S -> Type) -> Constraint Source #

Methods

pbimap :: forall (a :: S -> Type) (b :: S -> Type) (c :: S -> Type) (d :: S -> Type) (s :: S). (PSubcategoryLeft (PMap keys) a, PSubcategoryLeft (PMap keys) c, PSubcategoryRight (PMap keys) b, PSubcategoryRight (PMap keys) d) => Term s ((a :--> c) :--> ((b :--> d) :--> (PMap keys a b :--> PMap keys c d))) Source #

pfirst :: forall (a :: S -> Type) (b :: S -> Type) (c :: S -> Type) (s :: S). (PSubcategoryLeft (PMap keys) a, PSubcategoryLeft (PMap keys) c, PSubcategoryRight (PMap keys) b) => Term s ((a :--> c) :--> (PMap keys a b :--> PMap keys c b)) Source #

psecond :: forall (a :: S -> Type) (b :: S -> Type) (d :: S -> Type) (s :: S). (PSubcategoryLeft (PMap keys) a, PSubcategoryRight (PMap keys) b, PSubcategoryRight (PMap keys) d) => Term s ((b :--> d) :--> (PMap keys a b :--> PMap keys a d)) Source #

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 #

Infix, Term-lifted version of pfconst.

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 (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 #

Infix, Term-level version of pfmap.

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 (f a) -> Term s (a :--> b) -> Term s (f b) infixl 1 Source #

Flipped version of #<$>.

Since: 1.0.0

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) Source #

Erases every location in the input.

Since: 1.2.0