std:Reflection/Lens
lib/Reflection/Lens.omg
lib/Reflection/Lens.omg38 lines
1-- Record lenses derived from the common reflection row certificate. The
2-- projection and update share checked laws; field names remain metadata.
3let R = std:Reflection/Row
4let M =
5 { pure = \{A : Type} (value : A) -> value
6 , bind = \{A B : Type} (value : A) (next : A -> B) -> next value
7 }
8let Inspection = \(_ : {} -> Type) -> exists (Fields : Type) * Fields
9let empty : Inspection (\_ -> {}) = ({}, {=})
10let inspect =
11 \{S : {} -> Type} (description : Reflect @1 {=} S) ->
12 description.fold
13 Inspection
14 { leaf = {=}
15 , bool = empty
16 , natural = empty
17 , integer = empty
18 , double = empty
19 , text = empty
20 , word = \_ -> empty
21 , list = \_ _ -> empty
22 , optional = \_ _ -> empty
23 , pair = \_ _ _ _ -> empty
24 , function = \_ _ _ _ -> empty
25 , union = \_ _ _ _ _ -> empty
26 , record =
27 \I row children ops _ ->
28 let F = \i -> children i {=}
29 let Fields = { ...row (\i -> R.Lens { ...row F } (F i)) }
30 in ((Fields,
31 ops.build
32 (\i -> R.Lens { ...row F } (F i))
33 (\A -> A)
34 M
35 (\i -> R.fieldLens I row ops.editRecord F i)) :
36 Inspection (\_ -> { ...row F }))
37 }
38in { Lens = R.Lens, inspect }