-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSect1.v
58 lines (40 loc) · 1.41 KB
/
Sect1.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
Require Import Program.Basics.
Require Import Strings.String.
Require Import Sect2.
Open Scope program_scope.
(*****************)
(* Lens approach *)
(*****************)
(* Here, we show the simplified version of the university example, which only
requires lenses (Sect. 3.1). The traversal-based example serves us as
motivation to introduce the rich set of optic abstractions, but doesn't add
value to the rest of the paper. *)
(* Data layer *)
Record department := mkDepartment
{ budget : nat }.
Record university := mkUniversity
{ name : string
; mathDep : department
}.
Definition budgetLn : lens department nat :=
mkLens budget (fun _ b' => mkDepartment b').
Definition mathDepLn : lens university department :=
mkLens mathDep (fun u d' => mkUniversity (name u) d').
(* Business logic *)
Definition doubleDepBudget : department -> department :=
budgetLn %~ (fun b => b * 2).
Definition doubleUnivBudget : university -> university :=
mathDepLn %~ doubleDepBudget.
Definition doubleUnivBudget' : university -> university :=
(mathDepLn ▷ budgetLn) %~ (fun b => b * 2).
(*******************************)
(* Algebraic theories approach *)
(*******************************)
(* Repository algebras *)
Class UniversityAlg (p : Type -> Type) :=
{ getName : p string
; modifyName (f : string -> string) : p unit
; getMathDep : p department
; modifyMathDep (f : department -> department) : p unit
(* ... *)
}.