-
Notifications
You must be signed in to change notification settings - Fork 1
/
Lens_Lib.ML
83 lines (65 loc) · 2.38 KB
/
Lens_Lib.ML
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
signature LENS_LIB =
sig
(* Lens Constant Names *)
val bij_lensN: string
val vwb_lensN: string
val sym_lensN: string
val lens_indepN: string
val lens_plusN: string
val lens_quotientN: string
val lens_compN: string
val id_lensN: string
val sublensN: string
val lens_equivN: string
val lens_defsN: string
val indepsN: string
val sublensesN: string
val quotientsN: string
val compositionsN: string
val lens_suffix: string
(* Lens terms *)
val lensT: typ -> typ -> typ (* Lens type *)
val isLensT: typ -> bool
val astateT: typ (* Abstract state type *)
val pairsWith: 'a list -> 'a list -> ('a * 'a) list
val pairings: 'a list -> ('a * 'a) list (* Calculate all pairings *)
val mk_vwb_lens: term -> term (* Make a very well-behaved lens term *)
val mk_indep: term -> term -> term (* Make an independence term *)
val remove_lens_suffix: string -> string (* Remove the suffix subscript v from a name *)
end
structure Lens_Lib : LENS_LIB =
struct
open Syntax
open HOLogic
val bij_lensN = @{const_name bij_lens}
val vwb_lensN = @{const_name vwb_lens}
val sym_lensN = @{const_name sym_lens}
val lens_indepN = @{const_name lens_indep}
val lens_plusN = @{const_name lens_plus}
val lens_quotientN = @{const_name lens_quotient}
val lens_compN = @{const_name lens_comp}
val id_lensN = @{const_name id_lens}
val sublensN = @{const_name sublens}
val lens_equivN = @{const_name lens_equiv}
val lens_defsN = "lens_defs"
val indepsN = "indeps"
val sublensesN = "sublenses"
val quotientsN = "quotients"
val compositionsN = "compositions"
val lens_suffix = "\<^sub>v"
fun lensT a b = Type (@{type_name lens_ext}, [a, b, unitT])
fun isLensT (Type (n, _)) = (n = @{type_name lens_ext}) |
isLensT _ = false
val astateT = (TFree ("'st", [@{class scene_space}]))
fun pairWith _ [] = []
| pairWith x (y :: ys) = [(x, y), (y, x)] @ pairWith x ys;
fun pairsWith [] _ = []
| pairsWith (x :: xs) ys = pairWith x ys @ pairsWith xs ys;
fun pairings [] = []
| pairings (x :: xs) = pairWith x xs @ pairings xs;
fun mk_vwb_lens t = mk_Trueprop (const vwb_lensN $ t)
fun mk_indep x y = mk_Trueprop (const lens_indepN $ x $ y)
fun remove_lens_suffix x = (if (String.isSuffix lens_suffix x)
then String.substring (x, 0, (String.size x - String.size lens_suffix))
else x);
end