selective-0.4.2: Selective applicative functors
Copyright(c) Andrey Mokhov 2018-2019
LicenseMIT (see the file LICENSE)
Maintainerandrey.mokhov@gmail.com
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Control.Selective.Rigid.Free

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://www.staff.ncl.ac.uk/andrey.mokhov/selective-functors.pdf.

This module defines free rigid selective functors. Rigid selective functors are those that satisfy the property <*> = apS.

Intuitively, a selective functor f is "rigid" if any expression f a is equivalent to a list of effects chained with select operators (the normal form given by the free construction). In contrast, "non-rigid" selective functors can have non-linear, tree-like shapes, because * nodes can't be straightened using the <*> = apS equation.

Synopsis

Free rigid selective functors

data Select f a where Source #

Free rigid selective functors.

Constructors

Pure :: a -> Select f a 
Select :: Select f (Either a b) -> f (a -> b) -> Select f b 

Instances

Instances details
Functor f => Functor (Select f) Source # 
Instance details

Defined in Control.Selective.Rigid.Free

Methods

fmap :: (a -> b) -> Select f a -> Select f b #

(<$) :: a -> Select f b -> Select f a #

Functor f => Applicative (Select f) Source # 
Instance details

Defined in Control.Selective.Rigid.Free

Methods

pure :: a -> Select f a #

(<*>) :: Select f (a -> b) -> Select f a -> Select f b #

liftA2 :: (a -> b -> c) -> Select f a -> Select f b -> Select f c #

(*>) :: Select f a -> Select f b -> Select f b #

(<*) :: Select f a -> Select f b -> Select f a #

Functor f => Selective (Select f) Source # 
Instance details

Defined in Control.Selective.Rigid.Free

Methods

select :: Select f (Either a b) -> Select f (a -> b) -> Select f b Source #

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

Lift a functor into a free selective computation.

Static analysis

getPure :: 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.