module Distribution.Solver.Types.Progress
( Progress(..)
, foldProgress
) where
import Prelude ()
import Distribution.Solver.Compat.Prelude hiding (fail)
data Progress step fail done = Step step (Progress step fail done)
| Fail fail
| Done done
instance Functor (Progress step fail) where
fmap :: forall a b.
(a -> b) -> Progress step fail a -> Progress step fail b
fmap a -> b
f (Step step
s Progress step fail a
p) = forall step fail done.
step -> Progress step fail done -> Progress step fail done
Step step
s (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f Progress step fail a
p)
fmap a -> b
_ (Fail fail
x) = forall step fail done. fail -> Progress step fail done
Fail fail
x
fmap a -> b
f (Done a
r) = forall step fail done. done -> Progress step fail done
Done (a -> b
f a
r)
foldProgress :: (step -> a -> a) -> (fail -> a) -> (done -> a)
-> Progress step fail done -> a
foldProgress :: forall step a fail done.
(step -> a -> a)
-> (fail -> a) -> (done -> a) -> Progress step fail done -> a
foldProgress step -> a -> a
step fail -> a
fail done -> a
done = Progress step fail done -> a
fold
where fold :: Progress step fail done -> a
fold (Step step
s Progress step fail done
p) = step -> a -> a
step step
s (Progress step fail done -> a
fold Progress step fail done
p)
fold (Fail fail
f) = fail -> a
fail fail
f
fold (Done done
r) = done -> a
done done
r
instance Monad (Progress step fail) where
return :: forall a. a -> Progress step fail a
return = forall (f :: * -> *) a. Applicative f => a -> f a
pure
Progress step fail a
p >>= :: forall a b.
Progress step fail a
-> (a -> Progress step fail b) -> Progress step fail b
>>= a -> Progress step fail b
f = forall step a fail done.
(step -> a -> a)
-> (fail -> a) -> (done -> a) -> Progress step fail done -> a
foldProgress forall step fail done.
step -> Progress step fail done -> Progress step fail done
Step forall step fail done. fail -> Progress step fail done
Fail a -> Progress step fail b
f Progress step fail a
p
instance Applicative (Progress step fail) where
pure :: forall a. a -> Progress step fail a
pure a
a = forall step fail done. done -> Progress step fail done
Done a
a
Progress step fail (a -> b)
p <*> :: forall a b.
Progress step fail (a -> b)
-> Progress step fail a -> Progress step fail b
<*> Progress step fail a
x = forall step a fail done.
(step -> a -> a)
-> (fail -> a) -> (done -> a) -> Progress step fail done -> a
foldProgress forall step fail done.
step -> Progress step fail done -> Progress step fail done
Step forall step fail done. fail -> Progress step fail done
Fail (forall a b c. (a -> b -> c) -> b -> a -> c
flip forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Progress step fail a
x) Progress step fail (a -> b)
p
instance Monoid fail => Alternative (Progress step fail) where
empty :: forall a. Progress step fail a
empty = forall step fail done. fail -> Progress step fail done
Fail forall a. Monoid a => a
mempty
Progress step fail a
p <|> :: forall a.
Progress step fail a
-> Progress step fail a -> Progress step fail a
<|> Progress step fail a
q = forall step a fail done.
(step -> a -> a)
-> (fail -> a) -> (done -> a) -> Progress step fail done -> a
foldProgress forall step fail done.
step -> Progress step fail done -> Progress step fail done
Step (forall a b. a -> b -> a
const Progress step fail a
q) forall step fail done. done -> Progress step fail done
Done Progress step fail a
p