Browse Source

Define actions!

gas-move-test
Thomas Kerber 6 months ago
parent
commit
6cdfff51af
Signed by: Thomas Kerber <t.kerber@ed.ac.uk> GPG Key ID: 8489B911F9ED617B
1 changed files with 53 additions and 16 deletions
  1. 53
    16
      Yggdrasil/World.agda

+ 53
- 16
Yggdrasil/World.agda View File

@@ -1,41 +1,78 @@
1 1
 module Yggdrasil.World where
2 2
 
3
+open import Data.Bool using (Bool)
3 4
 open import Data.List using (List; _∷_; []; map)
5
+open import Data.Maybe using (Maybe)
4 6
 open import Data.Product using (_×_)
7
+open import Data.Sum using (_⊎_)
5 8
 open import Level using (Level; suc)
6 9
 open import Yggdrasil.List using (_∈_)
7 10
 
11
+record Query (ℓ : Level) : Set (suc ℓ) where
12
+  field
13
+    A : Set ℓ
14
+    B : A → Set ℓ
15
+
8 16
 record WorldType (ℓ : Level) : Set (suc ℓ)
9
-data Action {ℓ : Level} : (WorldType ℓ) → Set ℓ → Set (suc ℓ)
17
+data Action↯ {ℓ : Level} (Γ : WorldType ℓ) : Set ℓ → Set (suc ℓ)
18
+data Action↑ {ℓ : Level} (Γs : List (WorldType ℓ)) (Qs : List (Query ℓ)) : Set ℓ → Set (suc ℓ)
19
+data Action↓ {ℓ : Level} (Γ : WorldType ℓ) : Set ℓ → Set (suc ℓ)
20
+Action : {ℓ : Level} → WorldType ℓ → Set ℓ → Set (suc ℓ)
21
+Action Γ A = Action↯ Γ A ⊎ Action↓ Γ A
22
+
23
+data WorldState {ℓ : Level} (Γ : WorldType ℓ) : Set (suc ℓ)
24
+data WorldStates {ℓ : Level} : List (WorldType ℓ) → Set (suc ℓ)
25
+
10 26
 
11
-record Call (ℓ : Level) (Σ : Set ℓ) (Γ : List (WorldType ℓ)) : Set (suc ℓ) where
27
+record Call (ℓ : Level) (Σ : Set ℓ) (Γs : List (WorldType ℓ))
28
+    (Qs : List (Query ℓ)) : Set (suc ℓ) where
29
+  inductive
12 30
   field
13 31
     A : Set ℓ
14 32
     B : A → Set ℓ
15
-    δ : Σ → (x : A) → Σ × B x
33
+    δ : Σ → (x : A) → Σ × Action↑ Γs Qs (B x)
16 34
 
17 35
 record WorldType ℓ where
18 36
   inductive
19 37
   field
20 38
     root : Set ℓ
21
-    children : List (WorldType ℓ)
22
-    adv  : List (Call ℓ root children)
23
-    hon  : List (Call ℓ root children)
39
+    chld : List (WorldType ℓ)
40
+    qry  : List (Query ℓ)
41
+    adv  : List (Call ℓ root chld qry)
42
+    hon  : List (Call ℓ root chld qry)
24 43
 
25 44
 open WorldType
26 45
 
27
-data Action {ℓ} where
28
-  abort : ∀ {W A} → Action W A
29
-  pure  : ∀ {W A} → A → Action W A
30
-  call  : ∀ {W f} → f ∈ (hon W) → (x : Call.A f) → Action W (Call.B f x)
46
+data Action↯ {ℓ} Γ where
47
+  call↯ : ∀ {f} → f ∈ (adv Γ) → (x : Call.A f) → Action↯ Γ (Call.B f x)
48
+  lift↯ : ∀ {Γ′ A} → Action↯ Γ′ A → Γ′ ∈ (chld Γ) → Action↯ Γ A
31 49
 
32
-data WorldState {ℓ : Level} : WorldType ℓ → Set (suc ℓ)
33
-data WorldStates {ℓ : Level} : List (WorldType ℓ) → Set (suc ℓ)
50
+data Action↓ {ℓ} Γ where
51
+  call↓ : ∀ {f} → f ∈ (hon Γ) → (x : Call.A f) → Action↓ Γ (Call.B f x)
52
+
53
+data Action↑ {ℓ} Γs Qs where
54
+  abort : ∀ {A} → Action↑ Γs Qs A
55
+  pure  : ∀ {A} → A → Action↑ Γs Qs A
56
+  query : ∀ {q} → q ∈ Qs → (x : Query.A q) → Action↑ Γs Qs (Query.B q x)
57
+  _↑    : ∀ {Γ A} → Action↓ Γ A → Γ ∈ Γs → Action↑ Γs Qs A
58
+  _>>=_ : ∀ {A B} → Action↑ Γs Qs A → (A → Action↑ Γs Qs B) → Action↑ Γs Qs B
34 59
 
35 60
 data WorldStates {ℓ} where
36 61
   [] : WorldStates []
37
-  _∷_ : {W : WorldType ℓ} {Ws : List (WorldType ℓ)} → WorldState W →
38
-    WorldStates Ws → WorldStates (W ∷ Ws)
62
+  _∷_ : ∀ {Γ Γs} → WorldState Γ → WorldStates Γs → WorldStates (Γ ∷ Γs)
63
+
64
+data WorldState {ℓ} Γ where
65
+  node : root Γ → WorldStates (chld Γ) → WorldState Γ
66
+
67
+data _∈↑_ {ℓ : Level} (q : Query ℓ) (Γ : WorldType ℓ) : Set (suc ℓ) where
68
+  here : q ∈ qry Γ → q ∈↑ Γ
69
+  there : ∀ {Γ′} → q ∈↑ Γ′ → Γ′ ∈ chld Γ → q ∈↑ Γ
70
+
71
+record Strategy {ℓ : Level} (Γ : WorldType ℓ) (A : Set ℓ) : Set (suc ℓ) where
72
+  constructor strat
73
+  field
74
+    init : Action Γ A
75
+    oracle : ∀ {q} → q ∈↑ Γ → (x : Query.A q) → Action Γ (Query.B q x)
39 76
 
40
-data WorldState {ℓ} where
41
-  node : {T : WorldType ℓ} → root T → WorldStates (children T) → WorldState T
77
+exec : ∀ {ℓ Γ A} → Strategy {ℓ} Γ A → WorldState {ℓ} Γ → Maybe A
78
+exec = ?

Loading…
Cancel
Save