#ifdef TRUSTWORTHY
#endif
module Control.Lens.Internal.Review
(
Reviewable,
retagged,
Reviewed(..)
) where
import Control.Applicative
import Control.Comonad
import Control.Monad.Fix
import Data.Bifoldable
import Data.Bifunctor
import Data.Bitraversable
import Data.Distributive
import Data.Foldable
import Data.Functor.Bind
import Data.Profunctor
import Data.Profunctor.Rep
import Data.Profunctor.Unsafe
import Data.Proxy
import Data.Traversable
import Data.Void
#ifndef SAFE
import Unsafe.Coerce
#endif
class (Profunctor p, Bifunctor p) => Reviewable p
instance (Profunctor p, Bifunctor p) => Reviewable p
retagged :: (Profunctor p, Bifunctor p) => p a b -> p s b
retagged = first absurd . lmap absurd
newtype Reviewed a b = Reviewed { runReviewed :: b }
instance Functor (Reviewed a) where
fmap bc (Reviewed b) = Reviewed (bc b)
instance Apply (Reviewed a) where
(<.>) a = Reviewed #. runReviewed a .# runReviewed
a <. _ = a
_ .> b = b
instance Applicative (Reviewed a) where
pure = Reviewed
(<*>) a = Reviewed #. runReviewed a .# runReviewed
a <* _ = a
_ *> b = b
instance Comonad (Reviewed a) where
extract = runReviewed
duplicate = Reviewed
extend = ( #. ) Reviewed
instance ComonadApply (Reviewed a) where
(<@>) a = Reviewed #. runReviewed a .# runReviewed
a <@ _ = a
_ @> b = b
instance Bind (Reviewed a) where
Reviewed a >>- f = f a
instance Monad (Reviewed a) where
return = Reviewed
Reviewed a >>= f = f a
_ >> a = a
instance MonadFix (Reviewed a) where
mfix f = a where a = f (runReviewed a)
instance Foldable (Reviewed a) where
foldMap f (Reviewed b) = f b
instance Traversable (Reviewed a) where
traverse f (Reviewed b) = Reviewed <$> f b
instance Bifunctor Reviewed where
bimap _ g (Reviewed b) = Reviewed (g b)
instance Bifoldable Reviewed where
bifoldMap _ g (Reviewed b) = g b
instance Bitraversable Reviewed where
bitraverse _ g (Reviewed b) = Reviewed <$> g b
instance Distributive (Reviewed a) where
distribute = Reviewed . fmap runReviewed
instance Profunctor Reviewed where
dimap _ f (Reviewed c) = Reviewed (f c)
lmap _ (Reviewed c) = Reviewed c
rmap = fmap
Reviewed b .# _ = Reviewed b
#ifndef SAFE
( #. ) _ = unsafeCoerce
#endif
instance Choice Reviewed where
left' (Reviewed b) = Reviewed (Left b)
right' (Reviewed b) = Reviewed (Right b)
instance Corepresentable Reviewed where
type Corep Reviewed = Proxy
cotabulate f = Reviewed (f Proxy)
corep (Reviewed b) Proxy = b