annotate cbc/maybe-subtype.agda @ 57:75f9f71f364a

Trying define maybe-subtype
author atton <atton@cr.ie.u-ryukyu.ac.jp>
date Thu, 12 Jan 2017 01:04:59 +0000
parents
children 352e8a724829
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
57
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 module maybe-subtype (A : Set) where
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 open import Level
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 open import Function using (id)
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 open import Relation.Binary.PropositionalEquality
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 data Maybe (A : Set) : Set where
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 nothing : Maybe A
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 just : A -> Maybe A
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 record Context (A : Set) : Set where
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 field
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 maybeElem : Maybe A
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 open import subtype (Context A) as N
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 record Meta (A : Set) : Set where
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 field
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 context : Context A
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 open import subtype (Meta A) as M
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 instance
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 MetaIsMetaDataSegment : M.DataSegment (Meta A)
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 MetaIsMetaDataSegment = record {get = (\mc -> mc) ; set = (\_ mc -> mc)}
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 ContextIsMetaDataSegment : M.DataSegment (Context A)
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 ContextIsMetaDataSegment = record {get = Meta.context ; set = (\mc c -> record mc {context = c})}
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 return : {_ : Context A} {_ : Meta (Context A)} {{_ : N.DataSegment A}} {{_ : M.DataSegment A}} -> A -> Meta A
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 return {c} {mc} {{nd}} {{md}} a = record {context = record {maybeElem = just a}}
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 fmap' : {B : Set} {{_ : M.DataSegment (Context A)}} {{_ : M.DataSegment (Context B)}} -> (A -> B) -> Context A -> Context B
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 fmap' f record { maybeElem = (just x) } = record {maybeElem = just (f x)}
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 fmap' f record { maybeElem = nothing } = record {maybeElem = nothing}
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 fmap : {c : Context A} {B : Set}
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 {{_ : N.DataSegment A}} {{_ : N.DataSegment B}} {{_ : M.DataSegment (Context A)}} {{_ : M.DataSegment (Context B)}}
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 -> N.CodeSegment A B -> M.CodeSegment (Context A) (Context B)
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 fmap {c} {B} {{na}} {{nb}} {{ma}} {{mb}} (N.cs f) = M.cs {{ma}} (fmap' {B} {{ma}} {{mb}} f)
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 open ≡-Reasoning
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 exec-id : (x : Meta A) -> M.exec (M.cs {zero} {zero} {Context A} id) x ≡ x
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 exec-id record { context = context } = refl
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 maybe-preserve-id : {{na : N.DataSegment A}} {{ma : M.DataSegment A}} {{mx : M.DataSegment (Context A)}}
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 -> (x : Context A)
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 -> M.exec {{mx}} {{mx}} (fmap {x} {{na}}{{na}}{{mx}}{{mx}} (N.cs id)) (record {context = x})
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 M.exec {{mx}} {{mx}} (M.cs {{mx}} {{mx}} id) (record {context = x})
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 maybe-preserve-id {{na}} {{ma}} {{mx}} record { maybeElem = nothing } = begin
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 M.exec {{mx}} {{mx}} (fmap {record { maybeElem = nothing }} {{na}}{{na}}{{mx}}{{mx}} (N.cs id)) (record {context = record { maybeElem = nothing }})
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 ≡⟨ refl ⟩
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 M.DataSegment.set mx (record { context = record { maybeElem = nothing } }) ((fmap' {{mx}} {{mx}} id) (M.DataSegment.get mx (record { context = record { maybeElem = nothing } })))
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 ≡⟨ {!!} ⟩
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 record {context = record { maybeElem = nothing }}
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 ≡⟨ sym (exec-id (record {context = record {maybeElem = nothing}})) ⟩
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 M.exec {{mx}} {{mx}} (M.cs {{mx}} {{mx}} id) (record {context = record { maybeElem = nothing }})
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 maybe-preserve-id record { maybeElem = (just x) } = {!!}
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 {-
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 maybe-preserve-id {{na}} {{ma}} {{mx}} record { maybeElem = nothing } = begin
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 M.exec (fmap {record {maybeElem = nothing}} (N.cs id)) record {context = record { maybeElem = nothing}}
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 ≡⟨ refl ⟩
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 M.exec (M.cs (fmap' id)) record {context = record {maybeElem = nothing}}
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 ≡⟨ refl ⟩
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 M.DataSegment.set mx (record { context = record { maybeElem = nothing } }) ((fmap' id) (M.DataSegment.get mx (record { context = record { maybeElem = nothing } })))
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 ≡⟨ {!!} ⟩
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 record { context = record { maybeElem = nothing }}
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 ≡⟨ {!!} ⟩
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 M.exec {zero} {zero} {A} {A} (M.cs id) (record { context = record { maybeElem = nothing } })
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 maybe-preserve-id record { maybeElem = (just x) } = {!!}
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84
75f9f71f364a Trying define maybe-subtype
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 -}