std:Observation

lib/Observation.omg

lib/Observation.omg23 lines
1-- A family of values with one designated reader. Packing needs a source;
2-- observing gives its public result, not an arbitrary fold over the source.
3let Reader =
4      \{l : Level} {I : Type l} (A : I -> Type) ->
5        exists (F : I -> Type) * forall (i : I) -> A i -> F i
6-- Giving the equality itself would let a package cast a fabricated result
7-- to the reader's carrier. Double negation permits the chosen reader without
8-- giving the package a cast. No double-negation elimination is used.
9let Permitted = \{l : Level} {T : Type l} (chosen proposed : T) -> (proposed === chosen -> <>) -> <>
10let Package =
11      \{l : Level} {I : Type l} {A : I -> Type} (chosen : Reader @l @I A) (i : I) ->
12        forall (use : Reader @l @I A) -> Permitted chosen use -> use.1 i
13let pack
14    : forall {l : Level} {I : Type l} {A : I -> Type} (chosen : Reader @l @I A) (i : I)
15      -> A i
16      -> Package @l @I @A chosen i
17    = \{l} {I} {A} chosen i value use permitted -> use.2 i value
18let view
19    : forall {l : Level} {I : Type l} {A : I -> Type} (chosen : Reader @l @I A) (i : I)
20      -> Package @l @I @A chosen i
21      -> chosen.1 i
22    = \{l} {I} {A} chosen i value -> value chosen (\deny -> deny refl)
23in  { Reader, Package, pack, view }
Your result
Complete file: lib/Observation.omg · with imports