std:Validation

lib/Validation.omg

lib/Validation.omg24 lines
1-- A computable invariant, with diagnostics, and values carrying its evidence.
2-- Checking an unknown input never produces an unchecked success value.
3let Result = std:Result
4let Valid =
5      \{la le : Level} {A : Type la} {Error : Type le} (problems : A -> List Error) (value : A) ->
6        problems value === ([] : List Error)
7let Checked =
8      \{la le : Level} {A : Type la} {Error : Type le} (problems : A -> List Error) ->
9        exists (value : A) * Valid problems value
10let check
11    : forall {la le : Level}
12             {A : Type la}
13             {Error : Type le}
14             (problems : A -> List Error)
15             (value : A)
16      -> Result.Result (List Error) (Checked problems)
17    = \{la} {le} {A} {Error} problems value ->
18        List/elim
19          (\errors -> problems value === errors -> Result.Result (List Error) (Checked problems))
20          (\proof -> Result.ok (value, proof))
21          (\error rest recurse _ -> Result.err ([ error ] # rest))
22          (problems value)
23          refl
24in  { Valid, Checked, check }
Your result
Complete file: lib/Validation.omg · with imports