Moduleplutus-core-1.70.0.0
Universe
- 10 types
- 5 classes
- 12 values
- Packageplutus-core-1.70.0.0
- Exports31
- LicenceApache-2.0
- SourceInternal.hs
If f has a GEq instance, this function makes a suitable default
implementation of (==).
A basic dependent sum type where the first component is a tag that specifies the type of the second. For example, think of a GADT such as:
data Tag a where
AString :: Tag String
AnInt :: Tag Int
Rec :: Tag (DSum Tag Identity)Then we can write expressions where the RHS of (:=>) has
different types depending on the Tag constructor used. Here are
some expressions of type DSum Tag :Identity
AString :=> Identity "hello!"
AnInt :=> Identity 42Often, the f we choose has an Applicative instance, and we can
use the helper function (==>). The following expressions all
have the type Applicative f => DSum Tag f:
AString ==> "hello!"
AnInt ==> 42We can write functions that consume DSum Tag f values by
matching, such as:
toString :: DSum Tag Identity -> String
toString (AString :=> Identity str) = str
toString (AnInt :=> Identity int) = show int
toString (Rec :=> Identity sum) = toString sumThe (:=>) constructor and (==>) helper are chosen to
resemble the (key => value) construction for dictionary entries
in many dynamic languages. The :=> and ==> operators have very
low precedence and bind to the right, making repeated use of these
operators behave as you'd expect:
-- Parses as: Rec ==> (AnInt ==> (3 + 4))
-- Has type: Applicative f => DSum Tag f
Rec ==> AnInt ==> 3 + 4The precedence of these operators is just above that of $, so
foo bar $ AString ==> "eep" is equivalent to foo bar (AString
==> "eep").
To use the Eq, Ord, Read, and Show instances for DSum
tag f, you will need an ArgDict instance for your tag type. Use
deriveArgDict from the
constraints-extras package to generate this
instance.
Constructors
forall a. tag a :=> f ainfixr 1
Instances4Eq, Ord, Read, Show
(GEq tag, Has' Eq tag f) => Eq (DSum tag f)Defined in dependent-sum-0.7.2.0 · Data.Dependent.Sum(GCompare tag, Has' Eq tag f, Has' Ord tag f) => Ord (DSum tag f)Defined in dependent-sum-0.7.2.0 · Data.Dependent.Sum(GRead tag, Has' Read tag f) => Read (DSum tag f)Defined in dependent-sum-0.7.2.0 · Data.Dependent.Sum(GShow tag, Has' Show tag f) => Show (DSum tag f)Defined in dependent-sum-0.7.2.0 · Data.Dependent.Sum
Propositional equality. If a :~: b is inhabited by some terminating
value, then the type a is the same as the type b. To use this equality
in practice, pattern-match on the a :~: b to get out the Refl constructor;
in the body of the pattern-match, the compiler knows that a ~ b.
Instances24Category, Groupoid, Semigroupoid, TestCoercion, TestEquality, EqP, …
Category (:~:)Defined in ghc-internal-9.1401.0 · GHC.Internal.Control.CategoryGroupoid (:~:)Defined in semigroupoids-6.0.2 · Data.GroupoidSemigroupoid (:~:)Defined in semigroupoids-6.0.2 · Data.SemigroupoidTestCoercion ((:~:) a)Defined in ghc-internal-9.1401.0 · GHC.Internal.Data.Type.CoercionTestEquality ((:~:) a)Defined in ghc-internal-9.1401.0 · GHC.Internal.Data.Type.EqualityEqP ((:~:) a)Defined in some-1.0.6 · Data.EqPGCompare ((:~:) a)Defined in some-1.0.6 · Data.GADT.InternalGEq ((:~:) a)Defined in some-1.0.6 · Data.GADT.InternalGNFData ((:~:) a)Defined in some-1.0.6 · Data.GADT.DeepSeqGRead ((:~:) a)Defined in some-1.0.6 · Data.GADT.InternalGShow ((:~:) a)Defined in some-1.0.6 · Data.GADT.InternalOrdP ((:~:) a)Defined in some-1.0.6 · Data.OrdPNFData2 (:~:)Defined in deepseq-1.5.1.0 · Control.DeepSeqNFData1 ((:~:) a)Defined in deepseq-1.5.1.0 · Control.DeepSeqa ~ b => Bounded (a :~: b)Defined in ghc-internal-9.1401.0 · GHC.Internal.Data.Type.Equalitya ~ b => Enum (a :~: b)Defined in ghc-internal-9.1401.0 · GHC.Internal.Data.Type.EqualityEq (a :~: b)Defined in ghc-internal-9.1401.0 · GHC.Internal.Data.Type.Equality(a ~ b, Data a) => Data (a :~: b)Defined in ghc-internal-9.1401.0 · GHC.Internal.Data.DataOrd (a :~: b)Defined in ghc-internal-9.1401.0 · GHC.Internal.Data.Type.Equalitya ~ b => Read (a :~: b)Defined in ghc-internal-9.1401.0 · GHC.Internal.Data.Type.EqualityShow (a :~: b)Defined in ghc-internal-9.1401.0 · GHC.Internal.Data.Type.EqualityNFData (a :~: b)Defined in deepseq-1.5.1.0 · Control.DeepSeqa ~ b => Boring (a :~: b)Defined in boring-0.2.2.1 · Data.BoringHomogeneous type equality is Boring too.
HasDict (a ~ b) (a :~: b)Defined in constraints-0.14.4 · Data.Constraint
Associated types
type family Everywhere (uni :: Type -> Type) (constr :: Type -> Constraint) :: Constraint
Methods
encodeUni :: uni a -> [Int]withDecodedUni :: (forall k (a :: k). Typeable k => uni (Esc a) -> DecodeUniM r) -> DecodeUniM rbring :: Everywhere uni constr => proxy constr -> uni (Esc a) -> (constr a => r) -> r
Instances1Closed
Closed DefaultUniDefined in plutus-core-1.70.0.0 · PlutusCore.Default.Universe
Instances16Contains, …
Contains DefaultUni ByteStringDefined in plutus-core-1.70.0.0 · PlutusCore.Default.UniverseContains DefaultUni IntegerDefined in plutus-core-1.70.0.0 · PlutusCore.Default.UniverseContains DefaultUni BoolDefined in plutus-core-1.70.0.0 · PlutusCore.Default.UniverseContains DefaultUni ElementDefined in plutus-core-1.70.0.0 · PlutusCore.Default.UniverseContains DefaultUni ElementDefined in plutus-core-1.70.0.0 · PlutusCore.Default.UniverseContains DefaultUni MlResultDefined in plutus-core-1.70.0.0 · PlutusCore.Default.UniverseContains DefaultUni DataDefined in plutus-core-1.70.0.0 · PlutusCore.Default.UniverseContains DefaultUni ValueDefined in plutus-core-1.70.0.0 · PlutusCore.Default.UniverseContains DefaultUni TextDefined in plutus-core-1.70.0.0 · PlutusCore.Default.UniverseContains DefaultUni ()Defined in plutus-core-1.70.0.0 · PlutusCore.Default.Universe(Contains DefaultUni f, Contains DefaultUni a) => Contains DefaultUni (f a)Defined in plutus-core-1.70.0.0 · PlutusCore.Default.Universe(Typeable k, Contains uni a) => Contains (Kinded uni) aDefined in plutus-core-1.70.0.0 · Universe.CoreContains DefaultUni Tuple2Defined in plutus-core-1.70.0.0 · PlutusCore.Default.UniverseContains DefaultUni VectorDefined in plutus-core-1.70.0.0 · PlutusCore.Default.UniverseContains DefaultUni []Defined in plutus-core-1.70.0.0 · PlutusCore.Default.UniverseTypeError NoStandalonePolymorphicDataErrMsg => Contains uni TyVarRepDefined in plutus-core-1.70.0.0 · PlutusCore.Builtin.Polymorphism
Constructors
DecodeUniMunDecodeUniM :: StateT [Int] Maybe a
Instances6Monad, Functor, MonadFail, Applicative, Alternative, MonadPlus
Monad DecodeUniMDefined in plutus-core-1.70.0.0 · Universe.CoreFunctor DecodeUniMDefined in plutus-core-1.70.0.0 · Universe.CoreMonadFail DecodeUniMDefined in plutus-core-1.70.0.0 · Universe.CoreApplicative DecodeUniMDefined in plutus-core-1.70.0.0 · Universe.CoreAlternative DecodeUniMDefined in plutus-core-1.70.0.0 · Universe.CoreMonadPlus DecodeUniMDefined in plutus-core-1.70.0.0 · Universe.Core
Instances1Everywhere
type Everywhere DefaultUni constr = (Permits constr Integer, Permits constr ByteString, Permits constr Text, Permits constr (), Permits constr Bool, Permits constr Value, Permits constr [], Permits constr Vector, Permits constr Tuple2, Permits constr Data, Permits constr Element, Permits constr Element, Permits constr MlResult)Defined in plutus-core-1.70.0.0 · PlutusCore.Default.Universe
type family EverywhereAll (uni :: Type -> Type) (constrs :: [Type -> Constraint]) :: Constraint whereEquations
EverywhereAll uni '[] = ()EverywhereAll uni (constr ': constrs) = (Everywhere uni constr, EverywhereAll uni constrs)
Instances1HasUniApply
HasUniApply DefaultUniDefined in plutus-core-1.70.0.0 · PlutusCore.Default.Universe
Instances4GShow, Contains, Pretty, Show
GShow uni => GShow (Kinded uni)Defined in plutus-core-1.70.0.0 · Universe.Core(Typeable k, Contains uni a) => Contains (Kinded uni) aDefined in plutus-core-1.70.0.0 · Universe.CorePretty (SomeTypeIn uni) => Pretty (SomeTypeIn (Kinded uni))Defined in plutus-core-1.70.0.0 · PlutusCore.Pretty.PrettyConst · orphanGShow uni => Show (Kinded uni ta)Defined in plutus-core-1.70.0.0 · Universe.Core
Instances4Permits
type Permits constr = Permits0 constrDefined in plutus-core-1.70.0.0 · Universe.Coretype Permits constr = Permits1 constrDefined in plutus-core-1.70.0.0 · Universe.Coretype Permits constr = Permits2 constrDefined in plutus-core-1.70.0.0 · Universe.Coretype Permits constr = Permits3 constrDefined in plutus-core-1.70.0.0 · Universe.Core
Constructors
forall k a. SomeTypeIn !(uni (Esc a))
Instances9PrettyBy, Eq, Ord, Show, NFData, Pretty, …
PrettyBy RenderContext (SomeTypeIn DefaultUni)Defined in plutus-core-1.70.0.0 · PlutusCore.Default.UniverseGEq uni => Eq (SomeTypeIn uni)Defined in plutus-core-1.70.0.0 · Universe.CoreGCompare uni => Ord (SomeTypeIn uni)Defined in plutus-core-1.70.0.0 · Universe.CoreGShow uni => Show (SomeTypeIn uni)Defined in plutus-core-1.70.0.0 · Universe.CoreClosed uni => NFData (SomeTypeIn uni)Defined in plutus-core-1.70.0.0 · Universe.CorePretty (SomeTypeIn DefaultUni)Defined in plutus-core-1.70.0.0 · PlutusCore.Default.UniversePretty (SomeTypeIn uni) => Pretty (SomeTypeIn (Kinded uni))Defined in plutus-core-1.70.0.0 · PlutusCore.Pretty.PrettyConst · orphan(Closed uni, GEq uni) => Hashable (SomeTypeIn uni)Defined in plutus-core-1.70.0.0 · Universe.CoreClosed uni => Flat (SomeTypeIn uni)Defined in plutus-core-1.70.0.0 · PlutusCore.FlatInstances · orphan
Instances16GCompare, GEq, GNFData, GShow, PrettyBy, Eq, …
(GCompare uni, Closed uni, Everywhere uni Ord, Everywhere uni Eq) => GCompare (ValueOf uni)Defined in plutus-core-1.70.0.0 · Universe.Core(GEq uni, Closed uni, Everywhere uni Eq) => GEq (ValueOf uni)Defined in plutus-core-1.70.0.0 · Universe.Core(Closed uni, Everywhere uni NFData) => GNFData (ValueOf uni)Defined in plutus-core-1.70.0.0 · Universe.Core(GShow uni, Closed uni, Everywhere uni Show) => GShow (ValueOf uni)Defined in plutus-core-1.70.0.0 · Universe.Core(Closed uni, Everywhere uni PrettyConst) => PrettyBy ConstConfig (ValueOf uni a)Defined in plutus-core-1.70.0.0 · PlutusCore.Pretty.PrettyConst(Closed uni, Everywhere uni PrettyConst) => PrettyBy ConstConfig (Some (ValueOf uni))Defined in plutus-core-1.70.0.0 · PlutusCore.Pretty.PrettyConst(GEq uni, Closed uni, Everywhere uni Eq) => Eq (ValueOf uni a)Defined in plutus-core-1.70.0.0 · Universe.Core(GCompare uni, Closed uni, Everywhere uni Ord, Everywhere uni Eq) => Ord (ValueOf uni a)Defined in plutus-core-1.70.0.0 · Universe.Core(GShow uni, Closed uni, Everywhere uni Show) => Show (ValueOf uni a)Defined in plutus-core-1.70.0.0 · Universe.Core(Closed uni, Everywhere uni NFData) => NFData (ValueOf uni a)Defined in plutus-core-1.70.0.0 · Universe.Core(Closed uni, Everywhere uni PrettyConst) => Pretty (ValueOf uni a)Defined in plutus-core-1.70.0.0 · PlutusCore.Pretty.PrettyConst · orphan(Closed uni, Everywhere uni PrettyConst) => Pretty (Some (ValueOf uni))Defined in plutus-core-1.70.0.0 · PlutusCore.Pretty.PrettyConst · orphan(Closed uni, GEq uni, Everywhere uni Eq, Everywhere uni Hashable) => Hashable (ValueOf uni a)Defined in plutus-core-1.70.0.0 · Universe.Core(Closed uni, GEq uni, Everywhere uni Eq, Everywhere uni Hashable) => Hashable (Some (ValueOf uni))Defined in plutus-core-1.70.0.0 · Universe.Core(Closed uni, Everywhere uni Flat) => Flat (Some (ValueOf uni))Defined in plutus-core-1.70.0.0 · PlutusCore.FlatInstances · orphan(Closed uni, Everywhere uni ExMemoryUsage) => ExMemoryUsage (Some (ValueOf uni))Defined in plutus-core-1.70.0.0 · PlutusCore.Evaluation.Machine.ExMemoryUsage
A class for type-contexts which contain enough information to (at least in some cases) decide the equality of types occurring within them.
This class is sometimes confused with TestEquality from base. TestEquality only checks type equality.
Consider
data Tag a where TagInt1 :: Tag Int; TagInt2 :: Tag IntThe correct TestEquality Tag instance is
:{instance TestEquality Tag where testEquality TagInt1 TagInt1 = Just Refl testEquality TagInt1 TagInt2 = Just Refl testEquality TagInt2 TagInt1 = Just Refl testEquality TagInt2 TagInt2 = Just Refl:}
While we can define
instance GEq Tag where
geq = testEquality
this will mean we probably want to have
instance Eq Tag where
_ == _ = True
Note: In the future version of some package (to be released around GHC-9.6 / 9.8) the
forall a. Eq (f a) constraint will be added as a constraint to GEq,
with a law relating GEq and Eq:
geq x y = Just Refl ⇒ x == y = True ∀ (x :: f a) (y :: f b)
x == y ≡ isJust (geq x y) ∀ (x, y :: f a)
So, the more useful GEq Tag instance would differentiate between
different constructors:
:{instance GEq Tag where geq TagInt1 TagInt1 = Just Refl geq TagInt1 TagInt2 = Nothing geq TagInt2 TagInt1 = Nothing geq TagInt2 TagInt2 = Just Refl:}
which is consistent with a derived Eq instance for Tag
deriving instance Eq (Tag a)Note that even if a ~ b, the geq (x :: f a) (y :: f b) may
be Nothing (when value terms are inequal).
The consistency of GEq and Eq is easy to check by exhaustion:
let checkFwdGEq :: (forall a. Eq (f a), GEq f) => f a -> f b -> Bool; checkFwdGEq x y = case geq x y of Just Refl -> x == y; Nothing -> True(checkFwdGEq TagInt1 TagInt1, checkFwdGEq TagInt1 TagInt2, checkFwdGEq TagInt2 TagInt1, checkFwdGEq TagInt2 TagInt2)(True,True,True,True)
let checkBwdGEq :: (Eq (f a), GEq f) => f a -> f a -> Bool; checkBwdGEq x y = if x == y then isJust (geq x y) else isNothing (geq x y)(checkBwdGEq TagInt1 TagInt1, checkBwdGEq TagInt1 TagInt2, checkBwdGEq TagInt2 TagInt1, checkBwdGEq TagInt2 TagInt2)(True,True,True,True)
Methods
geq :: f a -> f b -> Maybe (a :~: b)Produce a witness of type-equality, if one exists.
A handy idiom for using this would be to pattern-bind in the Maybe monad, eg.:
extract :: GEq tag => tag a -> DSum tag -> Maybe a extract t1 (t2 :=> x) = do Refl <- geq t1 t2 return xOr in a list comprehension:
extractMany :: GEq tag => tag a -> [DSum tag] -> [a] extractMany t1 things = [ x | (t2 :=> x) <- things, Refl <- maybeToList (geq t1 t2)](Making use of the
DSumtype from Data.Dependent.Sum in both examples)
Instances15GEq, …
GEq SBinDefined in bin-0.1.4.1 · Data.Type.BinGEq SBinPDefined in bin-0.1.4.1 · Data.Type.BinPGEq SNatDefined in fin-0.3.2 · Data.Type.NatGEq SCharDefined in some-1.0.6 · Data.GADT.InternalGEq SSymbolDefined in some-1.0.6 · Data.GADT.InternalGEq SNatDefined in some-1.0.6 · Data.GADT.InternalGEq DefaultUniDefined in plutus-core-1.70.0.0 · PlutusCore.Default.UniverseGEq TypeRepDefined in some-1.0.6 · Data.GADT.Internal(GEq uni, Closed uni, Everywhere uni Eq) => GEq (ValueOf uni)Defined in plutus-core-1.70.0.0 · Universe.CoreGEq ((:~:) a)Defined in some-1.0.6 · Data.GADT.InternalGEq ((:~~:) a)Defined in some-1.0.6 · Data.GADT.Internal(GEq a, GEq b) => GEq (Product a b)Defined in some-1.0.6 · Data.GADT.Internal(GEq a, GEq b) => GEq (Sum a b)Defined in some-1.0.6 · Data.GADT.Internal(GEq a, GEq b) => GEq (a :*: b)Defined in some-1.0.6 · Data.GADT.Internal(GEq f, GEq g) => GEq (f :+: g)Defined in some-1.0.6 · Data.GADT.Internal
Show-like class for 1-type-parameter GADTs. GShow t => ... is equivalent to something
like (forall a. Show (t a)) => .... The easiest way to create instances would probably be
to write (or derive) an instance Show (T a), and then simply say:
instance GShow t where gshowsPrec = defaultGshowsPrecMethods
gshowsPrec :: Int -> t a -> ShowS
Instances21GShow, …
GShow PosDefined in bin-0.1.4.1 · Data.Bin.PosGShow PosPDefined in bin-0.1.4.1 · Data.BinP.PosPGShow SBinDefined in bin-0.1.4.1 · Data.Type.BinGShow SBinPDefined in bin-0.1.4.1 · Data.Type.BinPGShow FinDefined in fin-0.3.2 · Data.FinGShow SNatDefined in fin-0.3.2 · Data.Type.NatGShow SCharDefined in some-1.0.6 · Data.GADT.InternalGShow SSymbolDefined in some-1.0.6 · Data.GADT.InternalGShow SNatDefined in some-1.0.6 · Data.GADT.InternalGShow DefaultUniDefined in plutus-core-1.70.0.0 · PlutusCore.Default.UniverseSNatI n => GShow (PosP' n)Defined in bin-0.1.4.1 · Data.BinP.PosPGShow TypeRepDefined in some-1.0.6 · Data.GADT.InternalGShow uni => GShow (Kinded uni)Defined in plutus-core-1.70.0.0 · Universe.Core(GShow uni, Closed uni, Everywhere uni Show) => GShow (ValueOf uni)Defined in plutus-core-1.70.0.0 · Universe.CoreGShow (GOrdering a)Defined in some-1.0.6 · Data.GADT.InternalGShow ((:~:) a)Defined in some-1.0.6 · Data.GADT.InternalGShow ((:~~:) a)Defined in some-1.0.6 · Data.GADT.Internal(GShow a, GShow b) => GShow (Product a b)Defined in some-1.0.6 · Data.GADT.InternalExample1 expression gshow (Pair Refl Refl :: Product ((:~:) Int) ((:~:) Int) Int)"Pair Refl Refl"
(GShow a, GShow b) => GShow (Sum a b)Defined in some-1.0.6 · Data.GADT.InternalExample1 expression gshow (InL Refl :: Sum ((:~:) Int) ((:~:) Bool) Int)"InL Refl"
(GShow a, GShow b) => GShow (a :*: b)Defined in some-1.0.6 · Data.GADT.InternalExample1 expression gshow (Pair Refl Refl :: Product ((:~:) Int) ((:~:) Int) Int)"Refl :*: Refl"
(GShow a, GShow b) => GShow (a :+: b)Defined in some-1.0.6 · Data.GADT.InternalExample1 expression gshow (L1 Refl :: ((:~:) Int :+: (:~:) Bool) Int)"L1 Refl"
Existential. This is type is useful to hide GADTs' parameters.
data Tag :: Type -> Type where TagInt :: Tag Int; TagBool :: Tag Boolinstance GShow Tag where gshowsPrec _ TagInt = showString "TagInt"; gshowsPrec _ TagBool = showString "TagBool"classify s = case s of "TagInt" -> [mkGReadResult TagInt]; "TagBool" -> [mkGReadResult TagBool]; _ -> []instance GRead Tag where greadsPrec _ s = [ (r, rest) | (con, rest) <- lex s, r <- classify con ]
You can either use PatternSynonyms (available with GHC >= 8.0)
let x = Some TagIntxSome TagInt
case x of { Some TagInt -> "I"; Some TagBool -> "B" } :: String"I"
or you can use functions
let y = mkSome TagBoolySome TagBool
withSome y $ \y' -> case y' of { TagInt -> "I"; TagBool -> "B" } :: String"B"
The implementation of mapSome is safe.
let f :: Tag a -> Tag a; f TagInt = TagInt; f TagBool = TagBoolmapSome f ySome TagBool
but you can also use:
withSome y (mkSome . f)Some TagBool
read "Some TagBool" :: Some TagSome TagBool
read "mkSome TagInt" :: Some TagSome TagInt
Instances12PrettyBy, Eq, Ord, Read, Show, Semigroup, …
(Closed uni, Everywhere uni PrettyConst) => PrettyBy ConstConfig (Some (ValueOf uni))Defined in plutus-core-1.70.0.0 · PlutusCore.Pretty.PrettyConstGEq tag => Eq (Some tag)Defined in some-1.0.6 · Data.Some.NewtypeGCompare tag => Ord (Some tag)Defined in some-1.0.6 · Data.Some.NewtypeGRead f => Read (Some f)Defined in some-1.0.6 · Data.Some.NewtypeGShow tag => Show (Some tag)Defined in some-1.0.6 · Data.Some.NewtypeApplicative m => Semigroup (Some m)Defined in some-1.0.6 · Data.Some.NewtypeApplicative m => Monoid (Some m)Defined in some-1.0.6 · Data.Some.NewtypeGNFData tag => NFData (Some tag)Defined in some-1.0.6 · Data.Some.Newtype(Closed uni, Everywhere uni PrettyConst) => Pretty (Some (ValueOf uni))Defined in plutus-core-1.70.0.0 · PlutusCore.Pretty.PrettyConst · orphan(Closed uni, GEq uni, Everywhere uni Eq, Everywhere uni Hashable) => Hashable (Some (ValueOf uni))Defined in plutus-core-1.70.0.0 · Universe.Core(Closed uni, Everywhere uni Flat) => Flat (Some (ValueOf uni))Defined in plutus-core-1.70.0.0 · PlutusCore.FlatInstances · orphan(Closed uni, Everywhere uni ExMemoryUsage) => ExMemoryUsage (Some (ValueOf uni))Defined in plutus-core-1.70.0.0 · PlutusCore.Evaluation.Machine.ExMemoryUsage