{-# LANGUAGE CPP #-}
module LensDefs
(module LensDefs,
module Control.Applicative,
Choice,
Profunctor,
Coercible)
where
import Data.Profunctor
import Data.Profunctor.Unsafe
import Control.Applicative
import Control.Monad.Identity
import Unsafe.Coerce
#if __GLASGOW_HASKELL__ > 707
import GHC.Exts(Coercible)
#else
import GHC.Exts(Constraint)
type Coercible a b = (() :: Constraint)
#endif
type Equality' s a = forall p (f :: * -> *). a `p` f a -> s `p` f s
isSimple :: optic ~ (p a (f a) -> p s (f s)) => optic -> optic
isSimple :: forall {k} {k} optic (p :: k -> k -> *) (a :: k) (f :: k -> k)
(s :: k).
(optic ~ (p a (f a) -> p s (f s))) =>
optic -> optic
isSimple = forall a. a -> a
id
simple :: Equality' a a
simple :: forall a. Equality' a a
simple = forall a. a -> a
id
infixl 1 &
t
x & :: t -> (t -> t) -> t
& t -> t
f = t -> t
f t
x
infixr 4 %~
p a (Identity b) -> t -> Identity a
l %~ :: (p a (Identity b) -> t -> Identity a) -> p a b -> t -> a
%~ p a b
f = \t
t -> forall a. Identity a -> a
runIdentity forall a b. (a -> b) -> a -> b
$ p a (Identity b) -> t -> Identity a
l (forall (p :: * -> * -> *) b c a.
Profunctor p =>
(b -> c) -> p a b -> p a c
rmap forall a. a -> Identity a
Identity p a b
f) t
t
iso :: (Profunctor p, Functor f)
=> (s -> a) -> (b -> t)
-> p a (f b) -> p s (f t)
iso :: forall (p :: * -> * -> *) (f :: * -> *) s a b t.
(Profunctor p, Functor f) =>
(s -> a) -> (b -> t) -> p a (f b) -> p s (f t)
iso s -> a
sa b -> t
bt = forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap s -> a
sa (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> t
bt)
isoNewtype :: (Profunctor p, Functor f,
Coercible b t,
Coercible a s)
=> (s -> a) -> (b -> t)
-> p a (f b) -> p s (f t)
isoNewtype :: forall (p :: * -> * -> *) (f :: * -> *) b t a s.
(Profunctor p, Functor f, Coercible b t, Coercible a s) =>
(s -> a) -> (b -> t) -> p a (f b) -> p s (f t)
isoNewtype s -> a
sa b -> t
_bt p a (f b)
x = forall {k} {k} {k} (p :: k -> k -> *) (a :: k) (f :: k -> k)
(b :: k) (t :: k).
p a (f b) -> p a (f t)
coerceBT p a (f b)
x forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible b a) =>
p b c -> q a b -> p a c
.# s -> a
sa
where coerceBT :: p a (f b) -> p a (f t)
coerceBT :: forall {k} {k} {k} (p :: k -> k -> *) (a :: k) (f :: k -> k)
(b :: k) (t :: k).
p a (f b) -> p a (f t)
coerceBT = forall a b. a -> b
unsafeCoerce
prism :: (b -> t) -> (s -> Either t a)
-> (forall p f. (Choice p, Applicative f) => p a (f b) -> p s (f t))
prism :: forall b t s a.
(b -> t)
-> (s -> Either t a)
-> forall (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p a (f b) -> p s (f t)
prism b -> t
bt s -> Either t a
seta = forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap s -> Either t a
seta (forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> t
bt)) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) a b c.
Choice p =>
p a b -> p (Either c a) (Either c b)
right'
prism' :: (a -> s) -> (s -> Maybe a)
-> (forall p f. (Choice p, Applicative f) => p a (f a) -> p s (f s))
prism' :: forall a s.
(a -> s)
-> (s -> Maybe a)
-> forall (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p a (f a) -> p s (f s)
prism' a -> s
bs s -> Maybe a
sma = forall b t s a.
(b -> t)
-> (s -> Either t a)
-> forall (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p a (f b) -> p s (f t)
prism a -> s
bs (\s
s -> forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall a b. a -> Either a b
Left s
s) forall a b. b -> Either a b
Right (s -> Maybe a
sma s
s))