Control.Selective.Free

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.Free

Contents

- Free 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 free selective functors using the ideas from the Sjoerd Visscher's package 'free-functors': https://hackage.haskell.org/package/free-functors-1.0.1/docs/Data-Functor-HFree.html.

Synopsis

- newtype Select (f :: Type -> Type) a = Select (forall (g :: Type -> Type). Selective g => (forall x. f x -> g x) -> g 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 ()]
- getNecessaryEffects :: Functor f => Select f a -> [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 selective functors

newtype Select (f :: Type -> Type) a #

Free selective functors.

Constructors

Select (forall (g :: Type -> Type). Selective g => (forall x. f x -> g x) -> g a) |

#### Instances

Instances details

Applicative (Select f) # |
Instance details Defined in Control.Selective.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 (Select f) # |
Instance details Defined in Control.Selective.Free Methods fmap :: (a -> b) -> Select f a -> Select f b # (<$) :: a -> Select f b -> Select f a #
Selective (Select f) # |
Instance details Defined in Control.Selective.Free Methods select :: Select f (Either a b) -> Select f (a -> b) -> Select f b #

liftSelect :: f a -> Select f a #

Lift a functor into a free selective computation.

# Static analysis

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

Extract the resulting value if there are no necessary effects.

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

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

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

Extract all necessary effects in the order they appear in a free selective computation.

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

Given a natural transformation from `f` to `g`, this gives a canonical natural transformation from `Select f` to `g`. Note that here we rely on the fact that `g` is a lawful selective functor.

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

Concatenate all effects of a free selective computation.