HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulepolysemy-zoo-0.8.2.0Haskell2010

Polysemy.ConstraintAbsorber

  • 3 types
  • 1 class
  • 1 value
  • Packagepolysemy-zoo-0.8.2.0
  • Exports6
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceConstraintAbsorber.hs

Absorb builder

1 declaration
valueabsorbWithSem
  1. :: d

    Reified dictionary

  2. -> (forall s. Reifies s d :- p (x (Sem r) s))

    This parameter should always be Sub Dict

  3. -> (p (Sem r) => Sem r a)
  4. -> Sem r a
#

This function can be used to locally introduce typeclass instances for Sem. See Polysemy.ConstraintAbsorber.MonadState for an example of how to use it.

Re-exports

5 declarations
classclass Reifies (s :: k) a | s -> a where
#
Instances8Reifies, …
  • KnownSymbol n => Reifies n StringDefined in reflection-2.1.9 · Data.Reflection
  • KnownNat n => Reifies n IntegerDefined in reflection-2.1.9 · Data.Reflection
  • Reifies Z IntDefined in reflection-2.1.9 · Data.Reflection
  • Reifies n Int => Reifies (D n) IntDefined in reflection-2.1.9 · Data.Reflection
  • Reifies n Int => Reifies (PD n) IntDefined in reflection-2.1.9 · Data.Reflection
  • Reifies n Int => Reifies (SD n) IntDefined in reflection-2.1.9 · Data.Reflection
  • Reifies (StableBox w0 w1 a) (Box b) => Reifies (Stable w0 w1 a) bDefined in reflection-2.1.9 · Data.Reflection
  • (B b0, B b1, B b2, B b3, B b4, B b5, B b6, B b7, w0 ~ W b0 b1 b2 b3, w1 ~ W b4 b5 b6 b7) => Reifies (StableBox w0 w1 a) (Box a)Defined in reflection-2.1.9 · Data.Reflection
newtypenewtype (:-) (a :: Constraint) (b :: Constraint)
#

This is the type of entailment.

a :- b is read as a "entails" b.

With this we can actually build a category for Constraint resolution.

e.g.

Because Eq a is a superclass of Ord a, we can show that Ord a entails Eq a.

Because instance Ord a => Ord [a] exists, we can show that Ord a entails Ord [a] as well.

This relationship is captured in the :- entailment type here.

Since p :- p and entailment composes, :- forms the arrows of a Category of constraints. However, Category only became sufficiently general to support this instance in GHC 7.8, so prior to 7.8 this instance is unavailable.

But due to the coherence of instance resolution in Haskell, this Category has some very interesting properties. Notably, in the absence of IncoherentInstances, this category is "thin", which is to say that between any two objects (constraints) there is at most one distinguishable arrow.

This means that for instance, even though there are two ways to derive Ord a :- Eq [a], the answers from these two paths _must_ by construction be equal. This is a property that Haskell offers that is pretty much unique in the space of languages with things they call "type classes".

What are the two ways?

Well, we can go from Ord a :- Eq a via the superclass relationship, and then from Eq a :- Eq [a] via the instance, or we can go from Ord a :- Ord [a] via the instance then from Ord [a] :- Eq [a] through the superclass relationship and this diagram by definition must "commute".

Diagrammatically,

                   Ord a
               ins /     \ cls
                  v       v
            Ord [a]     Eq a
               cls \     / ins
                    v   v
                   Eq [a]

This safety net ensures that pretty much anything you can write with this library is sensible and can't break any assumptions on the behalf of library authors.

Constructors

Instances10Category, :=>, HasDict, Eq, Data, Ord, …
  • Category (:-)Defined in constraints-0.14.2 · Data.Constraint

    Possible since GHC 7.8, when Category was made polykinded.

  • () :=> Show (a :- b)Defined in constraints-0.14.2 · Data.Constraint
  • () :=> Eq (a :- b)Defined in constraints-0.14.2 · Data.Constraint
  • () :=> Ord (a :- b)Defined in constraints-0.14.2 · Data.Constraint
  • a => HasDict b (a :- b)Defined in constraints-0.14.2 · Data.Constraint
  • Eq (a :- b)Defined in constraints-0.14.2 · Data.Constraint

    Assumes IncoherentInstances doesn't exist.

  • (Typeable p, Typeable q, p => q) => Data (p :- q)Defined in constraints-0.14.2 · Data.Constraint
  • Ord (a :- b)Defined in constraints-0.14.2 · Data.Constraint

    Assumes IncoherentInstances doesn't exist.

  • Show (a :- b)Defined in constraints-0.14.2 · Data.Constraint
  • a => NFData (a :- b)Defined in constraints-0.14.2 · Data.Constraint
datadata Dict (a :: Constraint) where
#

Values of type Dict p capture a dictionary for a constraint of type p.

e.g.

Dict :: Dict (Eq Int)

captures a dictionary that proves we have an:

instance Eq Int

Pattern matching on the Dict constructor will bring this instance into scope.

Constructors

Instances20:=>, HasDict, Bounded, Enum, Eq, Data, …
  • () :=> Semigroup (Dict a)Defined in constraints-0.14.2 · Data.Constraint
  • () :=> Show (Dict a)Defined in constraints-0.14.2 · Data.Constraint
  • () :=> Eq (Dict a)Defined in constraints-0.14.2 · Data.Constraint
  • () :=> Ord (Dict a)Defined in constraints-0.14.2 · Data.Constraint
  • a :=> Monoid (Dict a)Defined in constraints-0.14.2 · Data.Constraint
  • a :=> Bounded (Dict a)Defined in constraints-0.14.2 · Data.Constraint
  • a :=> Enum (Dict a)Defined in constraints-0.14.2 · Data.Constraint
  • a :=> Read (Dict a)Defined in constraints-0.14.2 · Data.Constraint
  • HasDict a (Dict a)Defined in constraints-0.14.2 · Data.Constraint
  • a => Bounded (Dict a)Defined in constraints-0.14.2 · Data.Constraint
  • a => Enum (Dict a)Defined in constraints-0.14.2 · Data.Constraint
  • Eq (Dict a)Defined in constraints-0.14.2 · Data.Constraint
  • (Typeable p, p) => Data (Dict p)Defined in constraints-0.14.2 · Data.Constraint
  • Ord (Dict a)Defined in constraints-0.14.2 · Data.Constraint
  • a => Read (Dict a)Defined in constraints-0.14.2 · Data.Constraint
  • Show (Dict a)Defined in constraints-0.14.2 · Data.Constraint
  • Semigroup (Dict a)Defined in constraints-0.14.2 · Data.Constraint
  • a => Monoid (Dict a)Defined in constraints-0.14.2 · Data.Constraint
  • NFData (Dict c)Defined in constraints-0.14.2 · Data.Constraint
  • c => Boring (Dict c)Defined in constraints-0.14.2 · Data.Constraint
methodreflect :: proxy s -> a
#

Recover a value inside a reify context, given a proxy for its reified type.

datadata Proxy (t :: k)
#

Proxy is a type that holds no data, but has a phantom parameter of arbitrary type (or even kind). Its use is to provide type information, even though there is no value available of that type (or it may be too costly to create one).

Historically, Proxy :: Proxy a is a safer alternative to the undefined :: a idiom.

Example1 expression
Proxy :: Proxy (Void, Int -> Int)Proxy

Proxy can even hold types of higher kinds,

Example1 expression
Proxy :: Proxy EitherProxy
Example1 expression
Proxy :: Proxy FunctorProxy
Example1 expression
Proxy :: Proxy complicatedStructureProxy
Instances34Generic1, Monad, Functor, Applicative, Foldable, Traversable, …
  • Generic1 ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Monad ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • Functor ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • Applicative ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • Foldable ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Foldable
  • Traversable ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Traversable
  • Alternative ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • MonadPlus ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • MonadZip ProxyDefined in base-4.20.2.0 · Control.Monad.Zip
  • Eq1 ProxyDefined in base-4.20.2.0 · Data.Functor.Classes
  • Ord1 ProxyDefined in base-4.20.2.0 · Data.Functor.Classes
  • Read1 ProxyDefined in base-4.20.2.0 · Data.Functor.Classes
  • Show1 ProxyDefined in base-4.20.2.0 · Data.Functor.Classes
  • Contravariant ProxyDefined in base-4.20.2.0 · Data.Functor.Contravariant
  • NFData1 ProxyDefined in deepseq-1.5.0.0 · Control.DeepSeq
  • Hashable1 ProxyDefined in hashable-1.4.7.0 · Data.Hashable.Class
  • Decidable ProxyDefined in contravariant-1.5.5 · Data.Functor.Contravariant.Divisible
  • Divisible ProxyDefined in contravariant-1.5.5 · Data.Functor.Contravariant.Divisible
  • Bounded (Proxy t)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • Enum (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • Eq (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • Data t => Data (Proxy t)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Data
  • Ord (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • Read (Proxy t)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • Show (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • Ix (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • Generic (Proxy t)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Semigroup (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • Monoid (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • NFData (Proxy a)Defined in deepseq-1.5.0.0 · Control.DeepSeq
  • Hashable (Proxy a)Defined in hashable-1.4.7.0 · Data.Hashable.Class
  • Boring (Proxy a)Defined in boring-0.2.2 · Data.Boring
  • type Rep (Proxy t) = D1 ('MetaData "Proxy" "GHC.Internal.Data.Proxy" "ghc-internal" 'False) (C1 ('MetaCons "Proxy" 'PrefixI 'False) U1)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • type Rep1 Proxy = D1 ('MetaData "Proxy" "GHC.Internal.Data.Proxy" "ghc-internal" 'False) (C1 ('MetaCons "Proxy" 'PrefixI 'False) U1)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics