------------------------------------------------------------------------
-- The Agda standard library
--
-- Homogeneously-indexed binary relations
------------------------------------------------------------------------

-- The contents of this module should be accessed via
-- `Relation.Binary.Indexed.Homogeneous`.

{-# OPTIONS --cubical-compatible --safe #-}

module Relation.Binary.Indexed.Homogeneous.Core where

open import Level using (Level; _⊔_)
open import Data.Product.Base using (_×_)
open import Relation.Binary.Core as B using (REL; Rel)
open import Relation.Binary.PropositionalEquality.Core using (_≡_; refl)
import Relation.Binary.Indexed.Heterogeneous as I
open import Relation.Unary.Indexed using (IPred)

private
  variable
    a b c  : Level
    I : Set c

------------------------------------------------------------------------
-- Homegeneously indexed binary relations

-- Heterogeneous types

IREL : (I  Set a)  (I  Set b)  ( : Level)  Set _
IREL A B  =  {i}  REL (A i) (B i) 

-- Homogeneous types

IRel : (I  Set a)  ( : Level)  Set _
IRel A = IREL A A

------------------------------------------------------------------------
-- Lifting to non-indexed binary relations

-- Ideally this should be in: `Construct.Lift` but we want this relation
-- to be exported by the various structures & bundles.

Lift : (A : I  Set a)  IRel A   Rel (∀ i  A i) _
Lift _ _∼_ x y =  i  x i  y i

------------------------------------------------------------------------
-- Conversion between homogeneous and heterogeneously indexed relations

module _ {i a b} {I : Set i} {A : I  Set a} {B : I  Set b} where

  OverPath :  {}  IREL A B    {i j}  i  j  REL (A i) (B j) 
  OverPath _∼_ refl = _∼_

  toHetIndexed :  {}  IREL A B   I.IREL A B (i  )
  toHetIndexed _∼_ {i} {j} x y = (p : i  j)  OverPath _∼_ p x y

  fromHetIndexed :  {}  I.IREL A B   IREL A B 
  fromHetIndexed _∼_ = _∼_