-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProtocolMonad.v
66 lines (59 loc) · 2.51 KB
/
ProtocolMonad.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
Require Export StateMonad.
Require Export FunctionalExtensionality.
Definition C := Type.
Definition ID := Type.
(**
- [send] - Send a message of type [A] to [ID] over channel [C] and result in a [State] to be evaluated locally.
- [receive] - Receive a message of type [A] from [ID] on channel [C] and result in a [State] to be evaluated locally.
- [vtpm] - Communicate with the vTPM with result [A] and [State] for evaluation
locally
- [ifM] - Evaluate [Prop] locally and return the appropriate next state. Note
this is an if statement, not an if expression.
- [mapM] - _Definition is pending_
- [foldM] - _Definition is pending_
- [bundle] - _Definition is pending_
*)
Class ProtocolMonad {S A:Type} `(StateMonad) : Type :=
{
send : C -> ID -> A -> (State S A)
; receive : C -> ID -> A -> (State S A)
; vtpm : A -> (State S A)
; measure : A -> (State S A)
; ifM : bool -> (State S A) -> (State S A) -> (State S A)
; mapM : (State S A)
; foldM : (State S A)
; bundle : A -> (State S A)
}.
(** Make the [ProtocolMonad] an instance of [StateMonad] by giving values
to [put] and [get] and proving the state monad laws. This instance is
paramaterized over [S], [A] and [a], thus it can be used when creating
an instance of [ProtocolMonad]. *)
Instance ProtocolAsState (S A:Type) (a:A) :
StateMonad S A a StateAsMonad :=
{
put := (fun (s:S) => (fun (_:S) => (a,s)))
; get := (fun (s:S) => (s,s))
}.
Proof.
intros. simpl. extensionality x. reflexivity.
intros. simpl. extensionality x. reflexivity.
intros. simpl. extensionality x. reflexivity.
intros. simpl. extensionality x. reflexivity.
Defined.
(** Create an instnce of [ProtocolModad] using [nat] for the type of both [S]
and [A] and using [0] as the defuault result. This should be doable for
any types, not just [nat]. Right now there are no protocol monad laws, thus
one need only specify values for the elements of [ProtocolMonad] that
that define the specific instance. *)
Instance ProtocolMonadInstance :
ProtocolMonad (ProtocolAsState nat nat 0) :=
{
send := (fun (_:C) => (fun (_:ID) => (fun (a:nat) => (fun (s:nat) => (a,s)))))
; receive := (fun (_:C) => (fun (_:ID) => (fun (a:nat) => (fun (s:nat) => (a,s)))))
; measure := (fun (a:nat) => (fun (s:nat) => (a,s)))
; ifM := (fun (p:bool) => (fun (t:(State nat nat)) => (fun (f:(State nat nat)) => if p then t else f)))
; mapM := (fun (s:nat) => (0,s))
; foldM := (fun (s:nat) => (0,s))
; vtpm := (fun (a:nat) => (fun (s:nat) => (a,s)))
; bundle := (fun (a:nat) => (fun (s:nat) => (a,s)))
}.