selective-0.7.0.1: Selective applicative functors

Copyright | (c) Andrey Mokhov 2018-2024
License | MIT (see the file LICENSE)
Maintainer | andrey.mokhov@gmail.com
Stability | experimental
Safe Haskell | None
Language | Haskell2010

Control.Selective.Rigid.Freer

Contents

- Free rigid selective functors
- Static analysis

Description

This is a library for selective applicative functors, or just selective functors for short, an abstraction between applicative functors and monads, introduced in this paper: https://dl.acm.org/doi/10.1145/3341694.

This module defines freer rigid selective functors. Rigid selective functors are those that satisfy the property `<*> = apS`. Compared to the "free" construction from Control.Selective.Rigid.Free, this "freer" construction does not require the underlying base data type to be a functor.

Synopsis

- data Select (f :: Type -> Type) a where
  - Pure :: forall a (f :: Type -> Type). a -> Select f a
  - Select :: forall (f :: Type -> Type) x a. Select f (Either (x -> a) a) -> f x -> Select f a
- liftSelect :: f a -> Select f a
- getPure :: forall (f :: Type -> Type) a. Select f a -> Maybe a
- getEffects :: Functor f => Select f a -> [f ()]
- getNecessaryEffect :: Functor f => Select f a -> Maybe (f ())
- runSelect :: Selective g => (forall x. f x -> g x) -> Select f a -> g a
- foldSelect :: Monoid m => (forall x. f x -> m) -> Select f a -> m

# Free rigid selective functors

data Select (f :: Type -> Type) a where Source #

Free rigid selective functors.

Constructors

Pure :: forall a (f :: Type -> Type). a -> Select f a |
Select :: forall (f :: Type -> Type) x a. Select f (Either (x -> a) a) -> f x -> Select f a |

#### Instances

Instances details

Applicative (Select f) Source # |
Instance details Defined in Control.Selective.Rigid.Freer Methods pure :: a -> Select f a Source # (<*>) :: Select f (a -> b) -> Select f a -> Select f b Source # liftA2 :: (a -> b -> c) -> Select f a -> Select f b -> Select f c Source # (*>) :: Select f a -> Select f b -> Select f b Source # (<*) :: Select f a -> Select f b -> Select f a Source #
Functor (Select f) Source # |
Instance details Defined in Control.Selective.Rigid.Freer Methods fmap :: (a -> b) -> Select f a -> Select f b Source # (<$) :: a -> Select f b -> Select f a Source #
Selective (Select f) Source # |
Instance details Defined in Control.Selective.Rigid.Freer Methods select :: Select f (Either a b) -> Select f (a -> b) -> Select f b Source #

liftSelect :: f a -> Select f a Source #

Lift a functor into a free selective computation.

# Static analysis

getPure :: forall (f :: Type -> Type) a. Select f a -> Maybe a Source #

Extract the resulting value if there are no necessary effects.

getEffects :: Functor f => Select f a -> [f ()] Source #

Collect all possible effects in the order they appear in a free selective computation.

getNecessaryEffect :: Functor f => Select f a -> Maybe (f ()) Source #

Extract the necessary effect from a free selective computation. Note: there can be at most one effect that is statically guaranteed to be necessary.

runSelect :: Selective g => (forall x. f x -> g x) -> Select f a -> g a Source #

Given a natural transformation from `f` to `g`, this gives a canonical natural transformation from `Select f` to `g`.

foldSelect :: Monoid m => (forall x. f x -> m) -> Select f a -> m Source #

Concatenate all effects of a free selective computation.