{-# LANGUAGE DataKinds #-}

module U.Codebase.Referent where

import Control.Lens (Prism, Traversal)
import Data.Bifoldable (Bifoldable (..))
import Data.Bitraversable (Bitraversable (..))
import Data.Generics.Sum (_Ctor)
import U.Codebase.Decl (ConstructorId)
import U.Codebase.Reference (Reference, Reference')
import U.Codebase.Reference qualified as Reference
import Unison.Hash (Hash)
import Unison.OrBuiltin (OrBuiltin (..))
import Unison.Prelude
import Unison.ShortHash (ShortHash)
import Unison.ShortHash qualified as SH

data ConstructorType
  = DataConstructor
  | EffectConstructor
  deriving (Int -> ConstructorType -> ShowS
[ConstructorType] -> ShowS
ConstructorType -> String
(Int -> ConstructorType -> ShowS)
-> (ConstructorType -> String)
-> ([ConstructorType] -> ShowS)
-> Show ConstructorType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ConstructorType -> ShowS
showsPrec :: Int -> ConstructorType -> ShowS
$cshow :: ConstructorType -> String
show :: ConstructorType -> String
$cshowList :: [ConstructorType] -> ShowS
showList :: [ConstructorType] -> ShowS
Show, ConstructorType -> ConstructorType -> Bool
(ConstructorType -> ConstructorType -> Bool)
-> (ConstructorType -> ConstructorType -> Bool)
-> Eq ConstructorType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ConstructorType -> ConstructorType -> Bool
== :: ConstructorType -> ConstructorType -> Bool
$c/= :: ConstructorType -> ConstructorType -> Bool
/= :: ConstructorType -> ConstructorType -> Bool
Eq, Eq ConstructorType
Eq ConstructorType =>
(ConstructorType -> ConstructorType -> Ordering)
-> (ConstructorType -> ConstructorType -> Bool)
-> (ConstructorType -> ConstructorType -> Bool)
-> (ConstructorType -> ConstructorType -> Bool)
-> (ConstructorType -> ConstructorType -> Bool)
-> (ConstructorType -> ConstructorType -> ConstructorType)
-> (ConstructorType -> ConstructorType -> ConstructorType)
-> Ord ConstructorType
ConstructorType -> ConstructorType -> Bool
ConstructorType -> ConstructorType -> Ordering
ConstructorType -> ConstructorType -> ConstructorType
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ConstructorType -> ConstructorType -> Ordering
compare :: ConstructorType -> ConstructorType -> Ordering
$c< :: ConstructorType -> ConstructorType -> Bool
< :: ConstructorType -> ConstructorType -> Bool
$c<= :: ConstructorType -> ConstructorType -> Bool
<= :: ConstructorType -> ConstructorType -> Bool
$c> :: ConstructorType -> ConstructorType -> Bool
> :: ConstructorType -> ConstructorType -> Bool
$c>= :: ConstructorType -> ConstructorType -> Bool
>= :: ConstructorType -> ConstructorType -> Bool
$cmax :: ConstructorType -> ConstructorType -> ConstructorType
max :: ConstructorType -> ConstructorType -> ConstructorType
$cmin :: ConstructorType -> ConstructorType -> ConstructorType
min :: ConstructorType -> ConstructorType -> ConstructorType
Ord)

type Referent = Referent' Reference Reference

type ReferentH = Referent' (Reference' Text (Maybe Hash)) (Reference' Text Hash)

data Referent' termRef typeRef
  = Ref termRef
  | Con typeRef ConstructorId
  deriving (Referent' termRef typeRef -> Referent' termRef typeRef -> Bool
(Referent' termRef typeRef -> Referent' termRef typeRef -> Bool)
-> (Referent' termRef typeRef -> Referent' termRef typeRef -> Bool)
-> Eq (Referent' termRef typeRef)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall termRef typeRef.
(Eq termRef, Eq typeRef) =>
Referent' termRef typeRef -> Referent' termRef typeRef -> Bool
$c== :: forall termRef typeRef.
(Eq termRef, Eq typeRef) =>
Referent' termRef typeRef -> Referent' termRef typeRef -> Bool
== :: Referent' termRef typeRef -> Referent' termRef typeRef -> Bool
$c/= :: forall termRef typeRef.
(Eq termRef, Eq typeRef) =>
Referent' termRef typeRef -> Referent' termRef typeRef -> Bool
/= :: Referent' termRef typeRef -> Referent' termRef typeRef -> Bool
Eq, Eq (Referent' termRef typeRef)
Eq (Referent' termRef typeRef) =>
(Referent' termRef typeRef
 -> Referent' termRef typeRef -> Ordering)
-> (Referent' termRef typeRef -> Referent' termRef typeRef -> Bool)
-> (Referent' termRef typeRef -> Referent' termRef typeRef -> Bool)
-> (Referent' termRef typeRef -> Referent' termRef typeRef -> Bool)
-> (Referent' termRef typeRef -> Referent' termRef typeRef -> Bool)
-> (Referent' termRef typeRef
    -> Referent' termRef typeRef -> Referent' termRef typeRef)
-> (Referent' termRef typeRef
    -> Referent' termRef typeRef -> Referent' termRef typeRef)
-> Ord (Referent' termRef typeRef)
Referent' termRef typeRef -> Referent' termRef typeRef -> Bool
Referent' termRef typeRef -> Referent' termRef typeRef -> Ordering
Referent' termRef typeRef
-> Referent' termRef typeRef -> Referent' termRef typeRef
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall termRef typeRef.
(Ord termRef, Ord typeRef) =>
Eq (Referent' termRef typeRef)
forall termRef typeRef.
(Ord termRef, Ord typeRef) =>
Referent' termRef typeRef -> Referent' termRef typeRef -> Bool
forall termRef typeRef.
(Ord termRef, Ord typeRef) =>
Referent' termRef typeRef -> Referent' termRef typeRef -> Ordering
forall termRef typeRef.
(Ord termRef, Ord typeRef) =>
Referent' termRef typeRef
-> Referent' termRef typeRef -> Referent' termRef typeRef
$ccompare :: forall termRef typeRef.
(Ord termRef, Ord typeRef) =>
Referent' termRef typeRef -> Referent' termRef typeRef -> Ordering
compare :: Referent' termRef typeRef -> Referent' termRef typeRef -> Ordering
$c< :: forall termRef typeRef.
(Ord termRef, Ord typeRef) =>
Referent' termRef typeRef -> Referent' termRef typeRef -> Bool
< :: Referent' termRef typeRef -> Referent' termRef typeRef -> Bool
$c<= :: forall termRef typeRef.
(Ord termRef, Ord typeRef) =>
Referent' termRef typeRef -> Referent' termRef typeRef -> Bool
<= :: Referent' termRef typeRef -> Referent' termRef typeRef -> Bool
$c> :: forall termRef typeRef.
(Ord termRef, Ord typeRef) =>
Referent' termRef typeRef -> Referent' termRef typeRef -> Bool
> :: Referent' termRef typeRef -> Referent' termRef typeRef -> Bool
$c>= :: forall termRef typeRef.
(Ord termRef, Ord typeRef) =>
Referent' termRef typeRef -> Referent' termRef typeRef -> Bool
>= :: Referent' termRef typeRef -> Referent' termRef typeRef -> Bool
$cmax :: forall termRef typeRef.
(Ord termRef, Ord typeRef) =>
Referent' termRef typeRef
-> Referent' termRef typeRef -> Referent' termRef typeRef
max :: Referent' termRef typeRef
-> Referent' termRef typeRef -> Referent' termRef typeRef
$cmin :: forall termRef typeRef.
(Ord termRef, Ord typeRef) =>
Referent' termRef typeRef
-> Referent' termRef typeRef -> Referent' termRef typeRef
min :: Referent' termRef typeRef
-> Referent' termRef typeRef -> Referent' termRef typeRef
Ord, Int -> Referent' termRef typeRef -> ShowS
[Referent' termRef typeRef] -> ShowS
Referent' termRef typeRef -> String
(Int -> Referent' termRef typeRef -> ShowS)
-> (Referent' termRef typeRef -> String)
-> ([Referent' termRef typeRef] -> ShowS)
-> Show (Referent' termRef typeRef)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall termRef typeRef.
(Show termRef, Show typeRef) =>
Int -> Referent' termRef typeRef -> ShowS
forall termRef typeRef.
(Show termRef, Show typeRef) =>
[Referent' termRef typeRef] -> ShowS
forall termRef typeRef.
(Show termRef, Show typeRef) =>
Referent' termRef typeRef -> String
$cshowsPrec :: forall termRef typeRef.
(Show termRef, Show typeRef) =>
Int -> Referent' termRef typeRef -> ShowS
showsPrec :: Int -> Referent' termRef typeRef -> ShowS
$cshow :: forall termRef typeRef.
(Show termRef, Show typeRef) =>
Referent' termRef typeRef -> String
show :: Referent' termRef typeRef -> String
$cshowList :: forall termRef typeRef.
(Show termRef, Show typeRef) =>
[Referent' termRef typeRef] -> ShowS
showList :: [Referent' termRef typeRef] -> ShowS
Show, (forall x.
 Referent' termRef typeRef -> Rep (Referent' termRef typeRef) x)
-> (forall x.
    Rep (Referent' termRef typeRef) x -> Referent' termRef typeRef)
-> Generic (Referent' termRef typeRef)
forall x.
Rep (Referent' termRef typeRef) x -> Referent' termRef typeRef
forall x.
Referent' termRef typeRef -> Rep (Referent' termRef typeRef) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall termRef typeRef x.
Rep (Referent' termRef typeRef) x -> Referent' termRef typeRef
forall termRef typeRef x.
Referent' termRef typeRef -> Rep (Referent' termRef typeRef) x
$cfrom :: forall termRef typeRef x.
Referent' termRef typeRef -> Rep (Referent' termRef typeRef) x
from :: forall x.
Referent' termRef typeRef -> Rep (Referent' termRef typeRef) x
$cto :: forall termRef typeRef x.
Rep (Referent' termRef typeRef) x -> Referent' termRef typeRef
to :: forall x.
Rep (Referent' termRef typeRef) x -> Referent' termRef typeRef
Generic, (forall a b.
 (a -> b) -> Referent' termRef a -> Referent' termRef b)
-> (forall a b. a -> Referent' termRef b -> Referent' termRef a)
-> Functor (Referent' termRef)
forall a b. a -> Referent' termRef b -> Referent' termRef a
forall a b. (a -> b) -> Referent' termRef a -> Referent' termRef b
forall termRef a b. a -> Referent' termRef b -> Referent' termRef a
forall termRef a b.
(a -> b) -> Referent' termRef a -> Referent' termRef b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall termRef a b.
(a -> b) -> Referent' termRef a -> Referent' termRef b
fmap :: forall a b. (a -> b) -> Referent' termRef a -> Referent' termRef b
$c<$ :: forall termRef a b. a -> Referent' termRef b -> Referent' termRef a
<$ :: forall a b. a -> Referent' termRef b -> Referent' termRef a
Functor, (forall m. Monoid m => Referent' termRef m -> m)
-> (forall m a. Monoid m => (a -> m) -> Referent' termRef a -> m)
-> (forall m a. Monoid m => (a -> m) -> Referent' termRef a -> m)
-> (forall a b. (a -> b -> b) -> b -> Referent' termRef a -> b)
-> (forall a b. (a -> b -> b) -> b -> Referent' termRef a -> b)
-> (forall b a. (b -> a -> b) -> b -> Referent' termRef a -> b)
-> (forall b a. (b -> a -> b) -> b -> Referent' termRef a -> b)
-> (forall a. (a -> a -> a) -> Referent' termRef a -> a)
-> (forall a. (a -> a -> a) -> Referent' termRef a -> a)
-> (forall a. Referent' termRef a -> [a])
-> (forall a. Referent' termRef a -> Bool)
-> (forall a. Referent' termRef a -> Int)
-> (forall a. Eq a => a -> Referent' termRef a -> Bool)
-> (forall a. Ord a => Referent' termRef a -> a)
-> (forall a. Ord a => Referent' termRef a -> a)
-> (forall a. Num a => Referent' termRef a -> a)
-> (forall a. Num a => Referent' termRef a -> a)
-> Foldable (Referent' termRef)
forall a. Eq a => a -> Referent' termRef a -> Bool
forall a. Num a => Referent' termRef a -> a
forall a. Ord a => Referent' termRef a -> a
forall m. Monoid m => Referent' termRef m -> m
forall a. Referent' termRef a -> Bool
forall a. Referent' termRef a -> Int
forall a. Referent' termRef a -> [a]
forall a. (a -> a -> a) -> Referent' termRef a -> a
forall termRef a. Eq a => a -> Referent' termRef a -> Bool
forall termRef a. Num a => Referent' termRef a -> a
forall termRef a. Ord a => Referent' termRef a -> a
forall m a. Monoid m => (a -> m) -> Referent' termRef a -> m
forall termRef m. Monoid m => Referent' termRef m -> m
forall termRef a. Referent' termRef a -> Bool
forall termRef a. Referent' termRef a -> Int
forall termRef a. Referent' termRef a -> [a]
forall b a. (b -> a -> b) -> b -> Referent' termRef a -> b
forall a b. (a -> b -> b) -> b -> Referent' termRef a -> b
forall termRef a. (a -> a -> a) -> Referent' termRef a -> a
forall termRef m a.
Monoid m =>
(a -> m) -> Referent' termRef a -> m
forall termRef b a. (b -> a -> b) -> b -> Referent' termRef a -> b
forall termRef a b. (a -> b -> b) -> b -> Referent' termRef a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall termRef m. Monoid m => Referent' termRef m -> m
fold :: forall m. Monoid m => Referent' termRef m -> m
$cfoldMap :: forall termRef m a.
Monoid m =>
(a -> m) -> Referent' termRef a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Referent' termRef a -> m
$cfoldMap' :: forall termRef m a.
Monoid m =>
(a -> m) -> Referent' termRef a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> Referent' termRef a -> m
$cfoldr :: forall termRef a b. (a -> b -> b) -> b -> Referent' termRef a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Referent' termRef a -> b
$cfoldr' :: forall termRef a b. (a -> b -> b) -> b -> Referent' termRef a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Referent' termRef a -> b
$cfoldl :: forall termRef b a. (b -> a -> b) -> b -> Referent' termRef a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Referent' termRef a -> b
$cfoldl' :: forall termRef b a. (b -> a -> b) -> b -> Referent' termRef a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> Referent' termRef a -> b
$cfoldr1 :: forall termRef a. (a -> a -> a) -> Referent' termRef a -> a
foldr1 :: forall a. (a -> a -> a) -> Referent' termRef a -> a
$cfoldl1 :: forall termRef a. (a -> a -> a) -> Referent' termRef a -> a
foldl1 :: forall a. (a -> a -> a) -> Referent' termRef a -> a
$ctoList :: forall termRef a. Referent' termRef a -> [a]
toList :: forall a. Referent' termRef a -> [a]
$cnull :: forall termRef a. Referent' termRef a -> Bool
null :: forall a. Referent' termRef a -> Bool
$clength :: forall termRef a. Referent' termRef a -> Int
length :: forall a. Referent' termRef a -> Int
$celem :: forall termRef a. Eq a => a -> Referent' termRef a -> Bool
elem :: forall a. Eq a => a -> Referent' termRef a -> Bool
$cmaximum :: forall termRef a. Ord a => Referent' termRef a -> a
maximum :: forall a. Ord a => Referent' termRef a -> a
$cminimum :: forall termRef a. Ord a => Referent' termRef a -> a
minimum :: forall a. Ord a => Referent' termRef a -> a
$csum :: forall termRef a. Num a => Referent' termRef a -> a
sum :: forall a. Num a => Referent' termRef a -> a
$cproduct :: forall termRef a. Num a => Referent' termRef a -> a
product :: forall a. Num a => Referent' termRef a -> a
Foldable, Functor (Referent' termRef)
Foldable (Referent' termRef)
(Functor (Referent' termRef), Foldable (Referent' termRef)) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> Referent' termRef a -> f (Referent' termRef b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    Referent' termRef (f a) -> f (Referent' termRef a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> Referent' termRef a -> m (Referent' termRef b))
-> (forall (m :: * -> *) a.
    Monad m =>
    Referent' termRef (m a) -> m (Referent' termRef a))
-> Traversable (Referent' termRef)
forall termRef. Functor (Referent' termRef)
forall termRef. Foldable (Referent' termRef)
forall termRef (m :: * -> *) a.
Monad m =>
Referent' termRef (m a) -> m (Referent' termRef a)
forall termRef (f :: * -> *) a.
Applicative f =>
Referent' termRef (f a) -> f (Referent' termRef a)
forall termRef (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Referent' termRef a -> m (Referent' termRef b)
forall termRef (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Referent' termRef a -> f (Referent' termRef b)
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
Referent' termRef (m a) -> m (Referent' termRef a)
forall (f :: * -> *) a.
Applicative f =>
Referent' termRef (f a) -> f (Referent' termRef a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Referent' termRef a -> m (Referent' termRef b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Referent' termRef a -> f (Referent' termRef b)
$ctraverse :: forall termRef (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Referent' termRef a -> f (Referent' termRef b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Referent' termRef a -> f (Referent' termRef b)
$csequenceA :: forall termRef (f :: * -> *) a.
Applicative f =>
Referent' termRef (f a) -> f (Referent' termRef a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
Referent' termRef (f a) -> f (Referent' termRef a)
$cmapM :: forall termRef (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Referent' termRef a -> m (Referent' termRef b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Referent' termRef a -> m (Referent' termRef b)
$csequence :: forall termRef (m :: * -> *) a.
Monad m =>
Referent' termRef (m a) -> m (Referent' termRef a)
sequence :: forall (m :: * -> *) a.
Monad m =>
Referent' termRef (m a) -> m (Referent' termRef a)
Traversable)

refs_ :: Traversal (Referent' ref ref) (Referent' ref' ref') ref ref'
refs_ :: forall ref ref' (f :: * -> *).
Applicative f =>
(ref -> f ref') -> Referent' ref ref -> f (Referent' ref' ref')
refs_ ref -> f ref'
f Referent' ref ref
r = (ref -> f ref')
-> (ref -> f ref') -> Referent' ref ref -> f (Referent' ref' ref')
forall (f :: * -> *) a c b d.
Applicative f =>
(a -> f c) -> (b -> f d) -> Referent' a b -> f (Referent' c d)
forall (t :: * -> * -> *) (f :: * -> *) a c b d.
(Bitraversable t, Applicative f) =>
(a -> f c) -> (b -> f d) -> t a b -> f (t c d)
bitraverse ref -> f ref'
f ref -> f ref'
f Referent' ref ref
r

typeRef_ :: Traversal (Referent' termRef typeRef) (Referent' termRef typeRef') typeRef typeRef'
typeRef_ :: forall termRef typeRef typeRef' (f :: * -> *).
Applicative f =>
(typeRef -> f typeRef')
-> Referent' termRef typeRef -> f (Referent' termRef typeRef')
typeRef_ typeRef -> f typeRef'
f = (termRef -> f termRef)
-> (typeRef -> f typeRef')
-> Referent' termRef typeRef
-> f (Referent' termRef typeRef')
forall (f :: * -> *) a c b d.
Applicative f =>
(a -> f c) -> (b -> f d) -> Referent' a b -> f (Referent' c d)
forall (t :: * -> * -> *) (f :: * -> *) a c b d.
(Bitraversable t, Applicative f) =>
(a -> f c) -> (b -> f d) -> t a b -> f (t c d)
bitraverse termRef -> f termRef
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure typeRef -> f typeRef'
f

termRef_ :: Traversal (Referent' termRef typeRef) (Referent' termRef' typeRef) termRef termRef'
termRef_ :: forall termRef typeRef termRef' (f :: * -> *).
Applicative f =>
(termRef -> f termRef')
-> Referent' termRef typeRef -> f (Referent' termRef' typeRef)
termRef_ termRef -> f termRef'
f = (termRef -> f termRef')
-> (typeRef -> f typeRef)
-> Referent' termRef typeRef
-> f (Referent' termRef' typeRef)
forall (f :: * -> *) a c b d.
Applicative f =>
(a -> f c) -> (b -> f d) -> Referent' a b -> f (Referent' c d)
forall (t :: * -> * -> *) (f :: * -> *) a c b d.
(Bitraversable t, Applicative f) =>
(a -> f c) -> (b -> f d) -> t a b -> f (t c d)
bitraverse termRef -> f termRef'
f typeRef -> f typeRef
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure

_Ref :: Prism (Referent' tmr tyr) (Referent' tmr' tyr) tmr tmr'
_Ref :: forall tmr tyr tmr' (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p tmr (f tmr') -> p (Referent' tmr tyr) (f (Referent' tmr' tyr))
_Ref = forall (ctor :: Symbol) s t a b.
AsConstructor ctor s t a b =>
Prism s t a b
_Ctor @"Ref"

_Con :: Prism (Referent' tmr tyr) (Referent' tmr tyr') (tyr, ConstructorId) (tyr', ConstructorId)
_Con :: forall tmr tyr tyr' (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p (tyr, ConstructorId) (f (tyr', ConstructorId))
-> p (Referent' tmr tyr) (f (Referent' tmr tyr'))
_Con = forall (ctor :: Symbol) s t a b.
AsConstructor ctor s t a b =>
Prism s t a b
_Ctor @"Con"

toReference :: Referent -> Reference
toReference :: Referent -> Reference
toReference = \case
  Ref Reference
termRef -> Reference
termRef
  Con Reference
typeRef ConstructorId
_ -> Reference
typeRef

toReferenceId :: Referent -> Maybe Reference.Id
toReferenceId :: Referent -> Maybe Id
toReferenceId = \case
  Ref Reference
termRef -> Reference -> Maybe Id
Reference.toId Reference
termRef
  Con Reference
typeRef ConstructorId
_ -> Reference -> Maybe Id
Reference.toId Reference
typeRef

toTermReference :: Referent' termRef typeRef -> Maybe termRef
toTermReference :: forall termRef typeRef. Referent' termRef typeRef -> Maybe termRef
toTermReference = \case
  Ref termRef
termRef -> termRef -> Maybe termRef
forall a. a -> Maybe a
Just termRef
termRef
  Con typeRef
_ ConstructorId
_ -> Maybe termRef
forall a. Maybe a
Nothing

type Id = Id' Hash Hash

data Id' hTm hTp
  = RefId (Reference.Id' hTm)
  | ConId (Reference.Id' hTp) ConstructorId
  deriving (Id' hTm hTp -> Id' hTm hTp -> Bool
(Id' hTm hTp -> Id' hTm hTp -> Bool)
-> (Id' hTm hTp -> Id' hTm hTp -> Bool) -> Eq (Id' hTm hTp)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall hTm hTp.
(Eq hTm, Eq hTp) =>
Id' hTm hTp -> Id' hTm hTp -> Bool
$c== :: forall hTm hTp.
(Eq hTm, Eq hTp) =>
Id' hTm hTp -> Id' hTm hTp -> Bool
== :: Id' hTm hTp -> Id' hTm hTp -> Bool
$c/= :: forall hTm hTp.
(Eq hTm, Eq hTp) =>
Id' hTm hTp -> Id' hTm hTp -> Bool
/= :: Id' hTm hTp -> Id' hTm hTp -> Bool
Eq, (forall a b. (a -> b) -> Id' hTm a -> Id' hTm b)
-> (forall a b. a -> Id' hTm b -> Id' hTm a) -> Functor (Id' hTm)
forall a b. a -> Id' hTm b -> Id' hTm a
forall a b. (a -> b) -> Id' hTm a -> Id' hTm b
forall hTm a b. a -> Id' hTm b -> Id' hTm a
forall hTm a b. (a -> b) -> Id' hTm a -> Id' hTm b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall hTm a b. (a -> b) -> Id' hTm a -> Id' hTm b
fmap :: forall a b. (a -> b) -> Id' hTm a -> Id' hTm b
$c<$ :: forall hTm a b. a -> Id' hTm b -> Id' hTm a
<$ :: forall a b. a -> Id' hTm b -> Id' hTm a
Functor, Eq (Id' hTm hTp)
Eq (Id' hTm hTp) =>
(Id' hTm hTp -> Id' hTm hTp -> Ordering)
-> (Id' hTm hTp -> Id' hTm hTp -> Bool)
-> (Id' hTm hTp -> Id' hTm hTp -> Bool)
-> (Id' hTm hTp -> Id' hTm hTp -> Bool)
-> (Id' hTm hTp -> Id' hTm hTp -> Bool)
-> (Id' hTm hTp -> Id' hTm hTp -> Id' hTm hTp)
-> (Id' hTm hTp -> Id' hTm hTp -> Id' hTm hTp)
-> Ord (Id' hTm hTp)
Id' hTm hTp -> Id' hTm hTp -> Bool
Id' hTm hTp -> Id' hTm hTp -> Ordering
Id' hTm hTp -> Id' hTm hTp -> Id' hTm hTp
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall hTm hTp. (Ord hTm, Ord hTp) => Eq (Id' hTm hTp)
forall hTm hTp.
(Ord hTm, Ord hTp) =>
Id' hTm hTp -> Id' hTm hTp -> Bool
forall hTm hTp.
(Ord hTm, Ord hTp) =>
Id' hTm hTp -> Id' hTm hTp -> Ordering
forall hTm hTp.
(Ord hTm, Ord hTp) =>
Id' hTm hTp -> Id' hTm hTp -> Id' hTm hTp
$ccompare :: forall hTm hTp.
(Ord hTm, Ord hTp) =>
Id' hTm hTp -> Id' hTm hTp -> Ordering
compare :: Id' hTm hTp -> Id' hTm hTp -> Ordering
$c< :: forall hTm hTp.
(Ord hTm, Ord hTp) =>
Id' hTm hTp -> Id' hTm hTp -> Bool
< :: Id' hTm hTp -> Id' hTm hTp -> Bool
$c<= :: forall hTm hTp.
(Ord hTm, Ord hTp) =>
Id' hTm hTp -> Id' hTm hTp -> Bool
<= :: Id' hTm hTp -> Id' hTm hTp -> Bool
$c> :: forall hTm hTp.
(Ord hTm, Ord hTp) =>
Id' hTm hTp -> Id' hTm hTp -> Bool
> :: Id' hTm hTp -> Id' hTm hTp -> Bool
$c>= :: forall hTm hTp.
(Ord hTm, Ord hTp) =>
Id' hTm hTp -> Id' hTm hTp -> Bool
>= :: Id' hTm hTp -> Id' hTm hTp -> Bool
$cmax :: forall hTm hTp.
(Ord hTm, Ord hTp) =>
Id' hTm hTp -> Id' hTm hTp -> Id' hTm hTp
max :: Id' hTm hTp -> Id' hTm hTp -> Id' hTm hTp
$cmin :: forall hTm hTp.
(Ord hTm, Ord hTp) =>
Id' hTm hTp -> Id' hTm hTp -> Id' hTm hTp
min :: Id' hTm hTp -> Id' hTm hTp -> Id' hTm hTp
Ord, Int -> Id' hTm hTp -> ShowS
[Id' hTm hTp] -> ShowS
Id' hTm hTp -> String
(Int -> Id' hTm hTp -> ShowS)
-> (Id' hTm hTp -> String)
-> ([Id' hTm hTp] -> ShowS)
-> Show (Id' hTm hTp)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall hTm hTp. (Show hTm, Show hTp) => Int -> Id' hTm hTp -> ShowS
forall hTm hTp. (Show hTm, Show hTp) => [Id' hTm hTp] -> ShowS
forall hTm hTp. (Show hTm, Show hTp) => Id' hTm hTp -> String
$cshowsPrec :: forall hTm hTp. (Show hTm, Show hTp) => Int -> Id' hTm hTp -> ShowS
showsPrec :: Int -> Id' hTm hTp -> ShowS
$cshow :: forall hTm hTp. (Show hTm, Show hTp) => Id' hTm hTp -> String
show :: Id' hTm hTp -> String
$cshowList :: forall hTm hTp. (Show hTm, Show hTp) => [Id' hTm hTp] -> ShowS
showList :: [Id' hTm hTp] -> ShowS
Show)

instance Bifunctor Referent' where
  bimap :: forall a b c d.
(a -> b) -> (c -> d) -> Referent' a c -> Referent' b d
bimap a -> b
f c -> d
g = \case
    Ref a
r -> b -> Referent' b d
forall termRef typeRef. termRef -> Referent' termRef typeRef
Ref (a -> b
f a
r)
    Con c
r ConstructorId
i -> d -> ConstructorId -> Referent' b d
forall termRef typeRef.
typeRef -> ConstructorId -> Referent' termRef typeRef
Con (c -> d
g c
r) ConstructorId
i

instance Bifoldable Referent' where
  bifoldMap :: forall m a b.
Monoid m =>
(a -> m) -> (b -> m) -> Referent' a b -> m
bifoldMap a -> m
f b -> m
g = \case
    Ref a
r -> a -> m
f a
r
    Con b
r ConstructorId
_ -> b -> m
g b
r

instance Bitraversable Referent' where
  bitraverse :: forall (f :: * -> *) a c b d.
Applicative f =>
(a -> f c) -> (b -> f d) -> Referent' a b -> f (Referent' c d)
bitraverse a -> f c
f b -> f d
g = \case
    Ref a
r -> c -> Referent' c d
forall termRef typeRef. termRef -> Referent' termRef typeRef
Ref (c -> Referent' c d) -> f c -> f (Referent' c d)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f c
f a
r
    Con b
r ConstructorId
c -> (d -> ConstructorId -> Referent' c d)
-> ConstructorId -> d -> Referent' c d
forall a b c. (a -> b -> c) -> b -> a -> c
flip d -> ConstructorId -> Referent' c d
forall termRef typeRef.
typeRef -> ConstructorId -> Referent' termRef typeRef
Con ConstructorId
c (d -> Referent' c d) -> f d -> f (Referent' c d)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> f d
g b
r

instance Bifunctor Id' where
  bimap :: forall a b c d. (a -> b) -> (c -> d) -> Id' a c -> Id' b d
bimap a -> b
f c -> d
g = \case
    RefId Id' a
r -> Id' b -> Id' b d
forall hTm hTp. Id' hTm -> Id' hTm hTp
RefId ((a -> b) -> Id' a -> Id' b
forall a b. (a -> b) -> Id' a -> Id' b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f Id' a
r)
    ConId Id' c
r ConstructorId
j -> Id' d -> ConstructorId -> Id' b d
forall hTm hTp. Id' hTp -> ConstructorId -> Id' hTm hTp
ConId ((c -> d) -> Id' c -> Id' d
forall a b. (a -> b) -> Id' a -> Id' b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap c -> d
g Id' c
r) ConstructorId
j

instance Bifoldable Id' where
  bifoldMap :: forall m a b. Monoid m => (a -> m) -> (b -> m) -> Id' a b -> m
bifoldMap a -> m
f b -> m
g = \case
    RefId Id' a
r -> (a -> m) -> Id' a -> m
forall m a. Monoid m => (a -> m) -> Id' a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap a -> m
f Id' a
r
    ConId Id' b
r ConstructorId
_ -> (b -> m) -> Id' b -> m
forall m a. Monoid m => (a -> m) -> Id' a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap b -> m
g Id' b
r

instance Bitraversable Id' where
  bitraverse :: forall (f :: * -> *) a c b d.
Applicative f =>
(a -> f c) -> (b -> f d) -> Id' a b -> f (Id' c d)
bitraverse a -> f c
f b -> f d
g = \case
    RefId Id' a
r -> Id' c -> Id' c d
forall hTm hTp. Id' hTm -> Id' hTm hTp
RefId (Id' c -> Id' c d) -> f (Id' c) -> f (Id' c d)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a -> f c) -> Id' a -> f (Id' c)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Id' a -> f (Id' b)
traverse a -> f c
f Id' a
r
    ConId Id' b
r ConstructorId
c -> (Id' d -> ConstructorId -> Id' c d)
-> ConstructorId -> Id' d -> Id' c d
forall a b c. (a -> b -> c) -> b -> a -> c
flip Id' d -> ConstructorId -> Id' c d
forall hTm hTp. Id' hTp -> ConstructorId -> Id' hTm hTp
ConId ConstructorId
c (Id' d -> Id' c d) -> f (Id' d) -> f (Id' c d)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (b -> f d) -> Id' b -> f (Id' d)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Id' a -> f (Id' b)
traverse b -> f d
g Id' b
r

toShortHash :: Referent -> ShortHash
toShortHash :: Referent -> ShortHash
toShortHash = \case
  Ref Reference
r -> Reference -> ShortHash
Reference.toShortHash Reference
r
  Con Reference
r ConstructorId
conId ->
    case Reference -> ShortHash
Reference.toShortHash Reference
r of
      Builtin Text
b -> Text -> ShortHash
forall a b. a -> OrBuiltin a b
Builtin Text
b
      NotBuiltin (SH.ShortHash Text
prefix Maybe ConstructorId
cycle Maybe ConstructorId
_cid) -> ShortHash1 -> ShortHash
forall a b. b -> OrBuiltin a b
NotBuiltin (Text -> Maybe ConstructorId -> Maybe ConstructorId -> ShortHash1
SH.ShortHash Text
prefix Maybe ConstructorId
cycle (ConstructorId -> Maybe ConstructorId
forall a. a -> Maybe a
Just ConstructorId
conId))