Cabal-2.2.0.0: A framework for packaging Haskell software

Safe HaskellNone
LanguageHaskell2010

Distribution.Utils.Progress

Description

A progress monad, which we use to report failure and logging from otherwise pure code.

Synopsis

Documentation

data Progress step fail done #

A type to represent the unfolding of an expensive long running calculation that may fail (or maybe not expensive, but complicated!) We may get intermediate steps before the final result which may be used to indicate progress and/or logging messages.

TODO: Apply Codensity to avoid left-associativity problem. See http://comonad.com/reader/2011/free-monads-for-less/ and http://blog.ezyang.com/2012/01/problem-set-the-codensity-transformation/

Instances

Monad (Progress step fail) # 

Methods

(>>=) :: Progress step fail a -> (a -> Progress step fail b) -> Progress step fail b #

(>>) :: Progress step fail a -> Progress step fail b -> Progress step fail b #

return :: a -> Progress step fail a #

fail :: String -> Progress step fail a #

Functor (Progress step fail) # 

Methods

fmap :: (a -> b) -> Progress step fail a -> Progress step fail b #

(<$) :: a -> Progress step fail b -> Progress step fail a #

Applicative (Progress step fail) # 

Methods

pure :: a -> Progress step fail a #

(<*>) :: Progress step fail (a -> b) -> Progress step fail a -> Progress step fail b #

liftA2 :: (a -> b -> c) -> Progress step fail a -> Progress step fail b -> Progress step fail c #

(*>) :: Progress step fail a -> Progress step fail b -> Progress step fail b #

(<*) :: Progress step fail a -> Progress step fail b -> Progress step fail a #

Monoid fail => Alternative (Progress step fail) # 

Methods

empty :: Progress step fail a #

(<|>) :: Progress step fail a -> Progress step fail a -> Progress step fail a #

some :: Progress step fail a -> Progress step fail [a] #

many :: Progress step fail a -> Progress step fail [a] #

stepProgress :: step -> Progress step fail () #

Emit a step and then continue.

failProgress :: fail -> Progress step fail done #

Fail the computation.

foldProgress :: (step -> a -> a) -> (fail -> a) -> (done -> a) -> Progress step fail done -> a #

Consume a Progress calculation. Much like foldr for lists but with two base cases, one for a final result and one for failure.

Eg to convert into a simple Either result use:

foldProgress (flip const) Left Right