Domain Equations
The domains π Ο form a "standard collection of domains for arithmetic"
in PCF, written \(\mathcal D_\sigma\) in (Plotkin1977LCP).
As PCF is a simply-typed language, the domains π Ο are not reflexive,
so their embedding in Agda can use ordinary type definitions,
not involving bijections.
{-# OPTIONS --rewriting --confluence-check --lossy-unification #-}
module Examples.PCF.Domain-Equations where
open import Examples.PCF.Abstract-Syntax
open import Notation
open Notation.Flat.Booleans using (Bool; Boolβ₯)
open Notation.Flat.Naturals using (Natβ₯; eqNat)
π : Types β Domain -- standard domains
π ΞΉ = Natβ₯ -- natural numbers
π o = Boolβ₯ -- truth-values
π (Ο β Ο) = π Ο βαΆ π Ο -- functions
variable x y z : βͺ π Ο β«
Environments Ο are type-preserving maps from variables to values. They are
naturally modeled by a dependent type: Env Ο consists of type-preserving maps
from variables in Vars Ο to their values in the domain π Ο.
The environment Οβ₯ maps all variables to β₯.
Env = (Ο : Types) β βͺ Vars Ο βΛ’ π Ο β« -- typed environments
variable Ο : Env
Οβ₯ : Env -- initial environment
Οβ₯ _ _ = β₯
Extension or overriding typed environments, written Ο [ v / x ]β²,
requires instances of the equality tests
for both variables and types. The definition of the latter is somewhat tedious.
open Notation.Flat.Booleans using (Eq; _==_)
open Notation.Updates using (_[_/_])
_==β±½_ : Vars Ο β Vars Ο β Bool
open import Agda.Builtin.Nat renaming (_==_ to _==α΄Ί_) public
(Ξ± i Ο ==β±½ Ξ± iβ² Ο) = (i ==α΄Ί iβ²)
instance
eqV : Eq (Vars Ο)
_==_ {{eqV}} = _==β±½_
open Notation.Updates using (MaybeEq; _==?_; just; nothing; refl; _[_β_])
instance
eqT : MaybeEq Types
eqT ._==?_ ΞΉ ΞΉ = just refl
eqT ._==?_ o o = just refl
eqT ._==?_ (Ο β Ο) (Οβ β Οβ) with Ο ==? Οβ | Ο ==? Οβ
eqT ._==?_ (Ο β Ο) (Οβ β Οβ) | just refl | just refl = just refl
eqT ._==?_ (Ο β Ο) (Οβ β Οβ) | _ | _ = nothing
eqT ._==?_ _ _ = nothing
_[_/_]β² : Env β βͺ π Ο β« β Vars Ο β Env
-- Ο [ v / x ]β² maps x to v, and other xβ² to Ο xβ²
_[_/_]β² {Ο} Ο x v = Ο [ Ο β Ο Ο [ x / v ] ]