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

Modulererebase-1.21.2Haskell2010

Control.Selective.Multi

  • 11 types
  • 4 classes
  • 24 values
classclass Applicative f => Selective (f :: Type -> Type) where
#

Multi-way selective functors. Given a computation that produces a value of a sum type, we can match it to the corresponding computation in a given product type.

For greater similarity with matchCases, we could have given the following type to match:

match :: f (Sigma t) -> (t ~> Case f a) -> f a

We chose to simplify it by inlining ~> and Case.

Methods

Instances2Selective
valueapS :: Selective f => f a -> f (a -> b) -> f b
#

Recover the application operator <*> from match.

valuebindS :: (Enum a, Selective f) => f a -> (a -> f b) -> f b
#

A restricted version of monadic bind.

valuematchM :: Monad f => f (Sigma t) -> (forall x. t x -> f (x -> a)) -> f a
#

Every monad is a multi-way selective functor.

newtypenewtype Over m a
#

Static analysis of selective functors with over-approximation.

Constructors

Instances6Functor, Applicative, Selective, Eq, Ord, Show
  • Functor (Over m)Defined in selective-0.7.0.1 · Control.Selective.Multi
  • Monoid m => Applicative (Over m)Defined in selective-0.7.0.1 · Control.Selective.Multi
  • Monoid m => Selective (Over m)Defined in selective-0.7.0.1 · Control.Selective.Multi
  • Eq m => Eq (Over m a)Defined in selective-0.7.0.1 · Control.Selective.Multi
  • Ord m => Ord (Over m a)Defined in selective-0.7.0.1 · Control.Selective.Multi
  • Show m => Show (Over m a)Defined in selective-0.7.0.1 · Control.Selective.Multi
newtypenewtype Under m a
#

Static analysis of selective functors with under-approximation.

Constructors

Instances6Functor, Applicative, Selective, Eq, Ord, Show
  • Functor (Under m)Defined in selective-0.7.0.1 · Control.Selective.Multi
  • Monoid m => Applicative (Under m)Defined in selective-0.7.0.1 · Control.Selective.Multi
  • Monoid m => Selective (Under m)Defined in selective-0.7.0.1 · Control.Selective.Multi
  • Eq m => Eq (Under m a)Defined in selective-0.7.0.1 · Control.Selective.Multi
  • Ord m => Ord (Under m a)Defined in selective-0.7.0.1 · Control.Selective.Multi
  • Show m => Show (Under m a)Defined in selective-0.7.0.1 · Control.Selective.Multi
datadata One a b where
#

A data type with a single tag. This data type is commonly known as Refl, see Data.Type.Equality.

Constructors

Instances1Enumerable
  • Enumerable (One a)Defined in selective-0.7.0.1 · Control.Selective.Multi
datadata Many a b where
#

A potentially uncountable collection of tags for the same unit () payload.

Constructors

Instances1Enumerable
valuecompose :: u ~> v -> t ~> u -> t ~> v
#

As it turns out, one can compose such generalised products. Why not: given a tag, get the payload of the first product and then pass it as input to the second. This feels too trivial to be useful but is still somewhat cute.

datadata Zero a
#

A data type defining no tags. Similar to Void but parameterised.

Instances1Enumerable
  • Enumerable ZeroDefined in selective-0.7.0.1 · Control.Selective.Multi
valueapply :: t ~> u -> Sigma t -> Sigma u
#

Update a generalised sum given a generalised product that takes care of all possible cases.

valuebind :: MonadS f => f a -> (a -> f b) -> f b
#

Monadic bind.

valuefromPi :: Pi (One a) -> a
#

Decode a value from a generalised product type that has a single tag One.

valuefromSigma :: Sigma (One a) -> a
#

Decode a value from a generalised sum type that has a single tag One.

valueidentity :: t x -> t x
#

A trivial product type that stores nothing and simply returns the given tag as the result.

valueinject :: t x -> x -> Sigma t
#

An injection into a generalised sum. An alias for Sigma.

valuematchCases :: Functor f => Sigma t -> t ~> Case f a -> f a
#

Generalised pattern matching on a Sigma type using a Pi type to describe how to handle each case.

valuematchPure :: Sigma t -> (forall x. t x -> x -> a) -> a
#

Generalised pattern matching on a Sigma type using a Pi type to describe how to handle each case.

This is a specialisation of matchCases for f = Identity. We could also have also given it the following type:

matchPure :: Sigma t -> (t ~> Case Identity a) -> a

We chose to simplify it by inlining ~>, Case and Identity.

valuepairToPi :: (a, b) -> Pi (Two a b)
#

Encode (a, b) into a generalised product type.

valuepiToPair :: Pi (Two a b) -> (a, b)
#

Decode (a, b) from a generalised product type.

valueproject :: t a -> Pi t -> a
#

A projection from a generalised product.

valuetoPi :: a -> Pi (One a)
#

Encode a value into a generalised product type that has a single tag One.

valuetoSigma :: a -> Sigma (One a)
#

Encode a value into a generalised sum type that has a single tag One.

classclass Enumerable (t :: Type -> Type) where
#

A class of tags that can be enumerated.

A valid instance must list every tag in the resulting list exactly once.

Methods

Instances4Enumerable
  • Enumerable ZeroDefined in selective-0.7.0.1 · Control.Selective.Multi
  • Enum a => Enumerable (Many a)Defined in selective-0.7.0.1 · Control.Selective.Multi
  • Enumerable (One a)Defined in selective-0.7.0.1 · Control.Selective.Multi
  • Enumerable (Two a b)Defined in selective-0.7.0.1 · Control.Selective.Multi
typetype Pi (t :: Type -> Type) = t ~> Identity
#

A product type where the payload has the type specified with the tag.

datadata Sigma (t :: Type -> Type) where
#

A generalised sum type where t stands for the type of constructor "tags". Each tag has a type parameter x which determines the type of the payload. A Sigma t value therefore contains a payload whose type is not visible externally but is revealed when pattern-matching on the tag.

See Two, eitherToSigma and sigmaToEither for an example.

Constructors

typetype (~>) (t :: Type -> Type) (u :: Type -> Type) = forall x. t x -> u x
#

A generalised product type (Pi), which holds an appropriately tagged payload u x for every possible tag t x.

Note that this looks different than the standard formulation of Pi types. Maybe it's just all wrong!

See Two, pairToPi and piToPair for an example.