module Surface.Precision where

open import Data.Maybe
open import Data.List
open import Relation.Binary.PropositionalEquality using (_≡_; refl)

open import Syntax

open import Common.Utils
open import Common.Types
open import Surface.SurfaceSyntax


infix 6 _⊑ˢ_

data _⊑ˢ_ : Term  Term  Set where

  ⊑ˢ-const :  {ι} {k : rep ι} {}
      ---------------------------------
     $ k of  ⊑ˢ $ k of 

  ⊑ˢ-var :  {x}  ` x ⊑ˢ ` x

  ⊑ˢ-lam :  {pc A A′ N N′ }
     A   A′
     N ⊑ˢ N′
      -----------------------------------------------
     ƛ⟦ pc  A ˙ N of  ⊑ˢ ƛ⟦ pc  A′ ˙ N′ of 

  ⊑ˢ-app :  {L L′ M M′} {p q}
     L ⊑ˢ L′
     M ⊑ˢ M′
      ---------------------
     L · M at p ⊑ˢ L′ · M′ at q

  ⊑ˢ-if :  {L L′ M M′ N N′} {p q}
     L ⊑ˢ L′
     M ⊑ˢ M′
     N ⊑ˢ N′
      -----------------------------------------------------------
     if L then M else N at p ⊑ˢ if L′ then M′ else N′ at q

  ⊑ˢ-ann :  {M M′ A A′} {p q}
     M ⊑ˢ M′
     A   A′
      -------------------------------
     M  A at p ⊑ˢ M′  A′ at q

  ⊑ˢ-let :  {M M′ N N′}
     M ⊑ˢ M′
     N ⊑ˢ N′
      ---------------------------------
     `let M `in N ⊑ˢ `let M′ `in N′

  ⊑ˢ-ref :  {M M′ } {p q}
     M ⊑ˢ M′
      ----------------------------------------
     ref⟦   M at p ⊑ˢ ref⟦   M′ at q

  ⊑ˢ-deref :  {M M′}
     M ⊑ˢ M′
      --------------
     ! M ⊑ˢ ! M′

  ⊑ˢ-assign :  {L L′ M M′} {p q}
     L ⊑ˢ L′
     M ⊑ˢ M′
      -------------------------------
     L := M at p ⊑ˢ L′ := M′ at q