~ubuntu-branches/ubuntu/saucy/agda-stdlib/saucy

« back to all changes in this revision

Viewing changes to src/Data/Context.agda

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2011-11-29 17:00:35 UTC
  • mfrom: (2.1.4 sid)
  • Revision ID: package-import@ubuntu.com-20111129170035-be8cbok8ojft5tjl
Tags: 0.6~darcs20111129t1640-1
* [ef445ab] Imported Upstream version 0.6~darcs20111129t1640
  + Darcs snapshot required for Agda 2.3.0 compatibility
* [f801f83] Update BDs and deps to require Agda 2.3.0
* [c52be90] Use 3.0 (quilt) for bz2 orig

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
------------------------------------------------------------------------
2
 
------------------------------------------------------------------------
3
 
 
4
 
{-# OPTIONS --universe-polymorphism #-}
5
 
 
6
 
 
7
 
 
8
 
open import Universe
9
 
 
10
 
module Data.Context {u e} (Uni : Universe u e) where
11
 
 
12
 
open Universe.Universe Uni
13
 
 
14
 
open import Data.Product as Prod
15
 
open import Data.Unit
16
 
open import Function
17
 
open import Level
18
 
 
19
 
------------------------------------------------------------------------
20
 
 
21
 
mutual
22
 
 
23
 
  -- Contexts.
24
 
 
25
 
  infixl 5 _▻_
26
 
 
27
 
  data Ctxt : Set (u ⊔ e) where
28
 
    ε   : Ctxt
29
 
    _▻_ : (Γ : Ctxt) (σ : Type Γ) → Ctxt
30
 
 
31
 
  -- Semantic types: maps from environments to universe codes.
32
 
 
33
 
  Type : Ctxt → Set (u ⊔ e)
34
 
  Type Γ = Env Γ → U
35
 
 
36
 
  -- Interpretation of contexts: environments.
37
 
 
38
 
  Env : Ctxt → Set e
39
 
  Env ε       = Lift ⊤
40
 
  Env (Γ ▻ σ) = Σ (Env Γ) λ γ → El (σ γ)
41
 
 
42
 
 
43
 
Term-like : (ℓ : Level) → Set _
44
 
Term-like ℓ = (Γ : Ctxt) → Type Γ → Set ℓ
45
 
 
46
 
 
47
 
Value : Term-like _
48
 
Value Γ σ = (γ : Env Γ) → El (σ γ)
49
 
 
50
 
------------------------------------------------------------------------
51
 
 
52
 
 
53
 
infixr 4 _⇨_
54
 
 
55
 
_⇨_ : Ctxt → Ctxt → Set _
56
 
Γ ⇨ Δ = Env Δ → Env Γ
57
 
 
58
 
 
59
 
infixr 4 _⇨₁_
60
 
 
61
 
_⇨₁_ : ∀ {Γ} → Type Γ → Type Γ → Set _
62
 
σ ⇨₁ τ = ∀ {γ} → El (τ γ) → El (σ γ)
63
 
 
64
 
--
65
 
 
66
 
infixl 8 _/_
67
 
 
68
 
_/_ : ∀ {Γ Δ} → Type Γ → Γ ⇨ Δ → Type Δ
69
 
σ / ρ = σ ∘ ρ
70
 
 
71
 
 
72
 
infixl 8 _/v_
73
 
 
74
 
_/v_ : ∀ {Γ Δ σ} → Value Γ σ → (ρ : Γ ⇨ Δ) → Value Δ (σ / ρ)
75
 
v /v ρ = v ∘ ρ
76
 
 
77
 
 
78
 
wk : ∀ {Γ σ} → Γ ⇨ Γ ▻ σ
79
 
wk = proj₁
80
 
 
81
 
 
82
 
infixl 5 _►_
83
 
 
84
 
_►_ : ∀ {Γ Δ σ} (ρ : Γ ⇨ Δ) → Value Δ (σ / ρ) → Γ ▻ σ ⇨ Δ
85
 
_►_ = <_,_>
86
 
 
87
 
 
88
 
sub : ∀ {Γ σ} → Value Γ σ → Γ ▻ σ ⇨ Γ
89
 
sub v = id ► v
90
 
 
91
 
 
92
 
infixl 10 _↑_
93
 
 
94
 
_↑_ : ∀ {Γ Δ σ τ} (ρ : Γ ⇨ Δ) → σ / ρ ⇨₁ τ → Γ ▻ σ ⇨ Δ ▻ τ
95
 
_↑_ = Prod.map
96
 
 
97
 
 
98
 
infix 10 _↑
99
 
 
100
 
_↑ : ∀ {Γ Δ σ} (ρ : Γ ⇨ Δ) → Γ ▻ σ ⇨ Δ ▻ σ / ρ
101
 
ρ ↑ = ρ ↑ id
102
 
 
103
 
------------------------------------------------------------------------
104
 
 
105
 
 
106
 
infix 4 _∋_
107
 
 
108
 
data _∋_ : Term-like (u ⊔ e) where
109
 
  zero : ∀ {Γ σ}               → Γ ▻ σ ∋ σ / wk
110
 
  suc  : ∀ {Γ σ τ} (x : Γ ∋ σ) → Γ ▻ τ ∋ σ / wk
111
 
 
112
 
 
113
 
lookup : ∀ {Γ σ} → Γ ∋ σ → Value Γ σ
114
 
lookup zero    (γ , v) = v
115
 
lookup (suc x) (γ , v) = lookup x γ
116
 
 
117
 
 
118
 
infixl 8 _/∋_
119
 
 
120
 
_/∋_ : ∀ {Γ Δ σ} → Γ ∋ σ → (ρ : Γ ⇨ Δ) → Value Δ (σ / ρ)
121
 
x /∋ ρ = lookup x /v ρ
122
 
 
123
 
------------------------------------------------------------------------
124
 
 
125
 
mutual
126
 
 
127
 
  -- Context extensions.
128
 
 
129
 
  infixl 5 _▻_
130
 
 
131
 
  data Ctxt⁺ (Γ : Ctxt) : Set (u ⊔ e) where
132
 
    ε   : Ctxt⁺ Γ
133
 
    _▻_ : (Γ⁺ : Ctxt⁺ Γ) (σ : Type (Γ ++ Γ⁺)) → Ctxt⁺ Γ
134
 
 
135
 
  -- Appends a context extension to a context.
136
 
 
137
 
  infixl 5 _++_
138
 
 
139
 
  _++_ : (Γ : Ctxt) → Ctxt⁺ Γ → Ctxt
140
 
  Γ ++ ε        = Γ
141
 
  Γ ++ (Γ⁺ ▻ σ) = (Γ ++ Γ⁺) ▻ σ
142
 
 
143
 
mutual
144
 
 
145
 
  -- Application of substitutions to context extensions.
146
 
 
147
 
  infixl 8 _/⁺_
148
 
 
149
 
  _/⁺_ : ∀ {Γ Δ} → Ctxt⁺ Γ → Γ ⇨ Δ → Ctxt⁺ Δ
150
 
  ε        /⁺ ρ = ε
151
 
  (Γ⁺ ▻ σ) /⁺ ρ = Γ⁺ /⁺ ρ ▻ σ / ρ ↑⋆ Γ⁺
152
 
 
153
 
  -- N-ary lifting of substitutions.
154
 
 
155
 
  infixl 10 _↑⋆_
156
 
 
157
 
  _↑⋆_ : ∀ {Γ Δ} (ρ : Γ ⇨ Δ) → ∀ Γ⁺ → Γ ++ Γ⁺ ⇨ Δ ++ Γ⁺ /⁺ ρ
158
 
  ρ ↑⋆ ε        = ρ
159
 
  ρ ↑⋆ (Γ⁺ ▻ σ) = (ρ ↑⋆ Γ⁺) ↑