Community
Modules 24

Control.Applicative.Lift

experimental

Adding a new kind of pure computation to an applicative functor.

Lifting an applicative

data Lift f a

Applicative functor formed by adding pure computations to a given applicative functor.

Pure :: a -> Lift f a

Other :: (f a) -> Lift f a

unLift :: (Applicative f) => Lift f a -> f a

Projection to the other functor.

mapLift :: (f a -> g a) -> Lift f a -> Lift g a

Apply a transformation to the other computation.

elimLift :: (a -> r) -> (f a -> r) -> Lift f a -> r

Eliminator for Lift.

  • elimLift f g . pure = f

  • elimLift f g . Other = g

Collecting errors

type Errors e = Lift (Constant e)

An applicative functor that collects a monoid (e.g. lists) of errors. A sequence of computations fails if any of its components do, but unlike monads made with ExceptT from Control.Monad.Trans.Except, these computations continue after an error, collecting all the errors.

  • pure f <*> pure x = pure (f x)

  • pure f <*> failure e = failure e

  • failure e <*> pure x = failure e

  • failure e1 <*> failure e2 = failure (e1 <> e2)

runErrors :: Errors e a -> Either e a

Extractor for computations with accumulating errors.

  • runErrors (pure x) = Right x

  • runErrors (failure e) = Left e

failure :: e -> Errors e a

Report an error.

eitherToErrors :: Either e a -> Errors e a

Convert from Either to Errors (inverse of runErrors).

Instances

16
  • instance (Generic f, Generic a) => Generic (Lift f a)
  • instance (Generic1 f, Generic1 a) => Generic1 (Lift f a)
  • instance (Eq1 f) => Eq1 (Lift f)
  • instance (Ord1 f) => Ord1 (Lift f)
  • instance (Read1 f) => Read1 (Lift f)
  • instance (Show1 f) => Show1 (Lift f)
  • instance (Eq1 f, Eq a) => Eq (Lift f a)
  • instance (Ord1 f, Ord a) => Ord (Lift f a)
  • instance (Read1 f, Read a) => Read (Lift f a)
  • instance (Show1 f, Show a) => Show (Lift f a)
  • instance (Functor f) => Functor (Lift f)
  • instance (Foldable f) => Foldable (Lift f)
  • instance (Traversable f) => Traversable (Lift f)
  • instance (Applicative f) => Applicative (Lift f)

    A combination is Pure only if both parts are.

  • instance (Alternative f) => Alternative (Lift f)

    A combination is Pure only either part is.

  • instance (Foldable1 f) => Foldable1 (Lift f)
Maintainer
R.Paterson@city.ac.uk
Portability
portable
Copyright
(c) Ross Paterson 2010
License
BSD-style (see the file LICENSE)
Build record and source files

Community contribution. The service has not verified this documentation.

Target: Linux on x86-64. Some inferred types and resolved links are not available.

Generator: aihc-haddock-858b1951-web-1

Metadata snapshot: ac77ab7d2b1e88487eeab41661abedb7bfb8bc846deb92e7874c08d166bff65d

Open the dependency plan · Download the documentation model

Import a package

Enter a package name and an exact version from Hackage. The site contains imported versions only.