free-alternative-other
Safe HaskellNone
LanguageHaskell2010

Control.Applicative.Free.Zero

Description

An applicative with left zero f is an Applicative with polymorphic zero action which stops all actions right to zero.

-- Type of zero action
zero :: forall a. f a

-- Left zero law
zero <*> x === zero

This module provides the free Applicative with zero, ApZ, like the free applicative Ap.

Synopsis

Documentation

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

Free (applicative with left zero).

Constructors

Pure :: forall a (f :: Type -> Type). a -> ApZ f a 
Zero :: forall (f :: Type -> Type) a. ApZ f a 
Ap :: forall (f :: Type -> Type) a1 a. f a1 -> ApZ f (a1 -> a) -> ApZ f a 

Instances

Instances details
FFunctor ApZ Source # 
Instance details

Defined in Control.Applicative.Free.Zero

Methods

ffmap :: forall (g :: Type -> Type) (h :: Type -> Type) x. (Functor g, Functor h) => (g ~> h) -> ApZ g x -> ApZ h x #

FMonad ApZ Source # 
Instance details

Defined in Control.Applicative.Free.Zero

Methods

fpure :: forall (g :: Type -> Type). Functor g => g ~> ApZ g #

fbind :: forall (g :: Type -> Type) (h :: Type -> Type) a. (Functor g, Functor h) => (g ~> ApZ h) -> ApZ g a -> ApZ h a #

Alternative (ApZ f) Source #

Left zero + Left catch

Instance details

Defined in Control.Applicative.Free.Zero

Methods

empty :: ApZ f a #

(<|>) :: ApZ f a -> ApZ f a -> ApZ f a #

some :: ApZ f a -> ApZ f [a] #

many :: ApZ f a -> ApZ f [a] #

Applicative (ApZ f) Source # 
Instance details

Defined in Control.Applicative.Free.Zero

Methods

pure :: a -> ApZ f a #

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

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

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

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

Functor (ApZ f) Source # 
Instance details

Defined in Control.Applicative.Free.Zero

Methods

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

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

liftApZ :: f a -> ApZ f a Source #

hoistApZ :: (forall x. f x -> g x) -> ApZ f a -> ApZ g a Source #

trap :: forall (f :: Type -> Type) a. ApZ f a -> ApZ f a -> ApZ f a Source #

Recovery from Zero.

trap x y first look at x if it ends with Zero constructor. If x ends with Pure, return x itself. Otherwise, it replaces Zero in x with y.

trap (Ap f1 (Ap f2 ... Zero)) y === Ap f1 (Ap f2 ... y)

foldApZ :: Applicative g => (forall r. f r -> g r) -> (forall r. g r) -> ApZ f a -> g a Source #

foldMaybeT :: Monad g => (forall r. f r -> g r) -> ApZ f a -> g (Maybe a) Source #

retract :: Alternative f => ApZ f a -> f a Source #