Question

I wrote about transformers in a recent blog post, and someone asked "what do people use Control.Applicative.Lift for?" I wasn't able to answer this, so I echo the question to StackOverflow - what is Control.Applicative.Lift used for?

I see one example use of it in the package, but I don't seem to be entirely able to parse what it does. Does anyone know any other examples in the wild?

Was it helpful?

Solution

Lift is a relatively new contribution:

data Lift f a = Pure a | Other (f a)

That is, given a functor f , you can get a new functor by composing f with a pure value.

The package itself gives an example:

-- | 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 'ErrorT' from "Control.Monad.Trans.Error",
-- these computations continue after an error, collecting all the errors.
type Errors e = Lift (Constant e)

-- | Report an error.
failure :: Monoid e => e -> Errors e a
failure e = Other (Constant e)

I don't know of any in-the-wild uses of this, however.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top