{-# LANGUAGE CPP #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE Trustworthy #-}
#if __GLASGOW_HASKELL__ >= 806
{-# LANGUAGE PolyKinds #-}
#else
{-# LANGUAGE TypeInType #-}
#endif
module Control.Lens.Equality
(
Equality, Equality'
, AnEquality, AnEquality'
, (:~:)(..)
, runEq
, substEq
, mapEq
, fromEq
, simply
, simple
, equality
, equality'
, withEquality
, underEquality
, overEquality
, fromLeibniz
, fromLeibniz'
, cloneEquality
, Identical(..)
) where
import Control.Lens.Type
import Data.Proxy (Proxy)
import Data.Type.Equality ((:~:)(..))
import GHC.Exts (TYPE)
import Data.Kind (Type)
#include "lens-common.h"
data Identical a b s t where
Identical :: Identical a b a b
type AnEquality s t a b = Identical a (Proxy b) a (Proxy b) -> Identical a (Proxy b) s (Proxy t)
type AnEquality' s a = AnEquality s s a a
runEq :: AnEquality s t a b -> Identical s t a b
runEq :: forall {k} {k} (s :: k) (t :: k) (a :: k) (b :: k).
AnEquality s t a b -> Identical s t a b
runEq AnEquality s t a b
l = case AnEquality s t a b
l Identical a (Proxy b) a (Proxy b)
forall {k} {k} (a :: k) (b :: k). Identical a b a b
Identical of Identical a (Proxy b) s (Proxy t)
Identical -> Identical s t s t
Identical s t a b
forall {k} {k} (a :: k) (b :: k). Identical a b a b
Identical
{-# INLINE runEq #-}
substEq :: forall s t a b rep (r :: TYPE rep).
AnEquality s t a b -> ((s ~ a, t ~ b) => r) -> r
substEq :: forall {k} {k} (s :: k) (t :: k) (a :: k) (b :: k) r.
AnEquality s t a b -> ((s ~ a, t ~ b) => r) -> r
substEq AnEquality s t a b
l = case AnEquality s t a b -> Identical s t a b
forall {k} {k} (s :: k) (t :: k) (a :: k) (b :: k).
AnEquality s t a b -> Identical s t a b
runEq AnEquality s t a b
l of
Identical s t a b
Identical -> \(s ~ a, t ~ b) => r
r -> r
(s ~ a, t ~ b) => r
r
{-# INLINE substEq #-}
mapEq :: forall k1 k2 (s :: k1) (t :: k2) (a :: k1) (b :: k2) (f :: k1 -> Type) . AnEquality s t a b -> f s -> f a
mapEq :: forall k1 k2 (s :: k1) (t :: k2) (a :: k1) (b :: k2)
(f :: k1 -> *).
AnEquality s t a b -> f s -> f a
mapEq AnEquality s t a b
l f s
r = AnEquality s t a b -> ((s ~ a, t ~ b) => f a) -> f a
forall {k} {k} (s :: k) (t :: k) (a :: k) (b :: k) r.
AnEquality s t a b -> ((s ~ a, t ~ b) => r) -> r
substEq AnEquality s t a b
l f s
f a
(s ~ a, t ~ b) => f a
r
{-# INLINE mapEq #-}
fromEq :: AnEquality s t a b -> Equality b a t s
fromEq :: forall {k2} {k1} (s :: k2) (t :: k1) (a :: k2) (b :: k1).
AnEquality s t a b -> Equality b a t s
fromEq AnEquality s t a b
l = AnEquality s t a b
-> ((s ~ a, t ~ b) => p t (f s) -> p b (f a))
-> p t (f s)
-> p b (f a)
forall {k} {k} (s :: k) (t :: k) (a :: k) (b :: k) r.
AnEquality s t a b -> ((s ~ a, t ~ b) => r) -> r
substEq AnEquality s t a b
l p t (f s) -> p t (f s)
p t (f s) -> p b (f a)
(s ~ a, t ~ b) => p t (f s) -> p b (f a)
forall a. a -> a
id
{-# INLINE fromEq #-}
simply :: forall p f s a rep (r :: TYPE rep).
(Optic' p f s a -> r) -> Optic' p f s a -> r
simply :: forall {k} {k1} (p :: k -> k1 -> *) (f :: k -> k1) (s :: k)
(a :: k) r.
(Optic' p f s a -> r) -> Optic' p f s a -> r
simply = (Optic' p f s a -> r) -> Optic' p f s a -> r
forall a. a -> a
id
{-# INLINE simply #-}
simple :: Equality' a a
simple :: forall {k2} (a :: k2) k3 (p :: k2 -> k3 -> *) (f :: k2 -> k3).
p a (f a) -> p a (f a)
simple = p a (f a) -> p a (f a)
forall a. a -> a
id
{-# INLINE simple #-}
cloneEquality :: AnEquality s t a b -> Equality s t a b
cloneEquality :: forall {k1} {k2} (s :: k1) (t :: k2) (a :: k1) (b :: k2).
AnEquality s t a b -> Equality s t a b
cloneEquality AnEquality s t a b
an = AnEquality s t a b
-> ((s ~ a, t ~ b) => p a (f b) -> p s (f t))
-> p a (f b)
-> p s (f t)
forall {k} {k} (s :: k) (t :: k) (a :: k) (b :: k) r.
AnEquality s t a b -> ((s ~ a, t ~ b) => r) -> r
substEq AnEquality s t a b
an p a (f b) -> p s (f t)
p a (f b) -> p a (f b)
(s ~ a, t ~ b) => p a (f b) -> p s (f t)
forall a. a -> a
id
{-# INLINE cloneEquality #-}
equality :: s :~: a -> b :~: t -> Equality s t a b
equality :: forall {k1} {k2} (s :: k1) (a :: k1) (b :: k2) (t :: k2).
(s :~: a) -> (b :~: t) -> Equality s t a b
equality s :~: a
Refl b :~: t
Refl = p a (f b) -> p s (f t)
p a (f b) -> p a (f b)
forall a. a -> a
id
{-# INLINE equality #-}
equality' :: a :~: b -> Equality' a b
equality' :: forall {k2} (a :: k2) (b :: k2). (a :~: b) -> Equality' a b
equality' a :~: b
Refl = p b (f b) -> p a (f a)
p b (f b) -> p b (f b)
forall a. a -> a
id
{-# INLINE equality' #-}
overEquality :: AnEquality s t a b -> p a b -> p s t
overEquality :: forall {k} {k} (s :: k) (t :: k) (a :: k) (b :: k)
(p :: k -> k -> *).
AnEquality s t a b -> p a b -> p s t
overEquality AnEquality s t a b
an = AnEquality s t a b
-> ((s ~ a, t ~ b) => p a b -> p s t) -> p a b -> p s t
forall {k} {k} (s :: k) (t :: k) (a :: k) (b :: k) r.
AnEquality s t a b -> ((s ~ a, t ~ b) => r) -> r
substEq AnEquality s t a b
an p a b -> p s t
p a b -> p a b
(s ~ a, t ~ b) => p a b -> p s t
forall a. a -> a
id
{-# INLINE overEquality #-}
underEquality :: AnEquality s t a b -> p t s -> p b a
underEquality :: forall {k} {k} (s :: k) (t :: k) (a :: k) (b :: k)
(p :: k -> k -> *).
AnEquality s t a b -> p t s -> p b a
underEquality AnEquality s t a b
an = AnEquality s t a b
-> ((s ~ a, t ~ b) => p t s -> p b a) -> p t s -> p b a
forall {k} {k} (s :: k) (t :: k) (a :: k) (b :: k) r.
AnEquality s t a b -> ((s ~ a, t ~ b) => r) -> r
substEq AnEquality s t a b
an p t s -> p t s
p t s -> p b a
(s ~ a, t ~ b) => p t s -> p b a
forall a. a -> a
id
{-# INLINE underEquality #-}
fromLeibniz :: (Identical a b a b -> Identical a b s t) -> Equality s t a b
fromLeibniz :: forall {k1} {k2} (a :: k1) (b :: k2) (s :: k1) (t :: k2).
(Identical a b a b -> Identical a b s t) -> Equality s t a b
fromLeibniz Identical a b a b -> Identical a b s t
f = case Identical a b a b -> Identical a b s t
f Identical a b a b
forall {k} {k} (a :: k) (b :: k). Identical a b a b
Identical of Identical a b s t
Identical -> p a (f b) -> p a (f b)
p a (f b) -> p s (f t)
forall a. a -> a
id
{-# INLINE fromLeibniz #-}
fromLeibniz' :: (s :~: s -> s :~: a) -> Equality' s a
fromLeibniz' :: forall {k2} (s :: k2) (a :: k2).
((s :~: s) -> s :~: a) -> Equality' s a
fromLeibniz' (s :~: s) -> s :~: a
f = case (s :~: s) -> s :~: a
f s :~: s
forall {k} (a :: k). a :~: a
Refl of s :~: a
Refl -> p a (f a) -> p s (f s)
p a (f a) -> p a (f a)
forall a. a -> a
id
{-# INLINE fromLeibniz' #-}
withEquality :: forall s t a b rep (r :: TYPE rep).
AnEquality s t a b -> (s :~: a -> b :~: t -> r) -> r
withEquality :: forall {k} {k} (s :: k) (t :: k) (a :: k) (b :: k) r.
AnEquality s t a b -> ((s :~: a) -> (b :~: t) -> r) -> r
withEquality AnEquality s t a b
an = AnEquality s t a b
-> ((s ~ a, t ~ b) => ((s :~: a) -> (b :~: t) -> r) -> r)
-> ((s :~: a) -> (b :~: t) -> r)
-> r
forall {k} {k} (s :: k) (t :: k) (a :: k) (b :: k) r.
AnEquality s t a b -> ((s ~ a, t ~ b) => r) -> r
substEq AnEquality s t a b
an (\(s :~: a) -> (b :~: t) -> r
f -> (s :~: a) -> (b :~: t) -> r
f s :~: s
s :~: a
forall {k} (a :: k). a :~: a
Refl b :~: t
b :~: b
forall {k} (a :: k). a :~: a
Refl)
{-# INLINE withEquality #-}